From 67812a9ae3136aaf76b1d83d561c5bc010951afe Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Thu, 4 Jul 2024 22:05:12 +0530 Subject: vpn: refactor --- vpn | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/vpn b/vpn index 0eef247..e1eb205 100755 --- a/vpn +++ b/vpn @@ -3,24 +3,18 @@ note() { command -v notify-send > /dev/null && - notify-send " vpn" "$1" + notify-send "󰒒 vpn" "$1" printf "\n%s\n" "$1" } -main() -{ - wg_conf="${1:-wg0}" - - if ip -details link show "$wg_conf" 2> /dev/null | grep --quiet "wireguard" - then - sudo -A -p " halt, authentication required: " wg-quick down "$wg_conf" && - note "connection was dropped" - else - sudo -A -p " init, authentication required: " wg-quick up "$wg_conf" && - note "traffic routed through $wg_conf" - fi && command -v wip > /dev/null && - wip -} +wg_conf="${1:-kay}" -main "$@" +if systemctl status "wg-quick-${wg_conf}.service" > /dev/null 2>&1; then + sudo -A systemctl stop "wg-quick-${wg_conf}.service" && + note "connection was dropped" +else + sudo -A systemctl start "wg-quick-${wg_conf}.service" && + note "traffic routed through $wg_conf" +fi && + command -v wip > /dev/null && wip -- cgit v1.2.3