Last active
April 30, 2021 03:36
-
-
Save aniongithub/4ea0b123240c2f5daac37a5753ce1c4a to your computer and use it in GitHub Desktop.
Enable/Disable AP mode on a Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Requires hostapd and dnsmasq packages installed | |
# Parse options using getopt | |
# https://www.codebyamir.com/blog/parse-command-line-arguments-using-getopt | |
opts=$(getopt \ | |
--longoptions "on,off" \ | |
--name "$(basename "$0")" \ | |
--options "" \ | |
-- "$@" | |
) | |
eval set --$opts | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
--on) | |
sed -i 's;#include \"/etc/hostapd.conf\";include \"/etc/hostapd.conf\";' /etc/dhcpcd.conf && | |
systemctl daemon-reload && | |
service dhcpcd restart && | |
systemctl start dnsmasq && | |
systemctl unmask hostapd && | |
systemctl start hostapd && | |
systemctl enable dnsmasq && | |
systemctl enable hostapd && | |
echo heartbeat > /sys/class/leds/led0/trigger | |
shift | |
;; | |
--off) | |
systemctl stop dnsmasq && | |
systemctl stop hostapd && | |
systemctl disable dnsmasq && | |
systemctl disable hostapd && | |
sed -e 's;include \"/etc/hostapd.conf\";#include \"/etc/hostapd.conf\";' -i /etc/dhcpcd.conf && | |
systemctl daemon-reload && | |
service dhcpcd restart && | |
echo none > /sys/class/leds/led0/trigger | |
shift | |
;; | |
*) | |
break | |
;; | |
esac | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add the contents of this file to /etc/dhcpcd.conf before calling access_point | |
#include "/etc/hostapd.conf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface wlan0 | |
static ip_address=192.168.4.1/24 | |
nohook wpa_supplicant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment