]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - server-scripts/ipfire-cleanup-nightly-builds.sh
3abe283622e538283d7eff214ff5d438c8fa01cf
[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 counter=0
10 for build in $(find "${BASEDIR}" -mindepth 2 -maxdepth 2 -type d | sort -nr); do
11 time="$(basename "${build}")"
12 [ "${time}" = "latest" ] && continue
13
14 # Never delete the last two builds
15 if [ "${counter}" -lt 2 ]; then
16 counter=$(( ${counter} + 1 ))
17 continue
18 fi
19
20 # Determine age of the build
21 change="$(stat --format="%Y" "${build}")"
22 age=$(( ${NOW} - ${change} ))
23
24 # If the build is old enough we will delete it
25 if [[ ${age} -ge ${MAX_AGE} ]]; then
26 rm -rf "${build}"
27 fi
28 done
29
30 exit 0