From b7c041211b20552acd2fa5a96ccfb444156bb01a Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 28 Sep 2022 19:36:25 +0200 Subject: waybar: replace mullvad module with generic vpn module can also detect if we use tailscale exit node --- .config/waybar/config.jsonc | 30 ++++++++++++++++++++++++------ .config/waybar/modules/vpn.sh | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100755 .config/waybar/modules/vpn.sh diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index d30d87a..ae3f54c 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -104,9 +104,18 @@ "return-type": "json" }, + "custom/hotspots": { + "format": "{}", + "exec": "$HOME/.config/waybar/modules/hotspots.sh", + "on-click": "$HOME/.config/waybar/modules/hotspots.sh click", + "escape": true, + "interval": 600, + "return-type": "json" + }, + // ------------------------------------------------------------------------ // // "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#mullvad", "network#tailscale", "network", "battery"], - "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "custom/gamma", "pulseaudio", "network#mullvad", "network#tailscale", "network", "battery"], + "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "custom/gamma", "pulseaudio", "custom/vpn", "network#tailscale", "network", "battery"], "tray": { "spacing": 10 @@ -206,15 +215,24 @@ "on-click": "swx -t -F '0.4' pulsemixer" }, - "network#mullvad": { - "interface": "mlvd*", - "format": "󰒃", - "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", - "tooltip-format-disconnected": "disconnected", + "custom/vpn": { + "exec": "${HOME}/.config/waybar/modules/vpn.sh", + "interval": 600, + "return-type": "json" }, + + // "network#mullvad": { + // "interface": "mlvd*", + // "format": "󰒃", + // "format-disconnected": "", + // "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", + // "tooltip-format-disconnected": "disconnected", + // }, + "network#tailscale": { "interface": "tailscale0", "format": "󰌆", + "format-disconnected": "", "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", "tooltip-format-disconnected": "disconnected", "on-click": "doas rc-service tailscale start", diff --git a/.config/waybar/modules/vpn.sh b/.config/waybar/modules/vpn.sh new file mode 100755 index 0000000..4fc5bdd --- /dev/null +++ b/.config/waybar/modules/vpn.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e +[ -n "$DEBUG" ] && set -x + +extern_ip=$(curl -SsfL http://api.ipify.org/?format=text) + +vpn_is_up() { + case "$extern_ip" in + 138.201.245.159) return 0 ;; # hetzner node + esac + return 1 +} + +if vpn_is_up; then + printf '{"text": "󰒃 ", "tooltip": "external ip is %s"}\n' "$extern_ip" +else + printf '{}\n' +fi -- cgit 1.4.1