Browse Source

Finish the cleanup script

I really should've tackled this sooner. The cleanup script is a rather
dumb one, keeping up to a configurable number of builds.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
master
Shawn Webb 4 months ago
parent
commit
1e309ab193
Signed by: Shawn Webb <shawn.webb@hardenedbsd.org> GPG Key ID: FF2E67A277F8E1FA
3 changed files with 16 additions and 4 deletions
  1. +2
    -2
      bin/cleanup.sh
  2. +13
    -0
      lib/config.sh
  3. +1
    -2
      lib/util.sh

+ 2
- 2
bin/cleanup.sh View File

@@ -57,8 +57,8 @@ main() {
esac
done

# TODO: provide our own version of config_set_dynamic
config_set_dynamic
cleanup_set_dynamic
HBSD_LOCKFILE="${HBSD_LOCKFILE}.cleanup"

(
assert_unlocked && \

+ 13
- 0
lib/config.sh View File

@@ -57,3 +57,16 @@ config_set_dynamic() {

return 0
}

cleanup_set_dynamic() {
if [ ! -h ${HBSD_PUBDIR}/BUILD-LATEST ]; then
echo "Could not find symlink at ${HBSD_PUBDIR}/BUILD-LATEST"
HBSD_BUILDNUMBER=0
return 0
fi

HBSD_BUILDNUMBER=$(readlink ${HBSD_PUBDIR}/BUILD-LATEST)
HBSD_BUILDNUMBER=${HBSD_BUILDNUMBER##*-}
echo "[*] Build number: ${HBSD_BUILDNUMBER}"
return 0
}

+ 1
- 2
lib/util.sh View File

@@ -115,13 +115,12 @@ should_build() {
prune_old_builds() {
[ ${HBSD_BUILDNUMBER} -lt ${HBSD_KEEP_NBUILDS} ] && return 0

return 0

floor=$((${HBSD_BUILDNUMBER} - ${HBSD_KEEP_NBUILDS}))

for d in $(find ${HBSD_PUBDIR} -maxdepth 1 -type d | sed 1d); do
n=$(basename ${d})
if [ ${n} -lt ${floor} ]; then
echo "[*] Removing ${d}"
rm -rf ${d}
fi
done

Loading…
Cancel
Save