2023-11-28 21:33:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. ~/.bin/_config
|
|
|
|
|
|
|
|
LIST="$(cat /etc/wireguard/vpnlist.txt)"
|
2023-12-17 11:58:59 +01:00
|
|
|
SEL="$(print "$LIST\ndeactivate\nhome" | cut -d' ' -f1 | $DMENU_CMD -l 20 -p "VPN")"
|
2023-11-28 21:33:15 +01:00
|
|
|
|
|
|
|
[ -z "$SEL" ] && exit 0
|
|
|
|
|
2024-01-08 23:06:28 +01:00
|
|
|
needs wireguard-tools--
|
|
|
|
|
2023-11-28 21:33:15 +01:00
|
|
|
if [ "$SEL" == "deactivate" ]
|
|
|
|
then
|
|
|
|
ACTIVE=$(ifconfig | grep wg-quick | cut -d: -f3 | tr -d " ")
|
|
|
|
if [ ! -z "$ACTIVE" ]
|
|
|
|
then
|
2023-12-21 22:27:23 +01:00
|
|
|
doas wg-quick down $ACTIVE && NOTIFY_CMD "VPN: disconnected"
|
2023-11-28 21:33:15 +01:00
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-01-08 23:06:28 +01:00
|
|
|
|
2023-11-28 21:33:15 +01:00
|
|
|
HOST="$(echo "$LIST" | fgrep "$SEL" | cut -d' ' -f2)"
|
|
|
|
|
|
|
|
cat /etc/wireguard/template.conf | sed "s/XXXXXX/$HOST/g" > /tmp/vpn.conf
|
|
|
|
|
|
|
|
doas mv /tmp/vpn.conf /etc/wireguard/vpn.conf
|
|
|
|
|
|
|
|
ACTIVE=$(ifconfig | grep wg-quick | cut -d: -f3 | tr -d " ")
|
|
|
|
if [ ! -z "$ACTIVE" ]
|
|
|
|
then
|
2023-12-21 22:27:23 +01:00
|
|
|
doas wg-quick down $ACTIVE && NOTIFY_CMD "VPN: disconnected"
|
2023-11-28 21:33:15 +01:00
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2023-12-21 22:27:23 +01:00
|
|
|
doas wg-quick up vpn && NOTIFY_CMD "VPN: $HOST"
|