Created
March 31, 2020 12:43
-
-
Save qzaidi/0e2da06f39e8c72aa51f938b6593b4c0 to your computer and use it in GitHub Desktop.
Openfortivpn bitbar script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment