aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/waybar/executable_vpn-toggle.sh
blob: df13a3d95fb4cad92fc83568161ef3e325328ede (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# Toggle the wireguard interface managed by systemd-networkd. Polkit
# rule (etc/polkit-1/rules.d/50-networkd-wheel.rules) lets wheel-group
# members invoke networkctl up/down without a password prompt.
#
# After the state change, send SIGRTMIN+8 to waybar so the custom/vpn
# module refreshes immediately instead of waiting for the next interval.

set -eu

iface=hodor

if ip link show "$iface" 2>/dev/null | grep -qE '<[^>]*\<UP\>'; then
  networkctl down "$iface"
else
  networkctl up "$iface"
fi

# Refresh waybar's custom/vpn module right away.
pid=$(pidof waybar || true)
[ -n "$pid" ] && kill -SIGRTMIN+8 "$pid" 2>/dev/null || true