pi-scripts/autohotspot-setup

146 lines
3.7 KiB
Text
Raw Permalink Normal View History

2019-04-09 16:17:03 -05:00
#!/bin/bash
#install autohotspot from raspberrypiconnect.com
2019-04-11 06:04:52 -05:00
#http://www.raspberryconnect.com/network/item/331-raspberry-pi-auto-wifi-hotspot-switch-no-internet-routing
2019-04-09 16:17:03 -05:00
#km4ack 20190409
#km4ack 20190912
echo ""
echo "please use autohotspotN script instead of this one"
echo "download the correct script by running the command below"
echo "wget https://raw.githubusercontent.com/km4ack/pi-scripts/master/autohotspotN-setup"
exit 0
2019-04-09 16:17:03 -05:00
#update packages
apt-get update
#install hostapd, dnsmasq
2019-04-09 17:06:09 -05:00
apt-get install -y hostapd
apt-get install -y dnsmasq
2019-04-09 16:17:03 -05:00
#stop both services
2019-04-10 20:44:18 -05:00
systemctl disable hostapd
systemctl disable dnsmasq
2019-04-09 16:17:03 -05:00
mkdir -p $HOME/temp
wifipass () {
echo;echo;echo
echo "This password will be used to connect to the pi"
echo "when the pi is in hotspot mode"
read -p "Enter password to use with new hotspot " wifipasswd
2019-04-09 16:17:03 -05:00
echo;echo
echo "You entered $wifipasswd"
read -p "Is this correct? y/n " wifians
if [ $wifians == "y" ]
then
echo
else
wifipass
fi
}
wifipass
cd $HOME/temp
2019-04-09 18:33:39 -05:00
wget http://www.raspberryconnect.com/images/Autohotspot/autohotspot-95-4/hostapd.txt
2019-04-09 16:17:03 -05:00
#set new hotspot passwd
sed -i "s/wpa_passphrase=1234567890/wpa_passphrase=$wifipasswd/" $HOME/temp/hostapd.txt
#set country to US
sed -i 's/country_code=GB/country_code=US/' $HOME/temp/hostapd.txt
#move hostapd to correct location
mv $HOME/temp/hostapd.txt /etc/hostapd/hostapd.conf
2019-04-09 16:47:15 -05:00
sed -i s'/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/' /etc/default/hostapd
2019-04-09 16:17:03 -05:00
sed -i s'/DAEMON_OPTS=""/#DAEMON_OPTS=""/' /etc/default/hostapd
#add needed info to dnsmasq.conf
echo "#AutoHotspot config" >> /etc/dnsmasq.conf
echo "no-resolv" >> /etc/dnsmasq.conf
2019-04-09 16:17:03 -05:00
echo "interface=wlan0" >> /etc/dnsmasq.conf
echo "bind-interfaces" >> /etc/dnsmasq.conf
echo "dhcp-range=10.0.0.50,10.0.0.150,12h" >> /etc/dnsmasq.conf
2019-04-09 16:17:03 -05:00
mv /etc/network/interfaces /etc/network/interfaces.org
echo "source-directory /etc/network/interfaces.d" >> /etc/network/interfaces
echo "nohook wpa_supplicant" >> /etc/dhcpcd.conf
cd $HOME/temp
wget http://www.raspberryconnect.com/images/Autohotspot/autohotspot-95-4/autohotspot-service.txt
2019-04-09 16:17:03 -05:00
#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
apt-get install iw
fi
#install autohotspot script
cd $HOME/temp
wget http://www.raspberryconnect.com/images/Autohotspot/autohotspot-95-4/autohotspot.txt
mv autohotspot.txt /usr/bin/autohotspot
chmod +x /usr/bin/autohotspot
2019-04-09 16:17:03 -05:00
#shackwifi function
shackwifi1 () {
2019-04-09 16:17:03 -05:00
#get ham's wifi credentials
echo "What wifi SSID would you like to connect to?"
echo "This is the one already in your shack"
read shackwifi
echo "What is the password for this wifi?"
read shackpass
echo;echo;
echo "Your shack's current wifi is"
echo "wifi $shackwifi"
echo "passwd $shackpass"
echo "Is this correct? y/n"
read shackans
2019-04-11 06:21:56 -05:00
if [ $shackans == "y" ]
then
echo
else
shackwifi1
fi
}
2019-04-09 16:17:03 -05:00
#run shackwifi function
shackwifi1
#add shack wifi to wpa_supplicant.conf
2019-04-09 16:17:03 -05:00
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
#remove hostapd masked error on first run of hotspot
2019-04-10 21:15:13 -05:00
systemctl unmask hostapd
echo;echo;echo
echo "A reboot is required to complete the setup"
read -p "Would you like to reboot now? y/n " rebot
if [ $rebot == "y" ]
then
reboot
else
echo "Please remember to reboot soon"
fi
2019-04-09 16:17:03 -05:00
#need to setup cron job but can't do here b/c running as root