From cfd753217f063147268fc9ad504f3c68316006b5 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 16 Oct 2010 01:02:16 -0500 Subject: [PATCH] script/makeworld: support detached prepare/clean and deferred cleaning to reduce pointless work on multiple-invocation --- script/makeworld | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/script/makeworld b/script/makeworld index 7e5ed7e..7f95174 100755 --- a/script/makeworld +++ b/script/makeworld @@ -17,7 +17,7 @@ # Load shlib and modules _root="$(dirname "${0}")"; . "${_root}/lib/env.sh" -want root log +want log pebkac() { [ "${*}" ] && printf "%s\n\n" "${*}" @@ -27,6 +27,12 @@ pebkac() { echo " -c Target configuration (in worlds//)" echo " -h Help!" echo "" + echo "If, for some reason, you wish to spread out builds across multiple" + echo "invocations, these might come in handy:" + echo " -p Prepare chroot environment" + echo " -d Don't prepare or clean up chroot during run" + echo " -q Clean up chroot environment" + echo "" echo "Available make targets:" for target in ${make_tgts} do @@ -37,6 +43,7 @@ pebkac() { # Prepare chroot for build prepare() { + [ "${CHROOT_DIRTY}" -a ! "${CHROOT_PREPARE}" ] && return 0 # Verify environment sanity [ -d "${build}" ] && omg "${build}: directory exists; purging" && cleanup mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue" @@ -69,10 +76,12 @@ prepare() { [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/" fi + return 0 } # Cleanup chroot cleanup() { + [ "${CHROOT_DIRTY}" -a ! "${CHROOT_CLEAN}" ] && return 0 meh "Cleaning up" umount -f "${build}/mnt" umount -f "${build}/usr/obj" @@ -82,6 +91,7 @@ cleanup() { chflags -R noschg "${build}" rm -Rf "${build}" trap "" exit hup int term kill + return 0 } # Root directory of makeworld @@ -97,18 +107,24 @@ TARGET="i386" CONFIG="GENERIC" MAKEOPTS="-j${make_jobs}" -while getopts "m:t:c:h" opt +while getopts "m:t:c:hpdq" opt do case "${opt}" in m) MAKEOPTS="${MAKEOPTS} ${OPTARG}" ;; t) TARGET="${OPTARG}" ;; c) CONFIG="${OPTARG}" ;; + p) CHROOT_PREPARE="TRUE" ;; + d) CHROOT_DIRTY="TRUE" ;; + q) CHROOT_CLEAN="TRUE" ;; h) pebkac ;; [?]) pebkac "Unrecognized option ${opt}" ;; esac done shift $(( $OPTIND - 1 )) +# Should be root after this point +want root + # Build make target sequence sequence="${*:-${make_tgts}}" @@ -132,11 +148,19 @@ date="$(date +%Y%m%d)" # Check if target config exists [ -d "${world}" ] || wtf "${TARGET}/${CONFIG} doesn't exist" -# Purge any build directory that might be left over -if [ -d "${build}" ] +if [ "${CHROOT_PREPARE}" ] +then + prepare + trap "" exit + meh "Chroot prepared" + exit +fi + +if [ "${CHROOT_CLEAN}" ] then - omg "${build}: directory exists; purging" cleanup + meh "Chroot cleaned" + exit fi meh "Making world for ${TARGET}/${CONFIG}" -- 2.42.0