[ADD][SCRIPTS] VPN toggle w/ password prompt

This commit is contained in:
Bruno BELANYI 2020-08-20 13:00:07 +02:00
parent 99c5a8148c
commit 87d46ed8e7
2 changed files with 41 additions and 0 deletions

View File

@ -64,6 +64,7 @@ CLI_DEPENDENCIES := \
VISUAL_DEPENDENCIES := \
aur/bitwarden-rofi \
aur/gnome-ssh-askpass3 \
aur/i3-battery-popup-git \
aur/i3blocks-contrib-git \
aur/networkmanager-dmenu-git \

40
scripts/toggle-vpn Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
INTERFACE=wg0
if [ "$1" = '--visual' ]; then
USE_X=1
shift
fi
case "$1" in
up|down)
;;
*)
echo "Unkown command '$1'" >&2
echo "Usage: '$0 [--visual] <up|down>'" >&2
exit 1
;;
esac
notify() {
if [ -n "$USE_X" ]; then
notify-send -u "${2:-low}" "$1" \
-h string:x-canonical-private-synchronous:vpn-toggle # Overwrite
else
echo "$1" >&2
fi
}
toggle() {
# Explicitely do not use quotes when expanding '-A' argument
SUDO_ASKPASS="${USE_X+/usr/lib/ssh/gnome-ssh-askpass3}" \
sudo ${USE_X+-A} wg-quick "$1" "$INTERFACE"
}
if ! toggle "$1"; then
notify "Could not toggle VPN" critical
exit 1
fi
notify "Toggled VPN (${1})"