#!/bin/bash # Run sudo visudo and whitelist your user, eg #qasim ALL=(ALL) NOPASSWD: /usr/local/bin/openfortivpn #qasim ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openfortivpn VPN_EXECUTABLE=/usr/local/bin/openfortivpn VPN_EXECUTABLE_PARAMS="-c $HOME/vpn" # Optional VPN_INTERFACE=ppp0 # Command to determine if VPN is connected or disconnected VPN_CONNECTED="/sbin/ifconfig | egrep -A1 $VPN_INTERFACE | grep inet" # Command to run to disconnect VPN VPN_DISCONNECT_CMD="sudo killall -2 openfortivpn" case "$1" in connect) # VPN connection command, should eventually result in $VPN_CONNECTED, # may need to be modified for VPN clients other than openconnect sudo "$VPN_EXECUTABLE" $VPN_EXECUTABLE_PARAMS &> /dev/null & # Wait for connection so menu item refreshes instantly until eval "$VPN_CONNECTED"; do sleep 1; done ;; disconnect) eval "$VPN_DISCONNECT_CMD" # Wait for disconnection so menu item refreshes instantly until [ -z "$(eval "$VPN_CONNECTED")" ]; do sleep 1; done ;; esac