-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpn.sh
executable file
·91 lines (71 loc) · 1.81 KB
/
vpn.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
#!/bin/sh
readonly CMD=$1
readonly VPN_PATH=$HOME
readonly COLOR_OFF="%{F#66ffffff}"
readonly ICON_OFF=""
readonly COLOR_ON="%{F#61C766}"
readonly ICON_ON=""
function show_icon() {
openvpn=$(pgrep -a openvpn | head -n 1 | awk '{print $NF }' | rev | cut -d '/' -f 1 | rev)
openfortivpn=$(pgrep -a openfortivpn | head -n 1 | awk '{print $NF }' | rev | cut -d '/' -f 1 | rev)
if [ -n "$openvpn" ]; then
echo $COLOR_ON$ICON_ON $openvpn
elif [ -n "$openfortivpn" ] ; then
echo $COLOR_ON$ICON_ON
else
echo $COLOR_OFF$ICON_OFF
fi
}
function kill_vpn_gui {
cmd=(
yad
--undecorated --fixed --close-on-unfocus --borders=0
--button="Kill VPN"
--posx="2030" --posy="35"
)
"${cmd[@]}"
exval=$?
}
function toggle() {
openvpn=$(pgrep -a openvpn)
openfortivpn=$(pgrep -a openfortivpn)
if [ -n "$openvpn" ] ; then
kill_vpn_gui
case $exval in
0) pgrep openvpn | pkexec xargs kill;;
esac
elif [ -n "$openfortivpn" ] ; then
kill_vpn_gui
case $exval in
0) pgrep openfortivpn | pkexec xargs kill;;
esac
else
file=$(cd $VPN_PATH && yad --file)
extension="${file##*.}"
case $extension in
"ovpn")
options="$file"
pkexec openvpn $options
;;
"conf")
pkexec openfortivpn -c $file
;;
esac
fi
}
case $CMD in
"--show")
show_icon
;;
"--toggle")
toggle
;;
*)
echo "Invalid command"
echo ""
echo "Available commands :"
echo "--toggle Toggle vpn on/off"
echo "--show Show icons"
exit 0
;;
esac