Skip to content

Commit

Permalink
Merge pull request #14 from MattSurabian/hotfix-dry-run
Browse files Browse the repository at this point in the history
Hotfix: getopts does not support complex flags
  • Loading branch information
MattSurabian committed Nov 3, 2015
2 parents ae378c6 + fcb9350 commit ec86ff5
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions proxpn
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,33 @@ fi

# By default automatically connect to ProXPN when running this script
dryRun=false
dryRunExitCode=0

if [ $EUID -ne 0 ]; then
# Check for flags
while [[ $# > 0 ]]
do
key="$1"
case $key in
-dry-run|--dry-run)
dryRun=true
dryRunExitCode=0
echo -e "-dry-run mode active, you will not be automatically connected."
;;
*)
echo -e "Unknown option: $key \nUsage: proxpn [--dry-run|-dry-run]\n"
exit 1
;;
esac
shift # past argument or value
done

if [ $EUID != 0 -a $dryRun != true ]; then
echo "This script must be run as root in order to successfully apply network route configuration."
echo "Elevated permissions not detected, falling back to dry-run mode..."
dryRun=true
dryRunExitCode=1
fi

# If the user does not want to automatically connect to ProXPN they can pass -dry-run
while getopts ":dry-run" opt; do
case $opt in
a)
echo -e "\n-dry-run mode active, you will not be automatically connected.\n"
dryRun=true
;;
esac
done

# Catch control-c signals to make sure we don't lose stty echo
# if we decide to prematurely quit the script.If stty echo is lost the user
# won't be able to see what they're typing into the terminal
Expand Down Expand Up @@ -111,7 +121,7 @@ EXIT_NODES[BASIC]=bny1.proxpn.com

declare remote

echo "Which exit node would you like to use?"
echo -e "\nWhich exit node would you like to use?"

PS3="Select an exit node:"
select EXITNODE in ${!EXIT_NODES[@]};
Expand All @@ -133,7 +143,7 @@ COMMAND="$OPENVPN --config $OPENVPN_CONF --remote $remote $PORT --auth-user-pass
if [ $dryRun = true ]; then
echo -e "\nDry run comeplete!"
echo -e "Use following OpenVPN command to connect to ProXPN :\n$COMMAND\n"
exit 0
exit $dryRunExitCode
fi

echo -e "Running: \n$COMMAND\n"
Expand Down

0 comments on commit ec86ff5

Please sign in to comment.