Created
April 8, 2020 03:10
-
-
Save mbenford/d3d042b145c763074e7738ccb88e7940 to your computer and use it in GitHub Desktop.
Starts or stops a VPN connection
This file contains 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 | |
set -e | |
conn_id=$(nmcli conn show | grep vpn | awk '{print $2}' | head -n1) | |
if [ "$conn_id" == "" ]; then | |
echo "no VPN connection was found" | |
exit 1 | |
fi | |
is_active=$(nmcli conn show --active | grep "$conn_id" | wc -l) | |
if [ "$is_active" == "0" ]; then | |
nmcli con up $conn_id | |
exit 0 | |
fi | |
echo -n "there is an active VPN connection. disconnect? [y/N] "; read choice | |
if [[ "$choice" =~ [yY] ]]; then | |
nmcli con down $conn_id | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment