more unification

This commit is contained in:
George Danchev 2011-07-08 12:16:44 +00:00
parent 1466254129
commit 8cfd6308bb
4 changed files with 65 additions and 105 deletions

View File

@ -2,18 +2,43 @@ SELF=$(basename $0)
RELENG_XORRISO=0
KEEP=0
SIMULATE_FAILURE=0
CLEANUP=1
usage() {
START_DIR_DONT_CHANGE=`pwd`
GEN_DATA_DIR=releng_generated_data/${SELF}
#############################################
print_help() {
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.
-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).
EOF
}
while getopts “x:k:f:h” OPTION
#############################################
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
rm -rf ${GEN_DATA_DIR}
printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
else
printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
fi
else
printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
fi
}
#############################################
while getopts “x:k:c:f:h” OPTION
do
case $OPTION in
x)
@ -22,34 +47,46 @@ do
k)
KEEP=$OPTARG
;;
c)
CLEANUP=$OPTARG
cleanup
exit 0
;;
f)
SIMULATE_FAILURE=$OPTARG
;;
h)
usage
print_help
exit 0
;;
*)
usage
print_help
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"
# Each releng_ test should decide whether or not to check that
#if [ ! -x $RELENG_XORRISO ]; then
# print_help
# 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
print_help
printf "\n${SELF}: -k keep selfgenerated data.\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"
if [ x"$CLEANUP" != x"0" -a x"$CLEANUP" != x"1" ]; then
print_help
printf "\n${SELF}: -c cleanup selfgenerated data kept from previous run.\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"
print_help
printf "\n${SELF}: -f simulate failure.\n\n"
exit 31
fi

View File

@ -6,6 +6,7 @@ set -e
printf "\nRELENG_XORRISO =${RELENG_XORRISO}"
printf "\nKEEP =${KEEP}"
printf "\nCLEANUP =${CLEANUP}"
printf "\nSIMULATE_FAILURE =${SIMULATE_FAILURE}"
printf "\n"

View File

@ -2,68 +2,17 @@
set -e
START_DIR_DONT_CHANGE=`pwd`
SELF=$(basename "$0")
GEN_DATA_DIR=releng_generated_data/${SELF}
KEEP=0
. inc/releng_getopts.inc
# xorriso binary is not needed for that particular test
SAMPLE_CODE_DIR=codesamples
CC=g++
#####################################################################
print_help() {
cat << HLP
Usage:
$0 -help
#
$0 -rc [-keep]
# cleanup test generated data directory and exit
$0 -cleanup
HLP
}
#####################################################################
cleanup() {
if [ ${KEEP} -eq 0 ]; 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
rm -rf ${GEN_DATA_DIR}
printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
else
printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
fi
else
printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
fi
}
#####################################################################
# help
if [ ! "${1}" ]; then
print_help && exit 3
#
elif [ "${1}" == "-cleanup" ]; then
cleanup
exit 0
#
elif [ "${1}" == "-rc" -a "${2}" == "-keep" ]; then
KEEP=1
elif [ "${1}" == "-rc" -a ! "${2}" ]; then
KEEP=0
# the rest
else
print_help && exit 4
fi
#####################################################################
# check data dir
if [ -d "${GEN_DATA_DIR}" ]; then
printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
printf "\n${SELF}: use '${SELF} -cleanup' to remove.\n"
printf "\n${SELF}: use '${SELF} -c1' to remove.\n"
exit 5
else
mkdir "${GEN_DATA_DIR}"

View File

@ -2,46 +2,19 @@
set -e
START_DIR_DONT_CHANGE=`pwd`
SELF=$(basename "$0")
# required config items
# RELENG_XORRISO=""
# optional config items
# config file
CONFFILE=${HOME}/.libburnia-releng/${SELF}.conf
GEN_DATA_DIR=releng_generated_data/${SELF}
KEEP=0
. inc/releng_getopts.inc
# Each releng_ test should decide whether or not it need
# a xorriso binary to test, since some do compilations only.
if [ ! -x $RELENG_XORRISO ]; then
print_help
printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n"
exit 31
fi
printf "\n$0: FAIL: === TEPLATE === RENAME ME TO releng_<title>\n"
exit 31
#####################################################################
print_help() {
cat << HLP
Usage:
$0 -help
# using a config file ${CONFFILE}
$0 -rc [-keep]
# without using a config file
$0 your_own_options_here
# cleanup test generated data directory and exit
$0 -cleanup
HLP
}
#####################################################################
print_help
#if [ ! -x "${XOR}" ]; then
# printf "$0: Not found or not an executable: $XOR\n"
# exit 50
#fi
# xorriso version details, incl. underlying libraries
# "${XOR}" -version
exit 0