-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
256 lines (208 loc) · 6.42 KB
/
run.sh
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
# Ensure we are being ran as root
if [ $(id -u) -ne 0 ]; then
echo "This script must be ran as root"
exit 1
fi
clear
Red="\e[1;91m" ##### Colors Used #####
Green="\e[0;92m"
Yellow="\e[0;93m"
Blue="\e[1;94m"
White="\e[0;97m"
checkWiFiStatus () { ##### Check if $foo is enabled or not #####
WiFiStatus=`nmcli radio wifi`
if [ "$WiFiStatus" == "disabled" ]; then
nmcli radio wifi on
echo -e "[${Green}$foo${White}] Enabled!"
fi
}
banner () { ##### Banner #####
echo -e "${Green}
______________¶¶¶
_____________¶¶_¶¶¶¶
____________¶¶____¶¶¶
___________¶¶¶______¶¶
___________¶¶¶_______¶¶
__________¶¶¶¶________¶¶
__________¶_¶¶_________¶¶
__________¶__¶¶_________¶¶____¶¶
__________¶__¶¶__________¶¶¶¶¶¶¶
_________¶¶__¶¶¶______¶¶¶¶¶¶___¶
_________¶¶___¶¶__¶¶¶¶¶¶__¶¶
_______¶¶_¶____¶¶¶¶________¶¶
______¶¶__¶¶___¶¶__________¶¶
_____¶¶____¶¶___¶¶__________¶¶
___¶¶_______¶¶___¶¶_________¶¶
___¶¶¶¶¶¶¶¶¶¶¶¶¶__¶¶_________¶
_¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶_¶¶________¶¶
¶¶__¶¶¶¶¶¶____¶¶¶¶¶¶¶¶¶______¶¶
¶¶¶¶¶___¶______¶___¶¶¶¶¶_____¶¶
________¶¶¶¶¶¶¶¶______¶¶¶¶¶_¶¶
______¶¶¶¶¶¶¶¶¶¶¶________¶¶¶¶
______¶¶¶¶¶¶¶¶¶¶¶¶
______¶__¶¶_¶¶¶¶¶¶
_____¶¶______¶___¶
_____¶¶_____¶¶___¶
_____¶______¶¶___¶
____¶¶______¶¶___¶¶
____¶¶______¶¶___¶¶
___¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
__¶¶¶¶¶¶¶¶¶_¶¶¶¶¶¶¶¶
__¶¶________¶¶¶____¶¶
____¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
"
echo -e "${Yellow} \n Network Manager for noobz"
echo -e "${Green}\n v 1.0.3 By Liam Bendix (liam@liambendix.com) "
}
menu () { ##### Display available options #####
echo -e "\n${Yellow} [ Select Option To Continue ]\n\n"
echo -e " ${Red}[${Blue}1${Red}] ${Green}List WiFi Networks"
echo -e " ${Red}[${Blue}2${Red}] ${Green}Connect to a WiFi"
echo -e " ${Red}[${Blue}3${Red}] ${Green}Show Saved Connections"
echo -e " ${Red}[${Blue}4${Red}] ${Green}Start Ad Hoc Network"
echo -e " ${Red}[${Blue}5${Red}] ${Green}Stop Ad Hoc Network"
echo -e " ${Red}[${Blue}6${Red}] ${Green}Check Status"
echo -e " ${Red}[${Blue}7${Red}] ${Green}Exit\n\n"
while true; do
echo -e "${Green}┌─[${Red}Select Option${Green}]──[${Red}~${Green}]─[${Yellow}Menu${Green}]:"
read -p "└─────►$(tput setaf 7) " option
case $option in
1) echo -e "\n[${Green}Selected${White}] Option 1 List All Networks"
ScanList
exit 0
;;
2) echo -e "\n[${Green}Selected${White}] Option 2 Connect To Network"
connect
exit 0
;;
3) echo -e "\n[${Green}Selected${White}] Option 3 Show Saved Connections"
known
exit 0
;;
4) echo -e "\n[${Green}Selected${White}] Option 4 Start Ad Hoc Network"
startADHOC
exit 0
;;
5) echo -e "\n[${Green}Selected${White}] Option 5 Stop Ad Hoc Network"
stopADHOC
exit 0
;;
6) echo -e "\n[${Green}Selected${White}] Option 6 Check Device Status"
checkStatus
exit 0
;;
7) echo -e "${Red}\n\033[1mThank You for using the script,\n:)\n"
exit 0
;;
*) echo -e "${White}[${Red}Error${White}] Please select correct option...\n"
;;
esac
done
}
ScanList () {
checkWiFiStatus
nmUP
nmcli d wifi list
menu
}
connect () {
checkWiFiStatus
nmUP
echo "Enter network name: " SSID
read SSID
sudo nmcli --ask dev wifi connect $SSID
}
known () {
checkWiFiStatus
nmUP
nmcli c
}
nmUP () {
sudo systemctl stop dhcpcd > /dev/null 2>&1
/etc/init.d/dhcp stop > /dev/null 2>&1
sudo systemctl start NetworkManager.service > /dev/null 2>&1
sudo systemctl enable NetworkManager.service > /dev/null 2>&1
sudo systemctl start NetworkManager-wait-online.service > /dev/null 2>&1
sudo systemctl enable NetworkManager-wait-online.service > /dev/null 2>&1
sudo systemctl start NetworkManager-dispatcher.service > /dev/null 2>&1
sudo systemctl enable NetworkManager-dispatcher.service > /dev/null 2>&1
sudo systemctl start network-manager.service > /dev/null 2>&1
sudo systemctl enable network-manager.service > /dev/null 2>&1
}
nmDOWN () {
sudo systemctl stop NetworkManager.service > /dev/null 2>&1
sudo systemctl disable NetworkManager.service > /dev/null 2>&1
sudo systemctl stop NetworkManager-wait-online.service > /dev/null 2>&1
sudo systemctl disable NetworkManager-wait-online.service > /dev/null 2>&1
sudo systemctl stop NetworkManager-dispatcher.service > /dev/null 2>&1
sudo systemctl disable NetworkManager-dispatcher.service > /dev/null 2>&1
sudo systemctl stop network-manager.service > /dev/null 2>&1
sudo systemctl disable network-manager.service > /dev/null 2>&1
sudo systemctl start dhcpcd > /dev/null 2>&1
/etc/init.d/dhcp start > /dev/null 2>&1
}
startADHOC () {
echo 'system will automatically reboot in 10 seconds(Ctrl+C to cancel)'
sleep 10
nmDOWN
cp rc.local /etc
cp udhcpd.conf /etc
cp dhcpcd.conf /etc
echo "$(tput setaf 2)System needs to reboot, restarting..."
sleep 5
sudo reboot
}
stopADHOC () {
if [ -e /etc/rc.local.adhoc_bak ]
then
cp /etc/rc.local.adhoc_bak /etc/rc.local
fi
rm /etc/rc.local.adhoc_bak
if [ -e /etc/udhcpd.conf.adhoc_bak ]
then
cp /etc/udhcpd.conf.adhoc_bak /etc/udhcpd.conf
else
rm /etc/udhcpd.conf
fi
rm /etc/udhcpd.conf.adhoc_bak
if [ -e /etc/dhcpcd.conf.adhoc_bak ]
then
cp /etc/dhcpcd.conf.adhoc_bak /etc/dhcpcd.conf
else
rm /etc/dhcpcd.conf
fi
rm /etc/dhcpcd.conf.adhoc_bak
nmUP
echo "$(tput setaf 2)System needs to reboot, restarting..."
sleep 5
sudo reboot
exit 0
}
checkStatus () {
clear
echo -e "${Yellow} \n STATUS CHECK:"
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${Green} \n WiFi Connection Established:"
iwgetid
echo "Current IP:"
hostname -I | awk '{print $1}'
echo 'NetworkManager Status:'
systemctl status NetworkManager | grep Active | grep -v grep
echo 'DHCPCD Status:'
systemctl status dhcpcd.service | grep Active | grep -v grep
else
echo -e "${Red} \n No WiFi Connection:"
echo 'NetworkManager Status:'
systemctl status NetworkManager | grep Active | grep -v grep
echo 'DHCPCD Status:'
systemctl status dhcpcd.service | grep Active | grep -v grep
fi
}
############# End of tool ########################################################
checkme () {
banner
menu
}
checkme