summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorXiao Pan <gky44px1999@gmail.com>2024-07-03 12:21:12 -0700
committerXiao Pan <gky44px1999@gmail.com>2024-07-03 12:21:12 -0700
commitca558195f9cc480ada30a045ed0cd5b29ca01e7d (patch)
treefa3bca33a04dd02afa000b5232399c2c17bffac6 /sh
parente9a3936e5a91aa2ee75526f5711248f731032266 (diff)
fix: vpn need restore wg defaults at aa for all insp to aa connection down situations
Diffstat (limited to 'sh')
-rwxr-xr-xsh/vpn17
1 files changed, 12 insertions, 5 deletions
diff --git a/sh/vpn b/sh/vpn
index 0c467cc..5ef5017 100755
--- a/sh/vpn
+++ b/sh/vpn
@@ -7,8 +7,19 @@ down_not_mydefault () {
done
}
+wg_aa_restore_default () {
+ # case seems faster than pipe to grep maybe because case is shell built-in, so I use case
+ # if nmcli -t --fields device,state device | grep -q '^wg_aa:connected$'; then ...; fi
+ case "$(nmcli -t --fields device,state device)" in
+ # 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
+ *wg_aa:connected*) /usr/bin/alacritty -T aa --hold -e sh -c 'echo "Wait for aa sudo prompt and enter password, then manully close this window:"; ssh -t aa.flylightning.xyz "sudo systemctl stop wg-quick@wg0 && sudo systemctl start wg-quick@wg_ca"';;
+ esac
+}
+
# no toggle wg_mydefault, I want wg_mydefault to always on by default
if ! [ "$1" ] || [ "$1" = mydefault ]; then
+ wg_aa_restore_default
down_not_mydefault
nmcli connection up wg_mydefault
notify-send -u critical 'VPN disabled'
@@ -16,11 +27,7 @@ if ! [ "$1" ] || [ "$1" = mydefault ]; then
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 sh -c 'echo "Wait for aa sudo prompt and enter password, then manully close this window:"; ssh -t aa.flylightning.xyz "sudo systemctl stop wg-quick@wg0 && sudo systemctl start wg-quick@wg_ca"'
- fi
+ wg_aa_restore_default
down_not_mydefault
nmcli connection up wg_mydefault
notify-send -u critical "$1 VPN disabled"