pi-build/functions/autohotspot

101 wiersze
3.3 KiB
Plaintext
Czysty Zwykły widok Historia

2020-06-14 14:06:45 +00:00
#!/bin/bash
#install autohotspot from raspberrypiconnect.com
#http://www.raspberryconnect.com/network/item/330-raspberry-pi-auto-wifi-hotspot-switch-internet
#This version will provide internet when using the hotspot IF an ethernet cable is plugged in"
#This will be useful with AREDN mesh networking
#This script is for Buster ONLY
#Stretch users should use https://github.com/km4ack/pi-scripts/blob/master/autohotspotN-setup
#km4ack 20190923
#km4ack 20200513 mod for BAP script
shackwifi=$1
shackpass=$2
wifipasswd=$3
#escape all "&" incase used in HS password
wifipasswd=$(sed 's|&|\\&|g' <<<${wifipasswd})
2020-06-14 14:06:45 +00:00
#unblock wifi
#needed after buster 20200205
rfkill unblock all >/dev/null 2>&1
2020-06-14 14:06:45 +00:00
#install hostapd, dnsmasq
apt-get install -y hostapd
apt-get install -y dnsmasq
#remove hostapd mask
systemctl unmask hostapd
#stop both services
systemctl disable hostapd
systemctl disable dnsmasq
mkdir -p ${HOME}/temp
2021-03-17 14:36:15 +00:00
cd ${HOME}/temp || return
2020-06-14 14:06:45 +00:00
wget http://www.raspberryconnect.com/images/Autohotspot/autohotspot-95-4/hostapd.txt
#set new hotspot passwd
sed -i "s|wpa_passphrase=1234567890|wpa_passphrase=${wifipasswd}|" ${HOME}/temp/hostapd.txt
2020-06-14 14:06:45 +00:00
#set country to US
sed -i 's/country_code=GB/country_code=US/' ${HOME}/temp/hostapd.txt
2020-06-14 14:06:45 +00:00
#move hostapd to correct location
mv ${HOME}/temp/hostapd.txt /etc/hostapd/hostapd.conf
2020-06-14 14:06:45 +00:00
sed -i s'/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/' /etc/default/hostapd
sed -i s'/DAEMON_OPTS=""/#DAEMON_OPTS=""/' /etc/default/hostapd
#add needed info to dnsmasq.conf
echo "#AutoHotspot config" >>/etc/dnsmasq.conf
echo "interface=wlan0" >>/etc/dnsmasq.conf
echo "bind-dynamic" >>/etc/dnsmasq.conf
echo "server=8.8.8.8" >>/etc/dnsmasq.conf
echo "domain-needed" >>/etc/dnsmasq.conf
echo "bogus-priv" >>/etc/dnsmasq.conf
echo "dhcp-range=10.10.10.150,10.10.10.200,255.255.255.0,12h" >>/etc/dnsmasq.conf
echo "#Set up redirect for email.com" >>/etc/dnsmasq.conf
echo "dhcp-option=3,10.10.10.10" >>/etc/dnsmasq.conf
echo "address=/email.com/10.10.10.10" >>/etc/dnsmasq.conf
2020-06-14 14:06:45 +00:00
mv /etc/network/interfaces /etc/network/interfaces.org
echo "source-directory /etc/network/interfaces.d" >>/etc/network/interfaces
2020-06-14 14:06:45 +00:00
echo "nohook wpa_supplicant" >>/etc/dhcpcd.conf
2020-06-14 14:06:45 +00:00
#setup ip forward
sed 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
2021-03-17 14:36:15 +00:00
cd ${HOME}/temp || return
2020-06-14 14:06:45 +00:00
wget http://www.raspberryconnect.com/images/autohotspotN/autohotspotn-95-4/autohotspot-service.txt
#create autohotspot service file
mv autohotspot-service.txt /etc/systemd/system/autohotspot.service
#start autohotspot service
systemctl enable autohotspot.service
#check if iw installed. install if not
iwcheck=$(dpkg --get-selections | grep -w "iw")
if [ -z "iw" ]; then #THIS MIGHT NEED TO SOME LOOKING AT -- SEE SC2157
apt-get install iw
2020-06-14 14:06:45 +00:00
fi
#install autohotspot script
2021-03-17 14:36:15 +00:00
cd ${HOME}/temp || return
2020-06-14 14:06:45 +00:00
wget http://www.raspberryconnect.com/images/autohotspotN/autohotspotn-95-4/autohotspotN.txt
#mod ip address for our custom setup
sed -i 's/192.168.50.5/10.10.10.10/' autohotspotN.txt
mv autohotspotN.txt /usr/bin/autohotspotN
chmod +x /usr/bin/autohotspotN
#add shack wifi to wpa_supplicant.conf
echo "network={" >>/etc/wpa_supplicant/wpa_supplicant.conf
echo "ssid=\"$shackwifi\"" >>/etc/wpa_supplicant/wpa_supplicant.conf
echo "psk=\"$shackpass\"" >>/etc/wpa_supplicant/wpa_supplicant.conf
echo "key_mgmt=WPA-PSK" >>/etc/wpa_supplicant/wpa_supplicant.conf
echo "}" >>/etc/wpa_supplicant/wpa_supplicant.conf