Be more strict when validating YES/NO configuration variables.

This way users won't be surprised when misspelling "no" as "np" and
getting a "yes" behavior...

Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
mauro.giachero 2009-09-25 09:17:31 +00:00
parent 0cf9aea14a
commit ec602a72bb
2 changed files with 33 additions and 9 deletions

View file

@ -20,4 +20,5 @@ enhancements:
* Add the ability to run multiple sbopkg instances simultaneously. This has
been suggested many times in the past. Users should read the sbopkg.conf
man page before using this option (which is disabled by default).
* Be more strict validating YES/NO configuration variables.
+--------------------------+

View file

@ -135,15 +135,9 @@ EOF
fi
# Convert some YES/NO variables into 'set/unset' ones.
if [[ $KEEPLOG == [Nn][Oo] ]]; then
unset KEEPLOG
fi
if [[ $CLEANUP == [Nn][Oo] ]]; then
unset CLEANUP
fi
if [[ $ALLOW_MULTI == [Nn][Oo] ]]; then
unset ALLOW_MULTI
fi
yesno_to_setunset KEEPLOG
yesno_to_setunset CLEANUP
yesno_to_setunset ALLOW_MULTI
# If multiple instances of sbopkg are allowed, they need their own
# private $SBOPKGTMP.
@ -190,6 +184,35 @@ EOF
[[ -x /usr/bin/tput ]] && HAS_NCURSES=1
}
yesno_to_setunset() {
# Convert a yes/no variable to a set/unset one.
# $1 = variable name
# If the variable value is different from "yes" and "no" (case
# insensitive) spit an error message and exit.
# Note: $(eval echo \$$1) is the value of the variable (remember that
# $1 is the variable _name_).
if [[ $(eval echo \$$1) == [Nn][Oo] ]]; then
unset $1
elif [[ $(eval echo \$$1) != [Yy][Ee][Ss] ]]; then
cat <<EOF
ERROR
$SCRIPT: Unexpected value in $1
The configuration variable $1 is expected to be set to either YES or NO
(case insensitive). Its current value instead is $(eval echo \$$1).
Please fix this error by setting the appropriate value in
/etc/sbopkg/sbopkg.conf and/or in ~/.sbopkg.conf
and restart $SCRIPT.
EOF
exit 1
fi
}
load_repositories() {
# Fill the REPOSITORIES array with the data from the .repo files