-
Notifications
You must be signed in to change notification settings - Fork 1
/
swh
executable file
·152 lines (144 loc) · 2.76 KB
/
swh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
# Description: WiFi config helper
# Destination: /usr/local/bin/swh
export LANG=$LANG:C
if [[ $EUID -ne 0 ]]; then
sudo "$0" "$@"
exit 0
fi
INTERFACE="wlan0"
TXT="\033[0m"
FIN="\e[0m"
spinner(){
local i sp n
sp='|\-/'
n=${#sp}
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
}
# Commands
if [ $# -eq 0 ]; then
echo "Missing options!"
echo "(run $0 -h for help)"
echo ""
exit 0
fi
while getopts "hsSudrWIUm" OPTION; do
case $OPTION in
s)
echo -en "${TXT}"
echo -en "Scanning: "; spinner &
printf '\n'
iwlist ${INTERFACE} scan | grep 'ESSID:\|Frequency:\|Quality=\|Encryption key:'
kill "$!" # kill the spinner
printf '\n'
echo -en "${FIN}"
read -p "Press enter to continue."
;;
S)
echo ""
echo -en "Scan specific SSID: "
read SSID
iwlist ${INTERFACE} scanning | grep -C5 -i -w "$SSID"
echo ""
read -p "Press enter to continue."
;;
u)
echo ""
echo "Bringing up interface."
ifup ${INTERFACE}
echo "Done."
echo ""
;;
d)
echo ""
echo "Bringing down interface."
ifdown ${INTERFACE}
echo "Done."
echo ""
;;
r)
echo ""
echo "Restarting ..."
ifdown ${INTERFACE}
sleep .75
ifup ${INTERFACE}
;;
W)
nano /etc/wpa_supplicant/wpa_supplicant.conf
;;
I)
nano /etc/network/interfaces
;;
U)
if [[ `wget -S --spider http://github.com 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
mv -f /usr/local/bin/swh /usr/local/bin/swh.orig
wget -cq https://raw.githubusercontent.com/pyavitz/scripts/master/swh -P /usr/local/bin/
chmod +x $(command -v swh)
if [[ `command -v swh` ]]; then
rm -f /usr/local/bin/swh.orig
else
mv -f /usr/local/bin/swh.orig /usr/local/bin/swh
fi
swh -h
else
echo -e "This script requires an internet connection to update."
exit 0
fi
;;
m)
while [ 1 ]
do
CHOICE=$(
export NEWT_COLORS='root=,black roottext=lightgray,black title=black,lightgray'
whiptail --backtitle "Menu Interface: Simple Wifi Helper" --title "Simple Wifi Helper" --menu "" --nocancel 0 0 0 \
"1)" "Scan for SSID's" \
"2)" "Bring up interface" \
"3)" "Bring down interface" \
"4)" "Restart interface" \
"5)" "Edit wpa supplicant" \
"6)" "Edit interface" \
"E)" "Exit .." 3>&2 2>&1 1>&3
)
case $CHOICE in
"1)")
swh -s
;;
"2)")
swh -u
;;
"3)")
swh -d
;;
"4)")
swh -r
;;
"5)")
swh -W
;;
"6)")
swh -I
;;
"E)")
clear -x
exit 0
;;
esac
done
;;
h)
echo -e "${TXT}Simple wifi helper${FIN}"
echo -e "Usage: "
echo ""
echo -e "\t-s\tScan for SSID's"
echo -e "\t-u\tBring up interface"
echo -e "\t-d\tBring down interface"
echo -e "\t-r\tRestart interface"
echo -e "\t-W\tEdit wpa supplicant"
echo -e "\t-I\tEdit interfaces"
echo ""
exit 0
;;
esac
done