blob: 9811453018a9aa481f0210161d6c2f0658d9c358 (
plain)
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
|
#!/bin/sh
# toggle VPN
down_not_mydefault () {
for v in wg_studio wg_ia wg_aa; do
nmcli connection down "$v"
done
}
# no toggle wg_mydefault, I want wg_mydefault to always on by default
if ! [ "$1" ] || [ "$1" = mydefault ]; then
down_not_mydefault
nmcli connection up wg_mydefault
notify-send -u critical 'VPN disabled'
exit
fi
if nmcli -t --fields device,state device | grep -q "^wg_$1:connected$"; then
if [ "$1" = aa ]; then
# stop aa wireguard+swgp server that listen from insp wiregurad+swgp client, start aa wg+swgp connect to ca
# use /usr/bin/alacritty instead of /home/xyz/.local/bin/alacritty so script can wait until alacritty exit to run other codes following
/usr/bin/alacritty -T aa --hold -e ssh -t aa.flylightning.xyz 'sudo systemctl stop wg-quick@wg0 && sudo systemctl start wg-quick@wg_ca'
fi
down_not_mydefault
nmcli connection up wg_mydefault
notify-send -u critical "$1 VPN disabled"
else
if [ "$1" = aa ]; then
/usr/bin/alacritty -T aa --hold -e ssh -t aa.flylightning.xyz 'sudo systemctl stop wg-quick@wg_ca && sudo systemctl start wg-quick@wg0'
fi
down_not_mydefault
nmcli connection down wg_mydefault
nmcli connection up "wg_$1"
notify-send "$1 VPN enabled"
fi
|