-
Notifications
You must be signed in to change notification settings - Fork 6
/
nvpnmgr-menu.sh
executable file
·345 lines (307 loc) · 7.45 KB
/
nvpnmgr-menu.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/sh
# menu system
# inspired by approaches in repos from https://github.com/jackyaz
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
# load standard variables and helper script
source /usr/sbin/helper.sh
source "$SCRIPTPATH/addon_vars"
CONTROLSCRIPT="$LOCAL_REPO/$MY_ADDON_SCRIPT"
# default variables for this script
OPTIONCHECK=0
PressEnter(){
while true; do
printf "Press enter to continue..."
read -r "key"
case "$key" in
*)
break
;;
esac
done
return 0
}
ReturnToMainMenu(){
OPTIONCHECK=1
RETURNTEXT="$1"
break
ScriptHeader
UpdateNowMenuHeader
}
SetVPNClient(){
printf "\\n\\e[1mPlease select a VPN client connection (x to cancel): \\e[0m"
read -r "VPN_NO"
if [ "$VPN_NO" = "x" ]; then
OPTIONCHECK=1
ReturnToMainMenu "previous operation cancelled"
elif [ -z "$VPN_NO" ]; then
ReturnToMainMenu "you must specify a valid VPN client"
fi
# validate VPN_NO here (must be a number from 1 to 5 have "nordvpn" in the name)
}
SetVPNProtocol(){
printf "\\n\\e[1mPlease select a VPN protocol (x to cancel): \\e[0m\\n"
printf " 1. UDP\\n"
printf " 2. TCP\\n"
read -r "menu"
while true; do
case "$menu" in
1)
# check for connections
VPNPROT=openvpn_udp
break
;;
2)
# configure now
VPNPROT=openvpn_tcp
break
;;
x)
ReturnToMainMenu "previous operation cancelled"
break
;;
*)
ReturnToMainMenu "you must choose a protocol option"
break
;;
esac
done
if [ -z "$VPNPROT" ]; then
ReturnToMainMenu "you must choose a protocol option"
fi
}
SetVPNType(){
printf "\\n\\e[1mPlease select a VPN Type (x to cancel): \\e[0m\\n"
printf " 1. Standard VPN (default)\\n"
printf " 2. Double VPN\\n"
printf " 3. P2P\\n"
read -r "menu"
while true; do
case "$menu" in
1)
# check for connections
VPNTYPE=standard
break
;;
2)
# configure now
VPNTYPE=double
break
;;
3)
# configure now
VPNTYPE=p2p
break
;;
x)
ReturnToMainMenu "previous operation cancelled"
break
;;
*)
VPNTYPE=standard
break
;;
esac
done
if [ -z "$VPNTYPE" ]; then
ReturnToMainMenu "type not set or previous operation cancelled"
fi
}
SetDays(){
printf "\\n\\e[1mPlease choose update day/s (x to cancel - blank for every day): \\e[0m"
read -r "CRU_DAYNUMBERS"
if [ "$CRU_DAYNUMBERS" = "x" ]; then
ReturnToMainMenu "previous operation cancelled"
elif [ -z "$CRU_DAYNUMBERS" ]; then
CRU_DAYNUMBERS="*"
printf "\\n\\e[1mSet to every day\\e[0m\\n"
fi
# validate DAYS here (must be a number from 0 to 7 or these numbers separated by comma/s)
}
SetHours(){
printf "\\n\\e[1mPlease choose update hour/s (x to cancel): \\e[0m"
read -r "CRU_HOUR"
if [ "$CRU_HOUR" = "x" ]; then
ReturnToMainMenu "previous operation cancelled"
elif [ -z "$CRU_HOUR" ]; then
ReturnToMainMenu "you must specify a valid hour or hours separated by comma"
fi
# validate HOURS here (must be a number from 0 to 23)
}
SetMinutes(){
printf "\\n\\e[1mPlease choose update minute/s (x to cancel): \\e[0m"
read -r "CRU_MINUTE"
if [ "$CRU_MINUTE" = "x" ]; then
OPTIONCHECK=1
ReturnToMainMenu "previous operation cancelled"
elif [ -z "$CRU_MINUTE" ]; then
ReturnToMainMenu "you must specify a valid minute or minutes separated by comma"
fi
# validate MINUTES here (must be a number from 0 to 59)
}
ScriptHeader(){
clear
printf "\\n"
printf "\\e[1m############################################################\\e[0m\\n"
printf "\\e[1m## $MY_ADDON_NAME Menu ##\\e[0m\\n"
printf "\\e[1m############################################################\\e[0m\\n"
printf "\\n"
}
MainMenu(){
printf " 1. Check for available NordVPN VPN client connections\\n"
printf " 2. Update a VPN client connection NOW\\n"
printf " 3. Schedule a VPN client connection update\\n"
printf " d. Delete a scheduled VPN client connection update\\n"
printf " u. Update $MY_ADDON_NAME\\n"
printf " x. Exit $MY_ADDON_NAME menu\\n\\n"
printf " z. Uninstall $MY_ADDON_NAME\\n"
printf "\\n"
printf "\\e[1m############################################################\\e[0m\\n"
VPN_NO=
VPNPROT=
VPNTYPE=
CRU_HOUR=
CRU_DAYNUMBERS=
CRU_MINUTE=
while true; do
if [ "$OPTIONCHECK" = "1" ]
then
printf "$RETURNTEXT\\n"
OPTIONCHECK=0
else
printf "\\n"
fi
printf "Choose an option: "
read -r "menu"
case "$menu" in
1)
printf "\\n"
# check for connections
ListMenu
break
;;
2)
printf "\\n"
# configure now
UpdateNowMenu
break
;;
3)
printf "\\n"
# configure schedule
ScheduleUpdateMenu
break
;;
d)
printf "\\n"
# remove schedule
DeleteScheduleMenu
break
;;
u)
printf "\\n"
# update script from github
"$LOCAL_REPO/install.sh"
PressEnter
break
;;
x)
ScriptHeader
printf "\\n\\e[1mThanks for using $MY_ADDON_NAME!\\e[0m\\n\\n\\n"
exit 0
;;
z)
printf "\\n\\e[1mAre you sure you want to uninstall $MY_ADDON_NAME (Y to confirm)?\\e[0m "
read -r "confirm"
if [ "$confirm" = "Y" ]
then
echo "Uninstalling $MY_ADDON_NAME..."
# remove script
Addon_Uninstall
exit 0
else
ReturnToMainMenu "Uninstall of $MY_ADDON_NAME cancelled"
fi
;;
*)
ReturnToMainMenu "Please choose a valid option"
;;
esac
done
ScriptHeader
MainMenu
}
UpdateNowMenuHeader(){
printf " Choose options as follows:\\n"
printf " VPN client [1-5]\\n"
printf " protocol to use (pick from list)\\n"
printf " type to use (pick from list)\\n"
printf "\\n"
printf "\\e[1m############################################################\\e[0m\\n"
}
ScheduleUpdateMenuHeader(){
printf " Choose options as follows:\\n"
printf " VPN client [1-5]\\n"
printf " protocol to use (pick from list)\\n"
printf " type to use (pick from list)\\n"
printf " day/s to update [0-7]\\n"
printf " hour/s to update [0-23]\\n"
printf " minute/s to update [0-59]\\n"
printf "\\n"
printf "\\e[1m############################################################\\e[0m\\n"
}
DeleteScheduleMenuHeader(){
printf " Choose schedule entry to delete:\\n"
printf " VPN client [1-5]\\n"
printf "\\n"
printf "\\e[1m############################################################\\e[0m\\n"
}
ListMenu(){
ScriptHeader
$CONTROLSCRIPT list
printf "\\n"
PressEnter
ReturnToMainMenu
}
UpdateNowMenu(){
ScriptHeader
UpdateNowMenuHeader
SetVPNClient
SetVPNProtocol
SetVPNType
$CONTROLSCRIPT update "$VPN_NO" "$VPNPROT" "$VPNTYPE"
PressEnter
ReturnToMainMenu "Update VPN complete ($VPNTYPE)"
}
ScheduleUpdateMenu(){
ScriptHeader
ScheduleUpdateMenuHeader
SetVPNClient
SetVPNProtocol
SetVPNType
SetDays
SetHours
SetMinutes
$CONTROLSCRIPT schedule "$VPN_NO" "$VPNPROT" "$CRU_MINUTE" "$CRU_HOUR" "$CRU_DAYNUMBERS" "$VPNTYPE"
PressEnter
ReturnToMainMenu "Scheduled VPN update complete ($VPNTYPE)"
}
DeleteScheduleMenu(){
ScriptHeader
DeleteScheduleMenuHeader
SetVPNClient
$CONTROLSCRIPT cancel "$VPN_NO"
PressEnter
ReturnToMainMenu "Delete VPN schedule complete"
}
Addon_Uninstall(){
printf "Uninstalling $MY_ADDON_NAME has not yet been tested...\\n"
# printf "Uninstalling $MY_ADDON_NAME..."
# cd ~
# rm -f "$LOCAL_REPO" 2>/dev/null
# printf "Uninstall of $MY_ADDON_NAME completed"
}
ScriptHeader
MainMenu