Create wireless.sh

This commit is contained in:
tianyu 2016-12-06 08:18:29 -06:00 committed by GitHub
parent 2da218b528
commit 97e3b7108a
1 changed files with 48 additions and 0 deletions

48
net/wireless/wireless.sh Normal file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# dependencies: bash wireless-tools
DIR=$(dirname $0)
source "$DIR/wireless.conf"
WIFI=$(uci get wireless.@wifi-iface[0].ssid)
echo "current wifi: $WIFI"
if [ $(iw dev wlan0 scan|grep "$WIFI"|wc -l) -eq 0 ];then
uci set wireless.@wifi-iface[0].disabled=1
uci commit
/etc/init.d/network restart
sleep 15
fi
for wifi in "${essids[@]}" ; do
ESSID="${wifi%%:*}"
PASS="${wifi##*:}"
echo "checking: $ESSID ..."
#echo "$PASS"
if [ $(iw dev wlan0 scan|grep "$ESSID"|wc -l) -ne 0 ];then
echo "wifi: $ESSID is detected."
if [ "$WIFI" != "$ESSID" ]; then
uci set wireless.@wifi-device[0].channel="auto"
uci set wireless.@wifi-iface[0].ssid="$ESSID"
uci set wireless.@wifi-iface[0].key="$PASS"
uci delete wireless.@wifi-iface[0].bssid
uci set wireless.@wifi-iface[0].disabled=0
if [ -z "$PASS" ]; then
uci set wireless.@wifi-iface[0].encryption="none"
uci delete wireless.@wifi-iface[0].key
else
uci set wireless.@wifi-iface[0].encryption="psk-mixed"
fi
uci commit
/etc/init.d/network restart
fi
break
fi
done