31 lines
1.0 KiB
Bash
31 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
## Script to toggle WireGuard tunnel using wg command for state determination
|
|
|
|
# Define the WireGuard interface name
|
|
WG_INTERFACE="wg0"
|
|
|
|
# Function to check if WireGuard interface is active
|
|
is_wg_active() {
|
|
sudo /usr/bin/wg show | grep -q "interface"
|
|
}
|
|
|
|
if is_wg_active; then
|
|
# If the interface is active, disable it
|
|
sudo /usr/bin/wg-quick down "$WG_INTERFACE"
|
|
if ! is_wg_active; then
|
|
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i network-vpn "WireGuard Tunnel" "Tunnel Deactivated"
|
|
else
|
|
notify-send --urgency=critical -i network-vpn "WireGuard Tunnel" "Error: Failed to deactivate tunnel"
|
|
fi
|
|
else
|
|
# If the interface is not active, enable it
|
|
sudo /usr/bin/wg-quick up "$WG_INTERFACE"
|
|
if is_wg_active; then
|
|
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i network-vpn "WireGuard Tunnel" "Tunnel Activated"
|
|
else
|
|
notify-send --urgency=critical -i network-vpn "WireGuard Tunnel" "Error: Failed to activate tunnel"
|
|
fi
|
|
fi
|
|
|