diff options
Diffstat (limited to 'config/waybar/scripts')
| -rwxr-xr-x | config/waybar/scripts/ivpn.sh | 38 | ||||
| -rwxr-xr-x | config/waybar/scripts/mullvad.sh | 37 |
2 files changed, 38 insertions, 37 deletions
diff --git a/config/waybar/scripts/ivpn.sh b/config/waybar/scripts/ivpn.sh new file mode 100755 index 0000000..9ff88fc --- /dev/null +++ b/config/waybar/scripts/ivpn.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +ivpn_status_output () { + ivpn status +} + +ivpn_connected () { + ivpn status | grep -q '^VPN.*: CONNECTED' +} + +toggle_status () { + if ivpn_connected; then + ivpn disconnect + else + ivpn connect -f + fi +} + +case $1 in + --status) + status_output="$(ivpn_status_output)" + if echo "$status_output" | grep -q '^VPN.*: CONNECTED'; then + # Line after "VPN : CONNECTED" holds server + location, + # e.g. "de.gw.ivpn.net [de3.gw.ivpn.net], Frankfurt (DE), Germany" + server_line=$(echo "$status_output" | awk '/^VPN.*CONNECTED/{getline; sub(/^[ \t]+/, ""); print}') + protocol=$(echo "$status_output" | awk -F': ' '/^[ \t]*Protocol/{print $2}') + server_ip=$(echo "$status_output" | awk -F': ' '/^[ \t]*Server IP/{print $2}') + endpoint="${server_line%%,*} (${protocol})" + location="${server_line#*, } (${server_ip})" + echo "{\"text\":\"\",\"class\":\"connected\",\"alt\":\"connected\", \"tooltip\": \"${endpoint}\\n${location}\"}" + else + echo "{\"text\":\"\",\"class\":\"disconnected\",\"alt\":\"disconnected\", \"tooltip\": \"VPN is not active.\"}" + fi + ;; + --toggle) + toggle_status + ;; +esac diff --git a/config/waybar/scripts/mullvad.sh b/config/waybar/scripts/mullvad.sh deleted file mode 100755 index e02bb2f..0000000 --- a/config/waybar/scripts/mullvad.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -STATUS_KEY="state" -RUNNING="connected" - -mullvad_status () { - status="$(mullvad status --json | jq -r '.'$STATUS_KEY)" - if [ "$status" = $RUNNING ]; then - return 0 - fi - return 1 -} - -toggle_status () { - if mullvad_status; then - mullvad disconnect - else - mullvad connect - fi -} - -case $1 in - --status) - if mullvad_status; then - status_json=$(mullvad status --json) - endpoint=$(echo "$status_json" | jq -r '.details.endpoint | "\(.tunnel_interface) (\(.tunnel_type))"') - location=$(echo "$status_json" | jq -r '.details.location | "\(.country), \(.city) (\(.ipv4))"') - echo "{\"text\":\"\",\"class\":\"connected\",\"alt\":\"connected\", \"tooltip\": \"${endpoint}\\n${location}\"}" - else - echo "{\"text\":\"\",\"class\":\"disconnected\",\"alt\":\"disconnected\", \"tooltip\": \"VPN is not active.\"}" - fi - ;; - --toggle) - toggle_status - ;; -esac - |