summaryrefslogtreecommitdiff
path: root/sh/vpn
blob: a7387ac53a1e1bcfea7e41f272f541b90cc869eb (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
#!/bin/sh
# toggle VPN

down_not_master () {
	git -C "$HOME/programs/config_local_arch" branch | awk '!/pp/{print ($1=="*")?$2:$1}' | while read -r v; do
		nmcli connection down "wg_$v"
	done
}

# no toggle wg_master, I want wg_master to always on by default
if ! [ "$1" ] || [ "$1" = master ]; then
	down_not_master
	nmcli connection up wg_master
	notify-send -u critical 'VPN disabled'
	exit
fi

if nmcli -t --fields device,state device | grep -q "^wg_$1:connected$"; then
	down_not_master
	nmcli connection up wg_master
	notify-send -u critical "$1 VPN disabled"
else
	if [ "$1" = aa ]; then
		/usr/bin/alacritty -T aa --hold -e sh -c 'echo "Wait for aa sudo prompt and enter password, then manually close this window"; ssh -t aawg "sudo systemctl stop wg-quick@wg_ib && sudo systemctl start wg-quick@wg0"'
	fi
	down_not_master
	nmcli connection down wg_master
	nmcli connection up "wg_$1"
	notify-send "$1 VPN enabled"
fi