Skip to content

Instantly share code, notes, and snippets.

@aniongithub
Last active April 30, 2021 03:36
Show Gist options
  • Save aniongithub/4ea0b123240c2f5daac37a5753ce1c4a to your computer and use it in GitHub Desktop.
Save aniongithub/4ea0b123240c2f5daac37a5753ce1c4a to your computer and use it in GitHub Desktop.
Enable/Disable AP mode on a Raspberry Pi
#! /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
# Add the contents of this file to /etc/dhcpcd.conf before calling access_point
#include "/etc/hostapd.conf"
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