Last active
August 21, 2018 00:31
-
-
Save keuv-grvl/2163bb8f4b75b02c1223ac49d73505d8 to your computer and use it in GitHub Desktop.
Toggle a given VPN, eventually ask for password
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
#!/usr/bin/env bash | |
# usage: toggle-vpn.sh vpn-name | |
set -e # this script exits on error | |
set -o pipefail # a pipeline returns error code if any command fails | |
set -u # unset variables as an error, and immediately exit | |
command -v nmcli > /dev/null # ensure nmcli is installed | |
VPN=$1 | |
# ensure we do not try to shutdown ethernet or wifi | |
nmcli con | grep vpn | cut -d' ' -f1 | grep "^${VPN}$" > /dev/null | |
# try to shutdown, otherwise try to connect without passwd, otherwise ask for it | |
nmcli con down $VPN || nmcli con up $VPN || nmcli --ask con up $VPN ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment