NordVPN add all ovpn servers to nmcli and {gnome || kde}

This is simple script for import many ovpn config together with a password to nmcli . In current 0.4 version import  only configs  .
How it`s work.

Script finding  all ovpn files in directory and result assign to variable “a”

a=$(ls *.ovpn)
if [[ `echo $a | wc | awk '{print $2}'` -eq 0 ]]; then
 echo "Ovpn filne in $PWD do not found "
 exit 1

While iterating variable a line by line

printf '%s\n' "$a" | while IFS= read -r line

Prepare short name is it more readable  in gnome

conname=$(echo $line | awk  -F "." '{print $1"-"$4}')

import first file to nmcli  and grab uuid by awk

uuidcon=$(nmcli connection import type openvpn  file  $line |  awk 'match($0,  /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) {print substr($0, RSTART, RLENGTH)}')

modify name and add username , password to new connection

  nmcli con mod uuid $uuidcon $conname "username=$USERNAMEFORVPN" vpn.secrets password="$PASSWFORVPN"


I tested script at fedora 25 and NetworkManager.x86_64  v  1:1.4.4-3.fc25,  awk

NetworkManager.x86_64                                    1:1.4.4-3.fc25
NetworkManager-openvpn.x86_64                 1:1.2.8-1.fc25
NetworkManager-openvpn-gnome.x86_64 1:1.2.8-1.fc25

Example usage

Important username and password must be in quotes.

 ./importnordvpn -u "" -p "P44SSwoRd"
 ./importnordvpn -u "" -p "P44SSwoRd" -d Download/configs/
# get configs from Nordvpn webside [-g]
 ./importnordvpn -u "" -p "P44SSwoRd" -g</pre>
# if you want clean configuration
./importnordvpn -c
# clean configuration and load new
./importnordvpn -c -u "" -p "P44SSwoRd" -d Download/configs/</pre>
# clean configuration and load new from network
./importnordvpn -c -u "" -p "P44SSwoRd" -g


Look for new version on github :

Example effect:

Thousand  servers imported ready for use



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s