Allow passing credentials from environment

This commit is contained in:
Jānis Jansons
2020-12-18 01:40:20 +02:00
parent 164c46198b
commit 2d63b19af7
2 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ Rename routes.txt.sample to routes.txt or create an empty routes.txt and add sub
## Usage
```
sudo ./run-vpn.sh
sudo -E ./run-vpn.sh
```
In case of disconnect, it will try reconnecting after 3 seconds. You can stop it by pressing `CTRL+C` or killing the script.
+16
View File
@@ -1,10 +1,26 @@
#!/bin/bash
# Read from keychain on macOS by default
if [[ "$OSTYPE" == "darwin"* ]]; then
SERVER=$(security find-generic-password -l "Openconnect VPN Server" -w)
USERNAME=$(security find-generic-password -l "Openconnect Username" -w)
SEED=$(security find-generic-password -l "Openconnect TOTP Seed" -w)
PASSWORD=$(security find-generic-password -l "Openconnect Account Password" -w)
fi
# Allow reading from environment
if [[ -z "$OC_SERVER" ]]; then :; else
SERVER="$OC_SERVER"
fi
if [[ -z "$OC_USERNAME" ]]; then :; else
USERNAME="$OC_USERNAME"
fi
if [[ -z "$OC_SEED" ]]; then :; else
SEED="$OC_SEED"
fi
if [[ -z "$OC_PASSWORD" ]]; then :; else
PASSWORD="$OC_PASSWORD"
fi
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`