From fd072f1385b71be2f1c2c698357d5ab3dd03d0bc Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 2 Nov 2015 12:28:44 +0100 Subject: [PATCH] cleanup: Keep 2 builds per branch Signed-off-by: Michael Tremer --- .../ipfire-cleanup-nightly-builds.sh | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/server-scripts/ipfire-cleanup-nightly-builds.sh b/server-scripts/ipfire-cleanup-nightly-builds.sh index 3abe283..cd65a95 100755 --- a/server-scripts/ipfire-cleanup-nightly-builds.sh +++ b/server-scripts/ipfire-cleanup-nightly-builds.sh @@ -6,25 +6,28 @@ MAX_AGE=$(( 7 * 24 * 3600 )) # 7 days NOW="$(date +"%s")" -counter=0 -for build in $(find "${BASEDIR}" -mindepth 2 -maxdepth 2 -type d | sort -nr); do - time="$(basename "${build}")" - [ "${time}" = "latest" ] && continue - - # Never delete the last two builds - if [ "${counter}" -lt 2 ]; then - counter=$(( ${counter} + 1 )) - continue - fi - - # Determine age of the build - change="$(stat --format="%Y" "${build}")" - age=$(( ${NOW} - ${change} )) - - # If the build is old enough we will delete it - if [[ ${age} -ge ${MAX_AGE} ]]; then - rm -rf "${build}" - fi +for branch in $(find "${BASEDIR}" -mindepth 1 -maxdepth 1 -type d); do + counter=0 + + for build in $(find "${branch}" -mindepth 1 -maxdepth 1 -type d | sort -nr); do + time="$(basename "${build}")" + [ "${time}" = "latest" ] && continue + + # Never delete the last two builds + if [ "${counter}" -lt 2 ]; then + counter=$(( ${counter} + 1 )) + continue + fi + + # Determine age of the build + change="$(stat --format="%Y" "${build}")" + age=$(( ${NOW} - ${change} )) + + # If the build is old enough we will delete it + if [[ ${age} -ge ${MAX_AGE} ]]; then + rm -rf "${build}" + fi + done done exit 0 -- 2.47.3