Skip to content

Instantly share code, notes, and snippets.

@ralphotowo
Forked from Lewiscowles1986/rPi3-ap-setup.sh
Created April 2, 2016 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphotowo/c12825e50c5b04f5565c9d6781b1e154 to your computer and use it in GitHub Desktop.
Save ralphotowo/c12825e50c5b04f5565c9d6781b1e154 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 access-point-setup
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if [[ $# -ne 1 ]];
then echo "You need to pass a password!"
echo "Usage:"
echo "sudo $0 yourChosenPassword [apName]"
exit
fi
$APPASS=$1
$APSSID="rPi3"
if [[ $# -eq 2 ]];
$APSSID=$2
fi
apt-get remove --purge hostapd -y
apt-get install hostapd dnsmasq -y
cat > /etc/dnsmasq.conf <<EOF
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h
EOF
cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan0
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=$APPASS
ssid=$APSSID
EOF
sed -i -- 's/exit 0/ /g' /etc/rc.local
cat >> /etc/rc.local <<EOF
ifconfig wlan0 down
ifconfig wlan0 10.0.0.1 netmask 255.255.255.0 up
iwconfig wlan0 power off
service dnsmasq restart
hostapd -B /etc/hostapd/hostapd.conf & > /dev/null 2>&1
exit 0
EOF
echo "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment