There are times when network manager does not automatically reconnect or there are new servers added, I want to use a script to automatically read all ovpn files and let me select one.
I tried to find a way to store username and password without editing ovpn files. It all was beyond me.
I'd like to find a better way to do this for my purposes but here is what I did.
ovpnstart.sh (to call ovpnlist.sh with sudo so I only have to enter user OS password once)
Code: Select all
cd <to directory with ovpn & scripts> #So I no longer have to use full path in ovpnlist.sh
sudo <to directory with ovpn & scripts>/ovpnlist.sh
Code: Select all
#!/bin/bash
sed -i 's/auth-user-pass$/auth-user-pass ovpnp/g' *.ovpn # $ is to detect new line. Adds password file (ovpnp) to all .ovpn files
printf '\033[8;54;130t' #Resize terminal window to fit all servers. 54 is lines height, 130 is lines width
echo "Enter the number of the vpn you want to connect to"
echo "Ctrl+C to pick a new server. Press Enter to relist servers"
echo "Press Ctrl+C twice to exit"
echo " "
select FILENAME in *;
do
echo "Selected $FILENAME ($REPLY)"
sudo openvpn "$FILENAME"
done
Code: Select all
yourusername
yourpassword
I know it's not the most secure way to do things.
I'm using Ubuntu and my linux foo is weak.