]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - server-scripts/ipfire-cleanup-nightly-builds.sh
cleanup: Keep 2 builds per branch
[people/ms/nightly-builds.git] / server-scripts / ipfire-cleanup-nightly-builds.sh
1 #!/bin/bash -l
2
3 BASEDIR="/pub/nightly"
4
5 MAX_AGE=$(( 7 * 24 * 3600 )) # 7 days
6
7 NOW="$(date +"%s")"
8
9 for branch in $(find "${BASEDIR}" -mindepth 1 -maxdepth 1 -type d); do
10 counter=0
11
12 for build in $(find "${branch}" -mindepth 1 -maxdepth 1 -type d | sort -nr); do
13 time="$(basename "${build}")"
14 [ "${time}" = "latest" ] && continue
15
16 # Never delete the last two builds
17 if [ "${counter}" -lt 2 ]; then
18 counter=$(( ${counter} + 1 ))
19 continue
20 fi
21
22 # Determine age of the build
23 change="$(stat --format="%Y" "${build}")"
24 age=$(( ${NOW} - ${change} ))
25
26 # If the build is old enough we will delete it
27 if [[ ${age} -ge ${MAX_AGE} ]]; then
28 rm -rf "${build}"
29 fi
30 done
31 done
32
33 exit 0