diff options
author | Timmy Keller <tjk@tjkeller.xyz> | 2024-02-02 13:42:12 -0600 |
---|---|---|
committer | Timmy Keller <tjk@tjkeller.xyz> | 2024-02-02 13:42:12 -0600 |
commit | 4063c8f3f1808b114d15186f24817f269a88ce4e (patch) | |
tree | c00e37275238bb56499649c2ffcb054949b256c0 | |
parent | 5eec52989435efacd26ee691ab0ee2e2bf88fe35 (diff) | |
download | scripts-4063c8f3f1808b114d15186f24817f269a88ce4e.tar.xz scripts-4063c8f3f1808b114d15186f24817f269a88ce4e.zip |
wgconnect script added
-rwxr-xr-x | keyboard/wgconnect | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/keyboard/wgconnect b/keyboard/wgconnect new file mode 100755 index 0000000..de8f307 --- /dev/null +++ b/keyboard/wgconnect @@ -0,0 +1,40 @@ +#!/bin/sh +# Connect to/disconnect from wireguard tunnel using dmenu + +sudo="${SUDO:-sudo}" +pass="$(xsudo --get-pass)" + +ssudo() { echo "$pass" | $sudo $@ ; } + +dmenu_confirm_continue() { + case "$(echo "yes\nno" | dmenu -p "$1")" in + yes) + ;; + *) exit 0 ;; + esac +} + +curtun="$(ssudo wg show | sed 's/interface: //;q')" + +# Ask to disconnect from current interface +if [ -n "$curtun" ]; then + dmenu_confirm_continue "Currently connected to tunnel $curtun. Disconnect?" + + output="$(ssudo wg-quick down "$curtun" 2>&1)" + notify-send "Disconnected from $curtun" "$output" + + dmenu_confirm_continue "Connect to another interface?" +fi + +# Connect to new interface +tundir=/etc/wireguard + +tun="$tundir/$(ssudo ls "$tundir" | grep "\.conf$" | dmenu -p "Connect to which tunnel?")" + +if ! ssudo cat $tun >/dev/null 2>/dev/null; then + notify-send "Couldn't connect to tunnel $tun" + exit 1 +fi + +output="$(ssudo wg-quick up "$tun" 2>&1)" +notify-send "Connected to $tun" "$output" |