catalyst-auto: add a preclean option to trim temp files
This makes it easier to cronjob things w/out needing manual cleanup from time to time by people.
This commit is contained in:
parent
a85f4327c6
commit
880a1aa775
|
@ -24,6 +24,7 @@ config_files=()
|
||||||
verbose=0
|
verbose=0
|
||||||
keep_tmpdir=0
|
keep_tmpdir=0
|
||||||
testing=0
|
testing=0
|
||||||
|
preclean=0
|
||||||
|
|
||||||
# Set pipefail so that run_cmd returns the right value in $?
|
# Set pipefail so that run_cmd returns the right value in $?
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
@ -41,6 +42,7 @@ Usage:
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-c|--config Specifies the config file to use (required)
|
-c|--config Specifies the config file to use (required)
|
||||||
|
-C|--preclean Clean up loose artifacts from previous runs
|
||||||
-v|--verbose Send output of commands to console as well as log
|
-v|--verbose Send output of commands to console as well as log
|
||||||
-k|--keep-tmpdir Don't remove temp dir when build finishes
|
-k|--keep-tmpdir Don't remove temp dir when build finishes
|
||||||
-t|--test Stop after mangling specs and copying files
|
-t|--test Stop after mangling specs and copying files
|
||||||
|
@ -119,6 +121,9 @@ do
|
||||||
-t|--test)
|
-t|--test)
|
||||||
testing=1
|
testing=1
|
||||||
;;
|
;;
|
||||||
|
-C|--preclean)
|
||||||
|
preclean=1
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "ERROR: You have specified an invalid option: ${a}"
|
usage "ERROR: You have specified an invalid option: ${a}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -149,6 +154,12 @@ BUILD_SRCDIR_BASE=$(catalyst_var storedir)
|
||||||
TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" catalyst-auto.XXXXXX)
|
TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" catalyst-auto.XXXXXX)
|
||||||
DATESTAMP=$(date +%Y%m%d)
|
DATESTAMP=$(date +%Y%m%d)
|
||||||
|
|
||||||
|
# Nuke any previous tmpdirs to keep them from accumulating.
|
||||||
|
if [[ ${preclean} -eq 1 ]]; then
|
||||||
|
rm -rf "${TMPDIR%.??????}".*
|
||||||
|
mkdir "${TMPDIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ${verbose} = 1 ]; then
|
if [ ${verbose} = 1 ]; then
|
||||||
echo "TMPDIR = ${TMPDIR}"
|
echo "TMPDIR = ${TMPDIR}"
|
||||||
echo "DATESTAMP = ${DATESTAMP}"
|
echo "DATESTAMP = ${DATESTAMP}"
|
||||||
|
@ -225,6 +236,18 @@ if [ "${testing}" -eq 1 ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ${preclean} -eq 1 ]]; then
|
||||||
|
snapshot_cache=$(catalyst_var snapshot_cache)
|
||||||
|
if [[ -z ${snapshot_cache} ]]; then
|
||||||
|
echo "error: snapshot_cache not set in config file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
pushd "${BUILD_SRCDIR_BASE}" >/dev/null || exit 1
|
||||||
|
rm -rf --one-file-system \
|
||||||
|
kerncache packages snapshots tmp "${snapshot_cache}"/*
|
||||||
|
popd >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
# Create snapshot
|
# Create snapshot
|
||||||
if ! run_cmd "catalyst -c ${CATALYST_CONFIG} -s ${DATESTAMP}" "${TMPDIR}/log/snapshot.log"; then
|
if ! run_cmd "catalyst -c ${CATALYST_CONFIG} -s ${DATESTAMP}" "${TMPDIR}/log/snapshot.log"; then
|
||||||
send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log"
|
send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log"
|
||||||
|
|
Loading…
Reference in a new issue