dotfiles/.local/bin/vpn-toggle
2025-03-13 09:37:39 -06:00

17 lines
687 B
Bash
Executable File

#!/usr/bin/env zsh
exec </dev/null
# Toggles the GlobalProtect VPN connection on and off
# Get the current state of the VPN connection
if pgrep gpclient &>/dev/null; then
# VPN is connected, so disconnect
echo "Disconnecting from VPN..."
systemctl stop usu-gpclient
else
# VPN is disconnected, so connect
echo "Connecting to VPN..."
systemd-run --unit=usu-gpclient --setenv=SUDO_USER=$(whoami) --setenv=SUDO_UID=$(id -u) --setenv=SUDO_GID=$(id -g) --setenv=SUDO_HOME=$HOME --setenv=DISPLAY=$DISPLAY --setenv=XAUTHORITY=$XAUTHORITY -- /usr/sbin/gpclient --fix-openssl connect gp.usu.edu
sudo nft add element inet router vpn_cgroups \{ '"system.slice/usu-gpclient.service"' \}
fi