Skip to content

Instantly share code, notes, and snippets.

@diginfo
Created April 9, 2021 09:08
Show Gist options
  • Save diginfo/212cb3ff68298c5ecd6fbcb29da6a61a to your computer and use it in GitHub Desktop.
Save diginfo/212cb3ff68298c5ecd6fbcb29da6a61a to your computer and use it in GitHub Desktop.
#!/bin/bash
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if [[ $# -lt 2 ]];
echo "Usage:"
echo "$0 password ssid"
exit
fi
APPASS="$1"
APSSID="$2"
NWFN=/etc/network/interfaces.d/wlan0
apt-get remove --purge hostapd -yqq
apt-get update -yqq
apt-get upgrade -yqq
apt-get install hostapd dnsmasq -yqq
cat > /etc/dnsmasq.conf <<EOF
## setup by script $0
interface=wlan0
dhcp-range=192.168.3.100,192.168.3.199,255.255.255.0,12h
EOF
cat > /etc/hostapd/hostapd.conf <<EOF
## setup by script $0
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
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
EOF
sed -i -- 's/allow-hotplug wlan0//g' $NWFN
sed -i -- 's/iface wlan0 inet manual//g' $NWFN
sed -i -- 's/ wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf//g' $NWFN
sed -i -- 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd
cat >> $NWFN <<EOF
## setup by script $0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255
EOF
echo "denyinterfaces wlan0" >> /etc/dhcpcd.conf
systemctl unmask hostapd
systemctl enable hostapd
systemctl enable dnsmasq
service hostapd start
service dnsmasq start
echo "All done! Please reboot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment