#!/bin/bash

ovpn_file="${1}"
ovpn_name="${2}"

[ -f "${ovpn_file}" ] || exit
[ -z "${ovpn_name}" ] && basename -s .ovpn "${ovpn_file}"

read -p "Username: " ovpn_user
read -p "Password: " -s ovpn_pass;printf "\n"

nmcli connection import type openvpn file "${ovpn_file}"
nmcli connection modify `basename -s .ovpn "${ovpn_file}"` con-name "${ovpn_name}"
nmcli connection modify "${ovpn_name}" +vpn.data username="${ovpn_user}"
nmcli connection modify "${ovpn_name}" +vpn.data password-flags=0
nmcli connection modify "${ovpn_name}" +vpn.secrets password="${ovpn_pass}"
