add self-contained and unified option parsing

This commit is contained in:
George Danchev 2011-07-08 10:32:22 +00:00
parent def086fb8d
commit b3480b1653
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,55 @@
SELF=$(basename $0)
RELENG_XORRISO=0
KEEP=0
SIMULATE_FAILURE=0
usage() {
cat << EOF
Usage: $SELF -x path/to/xorriso [-k0|1] [-f0|1] [-h]
-x absolute or relative path to binary to be run.
-k keep selfgenerated data, values 0,1 default 0.
-f simulate failure, values 0,1 default 0.
EOF
}
while getopts “x:k:f:h” OPTION
do
case $OPTION in
x)
RELENG_XORRISO=$OPTARG
;;
k)
KEEP=$OPTARG
;;
f)
SIMULATE_FAILURE=$OPTARG
;;
h)
usage
exit 0
;;
*)
usage
exit 31
;;
esac
done
if [ ! -x $RELENG_XORRISO ]; then
usage
printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n"
exit 31
fi
if [ x"$KEEP" != x"0" -a x"$KEEP" != x"1" ]; then
usage
printf "\n${SELF}: -k keep selfgenerated data, values 0,1 default 0.\n\n"
exit 31
fi
if [ x"$SIMULATE_FAILURE" != x"0" -a x"$SIMULATE_FAILURE" != x"1" ]; then
usage
printf "\n${SELF}: -f simulate failure, values 0,1 default 0.\n\n"
exit 31
fi

View File

@ -0,0 +1,12 @@
#!/bin/bash
set -e
. releng_getopts.inc
printf "\nRELENG_XORRISO =${RELENG_XORRISO}"
printf "\nKEEP =${KEEP}"
printf "\nSIMULATE_FAILURE =${SIMULATE_FAILURE}"
printf "\n"
exit 0