pi-scripts/wificonnect

75 lines
1.6 KiB
Text
Raw Permalink Normal View History

2019-04-02 17:36:15 -05:00
#!/bin/bash
#script to list available SSID and mod wpa-supplicant
#file to connect to new wifi hotspot
#this script works in conjuction with autohotspot
#http://www.raspberryconnect.com/network/item/330-raspberry-pi-auto-wifi-hotspot-switch-internet
#km4ack 20190401
2020-02-21 14:27:13 -06:00
#edited 20200221
2019-04-02 17:36:15 -05:00
2020-02-21 14:27:13 -06:00
mkdir -p $HOME/temp
TEMPFILE=$HOME/temp/tempwifi
2019-04-02 17:36:15 -05:00
# Generate List of Available SSIDs
SSID_LIST () {
2020-02-21 14:27:13 -06:00
LIST=$(sudo iw dev "wlan0" scan ap-force | egrep "^BSS|SSID:" | grep SSID: | sed 's/SSID://' | awk '{ print $1 }' )
clear;echo;echo
echo "These SSID's are available"
2019-04-02 17:36:15 -05:00
echo
2020-02-21 14:27:13 -06:00
echo "$LIST" | sed '/^$/d'
2019-04-02 17:36:15 -05:00
#ask user about hotspots
echo
echo "1 to refresh the list, 2 to exit or"
echo "Enter name of SSID would you like add?"
read SSID
if [ $SSID == "1" ]
then
2020-02-21 14:27:13 -06:00
clear;echo;echo
echo "Scanning for WiFi again...please wait"
2019-04-02 17:36:15 -05:00
SSID_LIST
elif [ $SSID == "2" ]
then
echo "Goodbye"
exit
fi
}
#print list on screen
2020-02-21 14:27:13 -06:00
clear;echo;echo
echo "Scanning for Wifi.....please wait"
2019-04-02 17:36:15 -05:00
SSID_LIST
#get SSID password
echo
echo "What is the password for the hotspot?"
read PASS
#verify you want to add the hotspot
echo
2020-02-21 14:27:13 -06:00
echo "SSID = "$SSID
echo "Password = "$PASS
echo "REMEMBER THIS IS CASE SENSITIVE"
echo "Is this correct? y/n"
2019-04-02 17:36:15 -05:00
read ANSWER
#make the change to wpa_supplicant.conf
2020-02-21 14:27:13 -06:00
if [ $ANSWER == "y" ] || [ $ANSWER == "Y" ]
2019-04-02 17:36:15 -05:00
then
2020-02-21 14:27:13 -06:00
cat > $TEMPFILE <<EOF
network={
ssid="$SSID"
psk="$PASS"
key_mgmt=WPA-PSK
}
EOF
cat $TEMPFILE |sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
rm $TEMPFILE
echo "attempting to connect to new wifi"
sudo /usr/bin/autohotspotN
2019-04-02 17:36:15 -05:00
else
2020-02-21 14:27:13 -06:00
clear;echo;echo;
echo "Scanning for WiFi.....please wait"
SSID_LIST
2019-04-02 17:36:15 -05:00
fi