From aff51a1cc8a97732b2746cc508b00021e4311350 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 29 Nov 2012 01:27:43 +0000 Subject: [PATCH] Check for options mixed with positional arguments and throw error. --- bootstrap-salt-minion.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bootstrap-salt-minion.sh b/bootstrap-salt-minion.sh index 2d28c5e..2d349d9 100755 --- a/bootstrap-salt-minion.sh +++ b/bootstrap-salt-minion.sh @@ -63,17 +63,29 @@ do v|version ) echo "$0 -- Version $ScriptVersion"; exit 0 ;; c|config-dir ) TEMP_CONFIG_DIR="$OPTARG" ;; - \? ) echo "\n Option does not exist : $OPTARG\n" - usage; exit 1 ;; + \? ) echo "\n Option does not exist : $OPTARG\n" + usage; exit 1 ;; esac # --- end of case --- done shift $(($OPTIND-1)) +__check_unparsed_options() { + shellopts="$1" + unparsed_options=$( echo "$shellopts" | grep -e '[\-|\-\-][a-z]' ) + if [ "x$unparsed_options" != "x" ]; then + usage + echo + echo " * ERROR: options come before install arguments" + echo + exit 1 + fi +} # Define installation type if [ "$#" -eq 0 ];then ITYPE="stable" else + __check_unparsed_options "$*" ITYPE=$1 shift fi @@ -87,12 +99,14 @@ if [ $ITYPE = "git" ]; then if [ "$#" -eq 0 ];then GIT_REV="master" else + __check_unparsed_options "$*" GIT_REV="$1" shift fi fi if [ "$#" -gt 0 ]; then + __check_unparsed_options "$*" usage echo echo " * ERROR: Too many arguments."