diff --git a/polybar-scripts/vpn-tun-status/README.md b/polybar-scripts/vpn-tun-status/README.md new file mode 100644 index 00000000..e829b5b3 --- /dev/null +++ b/polybar-scripts/vpn-tun-status/README.md @@ -0,0 +1,21 @@ +# Script: vpn-tun-status + +A script that shows the IP address for each active tun adapter. + +![vpn-tun-status](screenshots/1.png) +![vpn-tun-status](screenshots/2.png) + + +## Dependencies + +* `jq` + + +## Module + +```ini +[module/vpn-tun-status] +type = custom/script +exec = ~/polybar-scripts/vpn-tunX-ip.sh +interval = 10 +``` diff --git a/polybar-scripts/vpn-tun-status/screenshots/1.png b/polybar-scripts/vpn-tun-status/screenshots/1.png new file mode 100644 index 00000000..d5f150d4 Binary files /dev/null and b/polybar-scripts/vpn-tun-status/screenshots/1.png differ diff --git a/polybar-scripts/vpn-tun-status/screenshots/2.png b/polybar-scripts/vpn-tun-status/screenshots/2.png new file mode 100644 index 00000000..4a20e3df Binary files /dev/null and b/polybar-scripts/vpn-tun-status/screenshots/2.png differ diff --git a/polybar-scripts/vpn-tun-status/vpn-tun-status.sh b/polybar-scripts/vpn-tun-status/vpn-tun-status.sh new file mode 100644 index 00000000..aad94a32 --- /dev/null +++ b/polybar-scripts/vpn-tun-status/vpn-tun-status.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Set format options +FORMAT_UP='' +FORMAT_DOWN='%{F#FF0000}' + +# Count the number of tun adapters, e.g. tun0, tun1, etc +TUNTAPS=$(ip -j tuntap list | jq -r '.[].ifname' | grep -c '^tun' ) + +if [ "$TUNTAPS" != "0" ]; then + # This filters the JSON output from ip to show "name ip.ip.ip.ip" for each adapter + MESSAGE_UP=$(\ + ip -4 -j addr show \ + | jq '[ .[] | select( .ifname | startswith("tun")) | [ .ifname, .addr_info[0].local ] ]'\ + | jq '[ .[] | join(" ") ]' \ + | jq -r 'join(", ")'\ + ) + echo "$FORMAT_UP$MESSAGE_UP" +else + MESSAGE_DOWN='VPN down' + echo "$FORMAT_DOWN$MESSAGE_DOWN" +fi