aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/waybar/executable_snx-vpn-status.sh
blob: 90886303f94af022edcf179832b9cc02a92e94ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
# Waybar custom/snx-vpn module: report the snx-rs (Check Point) tunnel
# state. `snxctl status` is fast (talks over a local UDS to the daemon)
# but might briefly stall during connect; cap it with `timeout`.

# Bail out if the daemon socket isn't even there (snx-rs.service stopped).
out=$(timeout 2 snxctl status 2>/dev/null) || out=

case "$out" in
  '' | *"Disconnected"*)
    printf '{"text":"<span color=\\"#928374\\"><s>󰌾 SNX</s></span>","class":"down","tooltip":"snx-rs disconnected — click to connect"}\n'
    ;;
  *"Connecting"* | *"MFA pending"*)
    printf '{"text":"<span color=\\"#fabd2f\\">󰌾 SNX…</span>","class":"connecting","tooltip":"%s"}\n' "$(echo "$out" | head -1)"
    ;;
  *)
    tooltip=$(echo "$out" | sed 's/"/\\"/g' | awk 'BEGIN{ORS="\\n"}{print}')
    printf '{"text":"<span color=\\"#b8bb26\\">󰌾 SNX</span>","class":"up","tooltip":"%s"}\n' "$tooltip"
    ;;
esac