From cb3c071e4d426fb933309f55bbbff296f6ae21ce Mon Sep 17 00:00:00 2001 From: bw00lley Date: Thu, 1 Feb 2024 23:20:57 +0000 Subject: [PATCH 1/4] Added a script that shows the IP address for each active tun adapter. --- polybar-scripts/vpn-tunX-ip/README.md | 26 ++++++++++++++++++ polybar-scripts/vpn-tunX-ip/screenshots/1.png | Bin 0 -> 894 bytes polybar-scripts/vpn-tunX-ip/screenshots/2.png | Bin 0 -> 894 bytes polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh | 22 +++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 polybar-scripts/vpn-tunX-ip/README.md create mode 100644 polybar-scripts/vpn-tunX-ip/screenshots/1.png create mode 100644 polybar-scripts/vpn-tunX-ip/screenshots/2.png create mode 100644 polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh diff --git a/polybar-scripts/vpn-tunX-ip/README.md b/polybar-scripts/vpn-tunX-ip/README.md new file mode 100644 index 00000000..a0306be0 --- /dev/null +++ b/polybar-scripts/vpn-tunX-ip/README.md @@ -0,0 +1,26 @@ +# Script: { vpn-tunX-ip } + +{ A script that shows the IP address for each active tun adapter, if one is active, or if not indicates the VPN connection is down. } + +![skeleton](screenshots/1.png) +![skeleton](screenshots/2.png) + + +## Dependencies + +{ Requires extremely common standard commands: ip, jq and wc. } + + +## Configuration + +{ You can edit the format lines in the script according to your taste. } + + +## Module + +```ini +[module/vpn-tunX-ip] +type = custom/script +exec = ~/polybar-scripts/vpn-tunX-ip.sh +interval = 5 +``` diff --git a/polybar-scripts/vpn-tunX-ip/screenshots/1.png b/polybar-scripts/vpn-tunX-ip/screenshots/1.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f150d49d5f2825664aad9971d9c4f2fdc26867 GIT binary patch literal 894 zcmV-^1A+XBP)?WfKjCG@{8|JiDWR{i{VT=k2iY^+Z7!^?z zg#?9RUQ&v%){5v;W>9@_&MDeWnWqmi$#l1pVx05)cFyzupZ5>XIqx~=J&K8wl0;-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N<$f|M(!A^-pY literal 0 HcmV?d00001 diff --git a/polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh b/polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh new file mode 100644 index 00000000..19520eed --- /dev/null +++ b/polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.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 From fdc5e707f25e8eabfb27f283b804b4fec427faf6 Mon Sep 17 00:00:00 2001 From: bw00lley Date: Thu, 1 Feb 2024 23:24:45 +0000 Subject: [PATCH 2/4] vpn-tunX-ip: updated README.md --- polybar-scripts/vpn-tunX-ip/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polybar-scripts/vpn-tunX-ip/README.md b/polybar-scripts/vpn-tunX-ip/README.md index a0306be0..18173b07 100644 --- a/polybar-scripts/vpn-tunX-ip/README.md +++ b/polybar-scripts/vpn-tunX-ip/README.md @@ -1,6 +1,6 @@ -# Script: { vpn-tunX-ip } +# Script: vpn-tunX-ip -{ A script that shows the IP address for each active tun adapter, if one is active, or if not indicates the VPN connection is down. } +A script that shows the IP address for each active tun adapter, or a message if ther are no active tun adapters. ![skeleton](screenshots/1.png) ![skeleton](screenshots/2.png) @@ -8,12 +8,12 @@ ## Dependencies -{ Requires extremely common standard commands: ip, jq and wc. } +Requires extremely common standard commands: ip, jq and wc. ## Configuration -{ You can edit the format lines in the script according to your taste. } +You can edit the format variables in the script according to your taste. ## Module From 658f9d2973ee6118df5812a8112d3b11474fda88 Mon Sep 17 00:00:00 2001 From: bw00lley Date: Thu, 1 Feb 2024 23:29:22 +0000 Subject: [PATCH 3/4] vpn-tunX-ip: updated README.md --- polybar-scripts/vpn-tunX-ip/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybar-scripts/vpn-tunX-ip/README.md b/polybar-scripts/vpn-tunX-ip/README.md index 18173b07..f672ab19 100644 --- a/polybar-scripts/vpn-tunX-ip/README.md +++ b/polybar-scripts/vpn-tunX-ip/README.md @@ -8,7 +8,7 @@ A script that shows the IP address for each active tun adapter, or a message if ## Dependencies -Requires extremely common standard commands: ip, jq and wc. +Requires extremely common standard commands: ip, jq and grep. ## Configuration From f8716d912a0d724a7a05977efa27f1a408f0bcef Mon Sep 17 00:00:00 2001 From: x70b1 Date: Mon, 5 Feb 2024 11:41:56 +0100 Subject: [PATCH 4/4] rename script to vpn-tun-status --- polybar-scripts/vpn-tun-status/README.md | 21 ++++++++++++++ .../screenshots/1.png | Bin .../screenshots/2.png | Bin .../vpn-tun-status.sh} | 4 +-- polybar-scripts/vpn-tunX-ip/README.md | 26 ------------------ 5 files changed, 23 insertions(+), 28 deletions(-) create mode 100644 polybar-scripts/vpn-tun-status/README.md rename polybar-scripts/{vpn-tunX-ip => vpn-tun-status}/screenshots/1.png (100%) rename polybar-scripts/{vpn-tunX-ip => vpn-tun-status}/screenshots/2.png (100%) rename polybar-scripts/{vpn-tunX-ip/vpn-tunX-ip.sh => vpn-tun-status/vpn-tun-status.sh} (94%) delete mode 100644 polybar-scripts/vpn-tunX-ip/README.md 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-tunX-ip/screenshots/1.png b/polybar-scripts/vpn-tun-status/screenshots/1.png similarity index 100% rename from polybar-scripts/vpn-tunX-ip/screenshots/1.png rename to polybar-scripts/vpn-tun-status/screenshots/1.png diff --git a/polybar-scripts/vpn-tunX-ip/screenshots/2.png b/polybar-scripts/vpn-tun-status/screenshots/2.png similarity index 100% rename from polybar-scripts/vpn-tunX-ip/screenshots/2.png rename to polybar-scripts/vpn-tun-status/screenshots/2.png diff --git a/polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh b/polybar-scripts/vpn-tun-status/vpn-tun-status.sh similarity index 94% rename from polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh rename to polybar-scripts/vpn-tun-status/vpn-tun-status.sh index 19520eed..aad94a32 100644 --- a/polybar-scripts/vpn-tunX-ip/vpn-tunX-ip.sh +++ b/polybar-scripts/vpn-tun-status/vpn-tun-status.sh @@ -7,7 +7,7 @@ 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 +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 \ @@ -16,7 +16,7 @@ if [ "$TUNTAPS" != "0" ]; then | jq -r 'join(", ")'\ ) echo "$FORMAT_UP$MESSAGE_UP" -else +else MESSAGE_DOWN='VPN down' echo "$FORMAT_DOWN$MESSAGE_DOWN" fi diff --git a/polybar-scripts/vpn-tunX-ip/README.md b/polybar-scripts/vpn-tunX-ip/README.md deleted file mode 100644 index f672ab19..00000000 --- a/polybar-scripts/vpn-tunX-ip/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Script: vpn-tunX-ip - -A script that shows the IP address for each active tun adapter, or a message if ther are no active tun adapters. - -![skeleton](screenshots/1.png) -![skeleton](screenshots/2.png) - - -## Dependencies - -Requires extremely common standard commands: ip, jq and grep. - - -## Configuration - -You can edit the format variables in the script according to your taste. - - -## Module - -```ini -[module/vpn-tunX-ip] -type = custom/script -exec = ~/polybar-scripts/vpn-tunX-ip.sh -interval = 5 -```