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
|
|
|
|
2011-07-08 10:32:22 +00:00
|
|
|
SELF=$(basename $0)
|
|
|
|
RELENG_XORRISO=0
|
|
|
|
SIMULATE_FAILURE=0
|
2011-07-15 18:22:09 +00:00
|
|
|
CLEANUP=1
|
2011-07-18 17:22:59 +00:00
|
|
|
SPECIFIC_HELP=0
|
2011-07-08 12:16:44 +00:00
|
|
|
START_DIR_DONT_CHANGE=`pwd`
|
|
|
|
GEN_DATA_DIR=releng_generated_data/${SELF}
|
2012-04-21 09:05:57 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
standalone_or_supervised() {
|
2012-04-21 15:41:45 +00:00
|
|
|
case "${RELENG_SCRIPT_RUN_BY_RUN_ALL_AUTO}" in
|
|
|
|
1)
|
|
|
|
echo "${SELF}: Running in Supervised mode"
|
2012-04-21 09:44:48 +00:00
|
|
|
;;
|
|
|
|
*)
|
2012-04-21 15:41:45 +00:00
|
|
|
echo "${SELF}: Running in Standalone mode"
|
2012-04-21 09:44:48 +00:00
|
|
|
;;
|
2012-04-21 15:41:45 +00:00
|
|
|
esac
|
2012-04-21 09:05:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-21 15:41:45 +00:00
|
|
|
# Unconditionally shout out the invocation mode - standalone or supervised
|
2012-04-21 09:05:57 +00:00
|
|
|
standalone_or_supervised
|
2011-07-08 12:16:44 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
print_help() {
|
2011-07-08 10:32:22 +00:00
|
|
|
cat << EOF
|
|
|
|
|
2011-08-03 18:19:19 +00:00
|
|
|
Usage: $SELF -x path/to/xorriso [-k] [-f] [-c] [-h]
|
2011-07-15 06:08:29 +00:00
|
|
|
[-- ...test specific options...]
|
|
|
|
General options:
|
2011-07-15 14:10:05 +00:00
|
|
|
-x absolute or relative path to xorriso binary to be run.
|
2011-07-15 18:26:02 +00:00
|
|
|
-k keep self-generated data.
|
|
|
|
-c cleanup self-generated data kept from previous run and exit.
|
2011-07-15 14:10:05 +00:00
|
|
|
-f simulate failure.
|
2011-08-03 18:19:19 +00:00
|
|
|
-h print this help text
|
2011-07-15 06:08:29 +00:00
|
|
|
-- end of general options, begin of test specific options.
|
2011-07-08 10:32:22 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2012-04-21 09:05:57 +00:00
|
|
|
#############################################
|
2011-07-09 16:31:46 +00:00
|
|
|
boldify() {
|
|
|
|
if which tput >/dev/null 2>&1; then tput smso; fi
|
|
|
|
}
|
|
|
|
|
2012-04-21 09:05:57 +00:00
|
|
|
#############################################
|
2011-07-09 16:31:46 +00:00
|
|
|
unboldify() {
|
|
|
|
if which tput >/dev/null 2>&1; then tput rmso; fi
|
|
|
|
}
|
|
|
|
|
2011-07-08 12:16:44 +00:00
|
|
|
#############################################
|
|
|
|
cleanup() {
|
2011-07-15 18:22:09 +00:00
|
|
|
if [ ${CLEANUP} -eq 1 ]; then
|
2011-07-08 12:16:44 +00:00
|
|
|
# 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
|
2011-07-08 16:01:17 +00:00
|
|
|
|
|
|
|
# Verify once again we are in the releng_generated_data directory
|
|
|
|
# Check for both returned code of grep and returned matching string
|
2011-08-09 16:24:40 +00:00
|
|
|
# There is no "readlink -e" on FreeBSD
|
|
|
|
READ_CANON_EXISTS=`cd "${GEN_DATA_DIR}" 2>/dev/null && pwd`
|
2011-07-08 16:01:17 +00:00
|
|
|
DIR_NAME_GEN_DATA=`dirname "${READ_CANON_EXISTS}"`
|
|
|
|
set +e
|
2011-08-09 16:24:40 +00:00
|
|
|
# There is no "grep -P" on FreeBSD
|
|
|
|
RET_NON_EMPTY_STRING=`echo "${DIR_NAME_GEN_DATA}" | grep "[a-zA-Z0-9_][a-zA-Z0-9_]*/releng_generated_data$"`
|
2011-07-08 16:01:17 +00:00
|
|
|
GREP_RET_GEN_DATA="$?"
|
|
|
|
case "${GREP_RET_GEN_DATA}" in
|
|
|
|
0)
|
|
|
|
if [ x"${RET_NON_EMPTY_STRING}" != x"" ]; then
|
|
|
|
# now call the nastiness
|
2011-08-09 16:24:40 +00:00
|
|
|
chmod -R +w ${GEN_DATA_DIR}
|
2011-07-08 16:01:17 +00:00
|
|
|
rm -rf ${GEN_DATA_DIR}
|
2011-08-18 08:45:49 +00:00
|
|
|
# boldify
|
2011-07-08 16:01:17 +00:00
|
|
|
printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
|
2011-08-18 08:45:49 +00:00
|
|
|
# unboldify
|
2011-07-08 16:01:17 +00:00
|
|
|
else
|
2011-08-05 15:49:07 +00:00
|
|
|
printf "FAIL : ${SELF} : Safety check for being in releng_generated_data directory.\n"
|
|
|
|
printf "FAIL : ${SELF} : GREP returned empty string: ${RET_NON_EMPTY_STRING}.\n"
|
|
|
|
printf "FAIL : ${SELF} : Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
|
2011-07-08 16:01:17 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2011-08-05 15:49:07 +00:00
|
|
|
printf "FAIL : ${SELF} : Safety check for being in releng_generated_data directory.\n"
|
|
|
|
printf "FAIL : ${SELF} : GREP returned code: ${GREP_RET_GEN_DATA}.\n"
|
|
|
|
printf "FAIL : ${SELF} : Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
|
2011-07-08 16:01:17 +00:00
|
|
|
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
|
2011-08-18 08:45:49 +00:00
|
|
|
# boldify
|
2011-07-08 12:16:44 +00:00
|
|
|
printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
|
2011-08-18 08:45:49 +00:00
|
|
|
# unboldify
|
2011-07-08 12:16:44 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-07-15 14:10:05 +00:00
|
|
|
#############################################
|
2011-07-15 11:30:30 +00:00
|
|
|
check_for_xorriso() {
|
|
|
|
# $1: if "-x" then check executability
|
|
|
|
|
|
|
|
if test -z "$RELENG_XORRISO" -o "$RELENG_XORRISO" = "0"
|
|
|
|
then
|
|
|
|
print_help
|
2011-07-15 13:58:34 +00:00
|
|
|
# print_specific_help
|
2011-07-15 14:10:05 +00:00
|
|
|
echo
|
|
|
|
echo "${SELF}: Need -x absolute or relative path to xorriso binary."
|
2011-07-15 11:30:30 +00:00
|
|
|
echo
|
|
|
|
exit 31
|
|
|
|
fi
|
|
|
|
if [ x"$1" = x"-x" -a ! -x "$RELENG_XORRISO" ]
|
|
|
|
then
|
|
|
|
print_help
|
2011-07-15 13:58:34 +00:00
|
|
|
# print_specific_help
|
2011-07-15 14:10:05 +00:00
|
|
|
echo
|
2011-07-15 11:30:30 +00:00
|
|
|
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-08-30 17:22:40 +00:00
|
|
|
#############################################
|
|
|
|
|
|
|
|
# To catch the exit value of a command in a pipe
|
|
|
|
return_value_file="$GEN_DATA_DIR"/wrapper_"$$"_return_value
|
|
|
|
return_wrapper()
|
|
|
|
{
|
|
|
|
cmd="$1"
|
|
|
|
shift 1
|
|
|
|
"$cmd" "$@"
|
|
|
|
RET="$?"
|
|
|
|
echo "$RET" >"$return_value_file"
|
|
|
|
return "$RET"
|
|
|
|
}
|
|
|
|
|
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"
|
2011-07-16 13:41:18 +00:00
|
|
|
then :
|
2011-07-15 06:08:29 +00:00
|
|
|
elif test "$next_is" = "x"
|
|
|
|
then
|
|
|
|
RELENG_XORRISO="$i"
|
|
|
|
next_is=
|
|
|
|
elif test x"$i" = x"-x"
|
|
|
|
then
|
|
|
|
next_is="x"
|
2011-07-15 14:10:05 +00:00
|
|
|
elif test x"$i" = x"-k"
|
2011-07-15 06:08:29 +00:00
|
|
|
then
|
2011-07-15 18:22:09 +00:00
|
|
|
CLEANUP=0
|
2011-07-15 14:10:05 +00:00
|
|
|
elif test x"$i" = x"-c"
|
2011-07-15 06:08:29 +00:00
|
|
|
then
|
|
|
|
CLEANUP=1
|
2011-07-15 18:05:14 +00:00
|
|
|
cleanup
|
|
|
|
exit 0
|
2011-07-15 14:10:05 +00:00
|
|
|
elif test x"$i" = x"-f"
|
2011-07-15 06:08:29 +00:00
|
|
|
then
|
|
|
|
SIMULATE_FAILURE=1
|
|
|
|
elif test x"$i" = x"-h"
|
|
|
|
then
|
|
|
|
print_help
|
2011-07-18 17:22:59 +00:00
|
|
|
SPECIFIC_HELP=1
|
2011-07-15 06:08:29 +00:00
|
|
|
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
|