From: Dmitry Fedotov Date: Mon, 8 Mar 2021 18:49:24 +0000 (+0300) Subject: Add vpn i3block. X-Git-Url: https://git.dmfe.net/?a=commitdiff_plain;h=5bf649de603236e17265ad4c1ee23545e7fdfd9e;p=dotfiles Add vpn i3block. --- diff --git a/config/i3blocks/config b/config/i3blocks/config index 9e0a97e..f6cfc16 100644 --- a/config/i3blocks/config +++ b/config/i3blocks/config @@ -136,3 +136,7 @@ command=~/scripts/keymap-switch.sh | ~/scripts/i3b-formatter.sh signal=5 interval=once min_width=xxx us + +[vpn] +command=~/scripts/vpn/vpn-status | ~/scripts/i3b-formatter.sh +interval=15 diff --git a/scripts/vpn/l2tp b/scripts/vpn/l2tp index ee95f4d..06f458c 100755 --- a/scripts/vpn/l2tp +++ b/scripts/vpn/l2tp @@ -11,19 +11,19 @@ connect() { local vpn_name=$1 echo "connecting (VPN Name: $1)..." - ipsec up ${vpn_name} - echo "c ${vpn_name}" > /var/run/xl2tpd/l2tp-control + sudo ipsec up ${vpn_name} + echo "c ${vpn_name}" | sudo tee /var/run/xl2tpd/l2tp-control sleep 5 - route add default dev ppp0 + sudo route add default dev ppp0 } disconnect() { local vpn_name=$1 echo "disconnecting (VPN Name: ${vpn_name})..." - route del default dev ppp0 - echo "d ${vpn_name}" > /var/run/xl2tpd/l2tp-control - ipsec down ${vpn_name} + sudo route del default dev ppp0 + echo "d ${vpn_name}" | sudo tee /var/run/xl2tpd/l2tp-control + sudo ipsec down ${vpn_name} } die() { diff --git a/scripts/vpn/vpn-status b/scripts/vpn/vpn-status new file mode 100755 index 0000000..6c2c38b --- /dev/null +++ b/scripts/vpn/vpn-status @@ -0,0 +1,15 @@ +#!/bin/sh + +icon= +vpn_name=$(sudo ipsec status | awk '/ESTABLISHED/ { print $1 }' | sed 's/\[.*\]://') + +[[ ${vpn_name} ]] || exit + +case $BLOCK_BUTTON in + 1) + notify-send "VPN Name: ${vpn_name}" + ;; +esac + +printf '%s\n' "${icon}" +