Created
January 3, 2021 16:29
-
-
Save Bapannarama/8239be78a5e288e8159a153b7f950bb4 to your computer and use it in GitHub Desktop.
A small script to add OpenVPN profiles from PrivateInternetAccess to networkmanager
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
#!/bin/bash | |
echo -n "PIA username (pNNNNNNN): " | |
read pia_username | |
echo -n "PIA password: " | |
read -s pia_password | |
echo "" | |
echo -n "OpenVPN config files location (blank for current directory): " | |
read pia_directory | |
if [[ $pia_directory == '' ]] | |
then | |
pia_directory="$PWD/*" | |
elif [[ ${pia_directory: -2} == '/*' ]] | |
then | |
: | |
elif [[ ${pia_directory: -1} == '/' ]] | |
then | |
pia_directory="$pia_directory*" | |
elif [[ ${pia_directory: -1} != '/' ]] && [[ ${pia_directory: -1} != '*' ]] | |
then | |
pia_directory="$pia_directory/*" | |
fi | |
for filename in $pia_directory; do | |
echo "Adding profile for $filename" | |
remote_line=$(grep -rhP '[\w-]+.privacy.network' $filename) | |
IFS=" " read -ra remote <<< "$remote_line" | |
nmcli connection import type openvpn file "$filename" | |
nmcli connection modify $(basename "$filename" .ovpn) +vpn.data remote=${remote[1]} | |
nmcli connection modify $(basename "$filename" .ovpn) +vpn.data port=${remote[2]} | |
nmcli connection modify $(basename "$filename" .ovpn) +vpn.data username=$pia_username | |
nmcli connection modify $(basename "$filename" .ovpn) vpn.secrets password=$pia_password | |
done |
The certs should be copied to ~/.cert/nm-openvpn - each of the ovpn files have the cert embedded in them so it shouldn't be necessary to copy the cert separately.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script added the profiles, but none of them worked. Seems to be an issue with the certificate. Do the .opvpn files need to be in a specific location when running OVPN? I assumed this script would be similar to PIA's "pia-nm.sh" where all profiles used the same certificate located in "/etc/openvpn"