Bash menu options from files, example with OpenVPN

Post date: Jul 25, 2011 12:33:9 AM

Friday, July 18, 2008, 06:58 AM

Posted by Administrator

Here is a bit that I did last night:

#!/usr/bin/bash

echo "Starting VPN initialization script."

echo "If all goes well, you will need to choose your configuration,"

echo "provide your decryption password and then leave this window"

echo "open until you are done with the VPN connection."

echo

cd /etc/openvpn

userchoice=''

thischoice=''

standardreminder="You may exit the VPN connection at any time by pressing\nCtrl and C keys at the same time.\n\n"

while [ -z "${choice[$userchoice]}" ]

do

ct=1

for i in *.conf

do

choice[$ct]=$i

let ct++

done

echo -e $standardreminder

for ((i=1; i<$((${#choice[*]}+1));i++))

do

echo "Choice $i: ${choice[$i]}"

done

echo -n "Choose your configuration by number: "

read userchoice

userchoice=`echo "$userchoice"|sed 's/[^0-9]//g'`

thischoice="${choice[$userchoice]}"

echo "Choice is: ${choice[$userchoice]}"

if [ -n "${choice[$userchoice]}" ];then break;fi

echo "Invalid choice"

echo

done

echo "DEBUG: proceeding with choice: $thischoice"

echo "DEBUG openvpn --config $thischoice"