diff options
author | Tim Keller <tjkeller.xyz> | 2024-11-17 23:34:54 -0600 |
---|---|---|
committer | Tim Keller <tjkeller.xyz> | 2024-11-17 23:34:54 -0600 |
commit | 09ada24d4ec23cf24ab136141b354953d1bbc2fa (patch) | |
tree | 2c41e87c71ad3f3cd67a8bea0c1413efbab4087d /.old/wgconnect | |
parent | 090a3a31683eb08b91351e4d1508a0a73a310a38 (diff) | |
download | scripts-09ada24d4ec23cf24ab136141b354953d1bbc2fa.tar.xz scripts-09ada24d4ec23cf24ab136141b354953d1bbc2fa.zip |
reorganize scripts
Diffstat (limited to '.old/wgconnect')
-rwxr-xr-x | .old/wgconnect | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/.old/wgconnect b/.old/wgconnect new file mode 100755 index 0000000..de8f307 --- /dev/null +++ b/.old/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" |