cleanup on prepature exits when self-generated data has been produced

This commit is contained in:
George Danchev 2011-07-03 18:31:10 +00:00
parent 73090436d4
commit d25db0a6ef

View File

@ -25,6 +25,7 @@ RES=""
REMOTE_URL="http://cdimage.debian.org/cdimage/daily-builds/daily/current/i386/iso-cd"
REMOTE_IMG="debian-testing-i386-businesscard.iso"
#####
print_help() {
cat << HLP
Usage:
@ -41,23 +42,27 @@ Usage:
HLP
}
#####
cleanup() {
# safety net, just in case -> we want to be in the starting
# directory before removing whatever self-generated stuff
cd "${START_DIR_DONT_CHANGE}" || exit 15
chmod +w -R ${GEN_DATA_DIR}
rm -rf ${GEN_DATA_DIR}
printf "${SELF}: Removed %s\n" ${GEN_DATA_DIR}
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 15
chmod +w -R ${GEN_DATA_DIR}
rm -rf ${GEN_DATA_DIR}
printf "${SELF}: Removed %s\n" ${GEN_DATA_DIR}
else
printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
fi
else
printf "${SELF}: Leaving %s\n" ${GEN_DATA_DIR}
fi
}
#####################################################################
# cleanup
if [ "${1}" == "-cleanup" ]; then
if [ -d "${GEN_DATA_DIR}" ]; then
cleanup
else
printf "${SELF}: ${GEN_DATA_DIR} does not exist.\n"
fi
cleanup
exit 0
fi
@ -113,9 +118,7 @@ else
mkdir "${GEN_DATA_DIR}"
fi
# all must be set at this point
# All must be set at this point
printf "${SELF}: Config items:"
printf "\n\txorriso_cmd=${RELENG_XORRISO}\n\tIN_dir=${RELENG_DIR}\n\tOUT_image=${RELENG_IMG}.iso"
printf "\n\tIN_isolinux=${RELENG_ISOLINUX_BIN}\n\tOUT_bootcat=${RELENG_BOOT_CAT}\n"
@ -126,6 +129,7 @@ RES="${RELENG_IMG}.iso ${RELENG_IMG}.new ${RELENG_IMG}.md5 ${RELENG_IMG}.jigdo $
if ! "${RELENG_XORRISO}" -version | grep libjte >/dev/null 2>&1; then
printf "\n${SELF}: JTE not supported with this xorriso build. Install jigit and rebuild."
printf "\n${SELF}: See http://www.einval.com/~steve/software/JTE/\n"
cleanup
exit 9
fi
@ -144,6 +148,7 @@ if [ ! -f "${TMP_DATA_DIR}"/"${REMOTE_IMG}" ]; then
;;
*)
echo -e "\n${SELF}: FAIL: wget returned code: $WGET_RET\n"
cleanup
exit 10
;;
esac
@ -154,6 +159,7 @@ fi
# check for extraction directory existence
if [ -d "${IMG_EXTRACT_DIR}" ]; then
printf "\n${SELF}: Found ${IMG_EXTRACT_DIR}. Please cleanup.\n"
cleanup
exit 11
else
mkdir "${IMG_EXTRACT_DIR}"
@ -181,6 +187,7 @@ if [ -x "${MKFS_MSDOS}" ]; then
else
printf "\n${SELF}: Not found: "${MKFS_MSDOS}". Install dosfstools."
printf "\n${SELF}: http://www.daniel-baumann.ch/software/dosfstools/\n"
cleanup
exit 12
fi
@ -207,6 +214,7 @@ CMD+="\
"
else
printf "\n${SELF}: FAIL to compose the boot section.\n"
cleanup
exit 13
fi
@ -225,6 +233,7 @@ if which jigdo-gen-md5-list >/dev/null 2>&1; then
else
printf "\n${SELF}: Not found: jigdo-gen-md5-list. Install jigit."
printf "\n${SELF}: See http://www.einval.com/~steve/software/JTE/\n"
cleanup
exit 14
fi
@ -257,6 +266,7 @@ if which jigit-mkimage >/dev/null 2>&1; then
else
printf "\n${SELF}: Not found: jigit-mkimage. Install jigit."
printf "\n${SELF}: See http://www.einval.com/~steve/software/JTE/\n"
cleanup
exit 15
fi
@ -273,11 +283,7 @@ case ${DIFF_RET} in
esac
# sort out the cruft
if [ ${KEEP} -eq 0 ]; then
cleanup
else
printf "${SELF}: Leaving %s\n" ${GEN_DATA_DIR}
fi
cleanup
# last hints
printf "\n${SELF}: HINT: manual checks remained to be done:\n"