-
-
Save utaani/0a3119f4cdcceecc6600336930d1e31e to your computer and use it in GitHub Desktop.
Raspberry Pi 3 access-point-setup
This file contains 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 | |
# | |
# This version uses September 2016 rpi jessie image, please use this image | |
# | |
if [ "$EUID" -ne 0 ] | |
then echo "Must be root" | |
exit | |
fi | |
if [[ $# -lt 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 ]]; then | |
APSSID=$2 | |
fi | |
apt-get remove --purge hostapd -y | |
apt-get install hostapd dnsmasq -y | |
cat > /etc/systemd/system/hostapd.service <<EOF | |
[Unit] | |
Description=Hostapd IEEE 802.11 Access Point | |
After=sys-subsystem-net-devices-wlan0.device | |
BindsTo=sys-subsystem-net-devices-wlan0.device | |
[Service] | |
Type=forking | |
PIDFile=/var/run/hostapd.pid | |
ExecStart=/usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
cat > /etc/dnsmasq.conf <<EOF | |
interface=wlan0 | |
dhcp-range=172.17.172.2,172.17.172.99,255.255.255.0,12h | |
dhcp-option=6,8.8.8.8 | |
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 | |
# backup orginal /etc/network/interfaces | |
cp /etc/network/interfaces /etc/network/interfaces.org | |
sed -i -- 's/allow-hotplug wlan0//g' /etc/network/interfaces | |
sed -i -- 's/iface wlan0 inet manual//g' /etc/network/interfaces | |
sed -i -- 's/ wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf//g' /etc/network/interfaces | |
cat >> /etc/network/interfaces <<EOF | |
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf | |
# Added by rPi Access Point Setup | |
allow-hotplug wlan0 | |
iface wlan0 inet static | |
address 172.17.172.1 | |
netmask 255.255.255.0 | |
network 172.17.172.0 | |
broadcast 172.17.172.255 | |
EOF | |
# backup orginal /etc/dhcpcd.conf | |
cp /etc/dhcpcd.conf /etc/dhcpcd.conf.org | |
echo "denyinterfaces wlan0" >> /etc/dhcpcd.conf | |
systemctl enable hostapd | |
echo "All done! Please reboot" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment