-
-
Save rhowe-gds/dda45cd739cc2f324b3e656f9f76a312 to your computer and use it in GitHub Desktop.
VPN connection script
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
#!/usr/bin/env bash | |
set -euo pipefail | |
usage="$0: <up|down> [connection name]" | |
action="${1?$usage}" | |
connection="${2:-GDS VPN Developer}" | |
oath_key=vpn | |
pass_key=gds/vpn | |
case "$action" in | |
up) | |
otp=$(ykman oath code "$oath_key" | awk '/[0-9]$/ { print $NF; }') | |
: "${otp:?OTP not found}" | |
password=$(pass "$pass_key") | |
# Shut down the GUI app, which doesn't get along with the CLI tool | |
pkill "Cisco AnyConnect Secure Mobility Client" || : | |
echo -e "${USER}\n${password}\n${otp}" | \ | |
/opt/cisco/anyconnect/bin/vpn -s connect "$connection" | \ | |
grep --line-buffered -Fv 'Second Password' | |
;; | |
down) | |
/opt/cisco/anyconnect/bin/vpn -s disconnect | |
;; | |
*) | |
echo "$usage" >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment