nix-conf/home/config/scripts/wgStatus.sh
2025-03-10 16:39:41 +08:00

20 lines
544 B
Bash
Executable file

#!/usr/bin/env bash
INTERFACE="wg0"
if [ "$1" = "toggle" ]; then
if ip link show "$INTERFACE" >/dev/null 2>&1; then
pkexec wg-quick down "$INTERFACE"
else
pkexec wg-quick up "$INTERFACE"
fi
exit 0
fi
if ! ip link show "$INTERFACE" >/dev/null 2>&1; then
echo "{\"text\": \"Not Connected\", \"tooltip\": \"WireGuard is down\", \"alt\": \"disconnected\", \"class\": \"disconnected\"}"
exit 0
fi
echo "{\"text\": \"Connected\", \"tooltip\": \"WireGuard connected\", \"alt\": \"connected\", \"class\": \"connected\"}"
exit 0