legacy/libisoburn/trunk/releng/inc/releng_getopts.inc

175 lines
4.6 KiB
PHP
Raw Normal View History

2011-07-11 09:44:01 +00:00
# Copyright 2011 George Danchev <danchev@spnet.net>
2011-07-15 06:08:29 +00:00
# Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
# Licensed under GNU GPL version 2 or later
2011-07-11 09:44:01 +00:00
SELF=$(basename $0)
RELENG_XORRISO=0
KEEP=0
SIMULATE_FAILURE=0
2011-07-08 12:16:44 +00:00
CLEANUP=1
2011-07-15 06:08:29 +00:00
RELENG_PRINTED_HELP=0
2011-07-08 12:16:44 +00:00
START_DIR_DONT_CHANGE=`pwd`
GEN_DATA_DIR=releng_generated_data/${SELF}
#############################################
print_help() {
cat << EOF
2011-07-15 06:08:29 +00:00
Usage: $SELF -x path/to/xorriso [-k0|1] [-f0|1] [-c0|1] [-h]
[-- ...test specific options...]
General options:
-x absolute or relative path to binary to be run.
2011-07-08 12:16:44 +00:00
-k keep selfgenerated data (values 0,1, default 0).
-c cleanup selfgenerated data kept from previous
run and exit (values 0,1, default 0).
-f simulate failure (values 0,1, default 0).
2011-07-15 06:08:29 +00:00
-- end of general options, begin of test specific options.
EOF
}
boldify() {
if which tput >/dev/null 2>&1; then tput smso; fi
}
unboldify() {
if which tput >/dev/null 2>&1; then tput rmso; fi
}
2011-07-08 12:16:44 +00:00
#############################################
cleanup() {
if [ ${KEEP} -eq 0 -a ${CLEANUP} -eq 1 ]; then
# safety net, just in case -> we want to be in the starting
# directory before removing whatever self-generated stuff
if [ -d "${GEN_DATA_DIR}" ]; then
cd "${START_DIR_DONT_CHANGE}" || exit 2
# Verify once again we are in the releng_generated_data directory
# Check for both returned code of grep and returned matching string
READ_CANON_EXISTS=`readlink -e "${GEN_DATA_DIR}"`
DIR_NAME_GEN_DATA=`dirname "${READ_CANON_EXISTS}"`
set +e
RET_NON_EMPTY_STRING=`echo "${DIR_NAME_GEN_DATA}" | grep -P "\w+\/releng_generated_data$"`
GREP_RET_GEN_DATA="$?"
case "${GREP_RET_GEN_DATA}" in
0)
if [ x"${RET_NON_EMPTY_STRING}" != x"" ]; then
# now call the nastiness
chmod +w -R ${GEN_DATA_DIR}
rm -rf ${GEN_DATA_DIR}
boldify
printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
unboldify
else
printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n"
printf "${SELF}: FAIL: GREP returned empty string: ${RET_NON_EMPTY_STRING}.\n"
printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
fi
;;
*)
printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n"
printf "${SELF}: FAIL: GREP returned code: ${GREP_RET_GEN_DATA}.\n"
printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
exit 30
;;
esac
2011-07-08 12:16:44 +00:00
else
printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
fi
else
boldify
2011-07-08 12:16:44 +00:00
printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
unboldify
2011-07-08 12:16:44 +00:00
fi
}
check_for_xorriso() {
# $1: if "-x" then check executability
if test -z "$RELENG_XORRISO" -o "$RELENG_XORRISO" = "0"
then
print_help
# print_specific_help
echo "${SELF}: Need -x absolute or relative path to binary to be run."
echo
exit 31
fi
if [ x"$1" = x"-x" -a ! -x "$RELENG_XORRISO" ]
then
print_help
# print_specific_help
echo "${SELF}: Path given by option -x does not lead to an executable file."
echo "Given is: '$RELENG_XORRISO'"
if test "$RELENG_XORRISO" = "xorriso"
then
xorriso=$(type -p xorriso)
if test -n "xorriso"
then
echo "Hint: Try '$xorriso'"
fi
fi
echo
exit 31
fi
}
2011-07-08 12:16:44 +00:00
#############################################
2011-07-15 06:08:29 +00:00
next_is=
for i in "$@"
do
if test "$next_is" = "ignore"
then
dummy=dummy
elif test "$next_is" = "x"
then
RELENG_XORRISO="$i"
next_is=
elif test x"$i" = x"-x"
then
next_is="x"
elif test x"$i" = x"-k" -o x"$i" = x"-k0"
then
KEEP=0
elif test x"$i" = x"-k1"
then
KEEP=1
elif test x"$i" = x"-c" -o x"$i" = x"-c0"
then
CLEANUP=0
elif test x"$i" = x"-c1"
then
CLEANUP=1
elif test x"$i" = x"-f" -o x"$i" = x"-f0"
then
SIMULATE_FAILURE=0
elif test x"$i" = x"-f1"
then
SIMULATE_FAILURE=1
elif test x"$i" = x"-h"
then
print_help
RELENG_PRINTED_HELP=1
elif test x"$i" = x"--"
then
# Begin of private arguments for caller
next_is="ignore"
else
echo >&2
echo "Unknown general option: $i" >&2
print_help
exit 31
fi
done
if test "$next_is" = x
then
echo >&2
echo "Option -x expects an argument (the path to the xorriso program)" >&2
print_help
exit 31
fi