From d8a667f9beb8ea34f1c4a195273fbcda4479ee19 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 5 May 2025 20:56:59 +0200 Subject: [PATCH] bin/vpn: advanced handling --- .local/bin/scripts/vpn | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.local/bin/scripts/vpn b/.local/bin/scripts/vpn index 707ae76..db0a31e 100755 --- a/.local/bin/scripts/vpn +++ b/.local/bin/scripts/vpn @@ -4,8 +4,11 @@ case "$1" in ("") tmux new-session -s "vpn" "tmux ls; $SHELL";; (forti) if ip route | grep -q ppp0 - then echo "Device ppp0 already in use!" - else sudo tmux new-session -s "$1" ' + then printf "Device ppp0 already in use - press Enter to kill" + read -r _ + sudo killall openfortivpn + fi + sudo tmux new-session -s "$1" ' set -x route="$(ip route | grep default | sort | head -1)" # Start openfortivpn in the background @@ -13,7 +16,7 @@ case "$1" in VPN_PID=$! # Wait a little for the VPN to establish the connection sleep 5 -# TODO Loop + # TODO Loop # Delete the default route set by openfortivpn (ppp0) ip route del default dev ppp0 # Add the default route via the local network @@ -22,8 +25,10 @@ case "$1" in ip route wait $VPN_PID echo "VPN has disconnected." + ip dev del ppp0; ' - fi ;; - (*) tmux new-session -s "$@" "sudo openvpn $@ || read";; + (*) test -f "$1" || file=$(find $1* -name '*.ovpn') + cd "$(dirname "$file")" && file="$(basename "$file")" + tmux new-session -s "$@" "sudo openvpn ${file:-$@} || read" esac