Skip to content

Commit

Permalink
vpn-tun-status: add script
Browse files Browse the repository at this point in the history
  • Loading branch information
bw00lley authored Feb 5, 2024
1 parent 54a4833 commit f122dfa
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions polybar-scripts/vpn-tun-status/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Binary file added polybar-scripts/vpn-tun-status/screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added polybar-scripts/vpn-tun-status/screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions polybar-scripts/vpn-tun-status/vpn-tun-status.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f122dfa

Please sign in to comment.