Created
July 18, 2021 12:39
-
-
Save bsless/04535eb299a1eaf29b4185ab7f6f9dbe to your computer and use it in GitHub Desktop.
Import and set up VPN connections from ovpn files in archive
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 | |
# Use this to unpack and import an archive | |
ARCHIVE="$1" | |
USERNAME="$2" | |
PASS="$3" | |
HERE="$PWD" | |
NOW=$(date +'%s.%N') | |
OUTDIR="/tmp/vpn.import.$NOW" | |
unzip "$ARCHIVE" -d "$OUTDIR" | |
cd "$OUTDIR" | |
for f in *.ovpn | |
do | |
name=$(basename "$f" .ovpn) | |
nmcli connection import type openvpn file $f | |
nmcli connection modify "${name}" +vpn.data username="${USERNAME}" | |
nmcli connection modify "${name}" +vpn.secrets password="${PASS}" | |
done | |
cd "$HERE" | |
rm -rfv "$OUTDIR" |
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 | |
# Use this only to set the password | |
USERNAME="$1" | |
PASS="$2" | |
for f in $(nmcli connection | grep vpn | cut -f1 -d' ') | |
do | |
name=$f | |
nmcli connection modify "${name}" +vpn.data username="${USERNAME}" | |
nmcli connection modify "${name}" +vpn.secrets password="${PASS}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment