Skip to content

Instantly share code, notes, and snippets.

@bsless
Created July 18, 2021 12:39
Show Gist options
  • Save bsless/04535eb299a1eaf29b4185ab7f6f9dbe to your computer and use it in GitHub Desktop.
Save bsless/04535eb299a1eaf29b4185ab7f6f9dbe to your computer and use it in GitHub Desktop.
Import and set up VPN connections from ovpn files in archive
#!/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"
#!/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