]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - server-scripts/ipfire-cleanup-nightly-builds.sh
Merge remote-tracking branch 'origin/master'
[people/ms/nightly-builds.git] / server-scripts / ipfire-cleanup-nightly-builds.sh
1 #!/bin/bash -l
2
3 BASEDIR="/pub/nightly"
4 declare -A ARCHES
5 ARCHES["master"]="x86_64 i586"
6 ARCHES["next"]="x86_64 i586 armv5tel"
7
8 MAX_AGE=$(( 7 * 24 * 3600 )) # 7 days
9
10 NOW="$(date +"%s")"
11
12 all_successful() {
13 local branch="${1}"
14 local release="${2}"
15
16 local arches="${ARCHES[${branch}]}"
17 [ -z "${arches}" ] && return 0
18
19 local arch
20 for arch in ${arches}; do
21 if [ ! -e "${release}/${arch}/.success" ]; then
22 return 1
23 fi
24 done
25
26 return 0
27 }
28
29 for branch in $(find "${BASEDIR}" -mindepth 1 -maxdepth 1 -type d); do
30 counter=0
31
32 for build in $(find "${branch}" -mindepth 1 -maxdepth 1 -type d | sort -nr); do
33 time="$(basename "${build}")"
34 [ "${time}" = "latest" ] && continue
35
36 # Never delete the last two builds
37 if [ "${counter}" -lt 2 ] && all_successful "$(basename ${branch})" "${build}"; then
38 counter=$(( ${counter} + 1 ))
39 continue
40 fi
41
42 # Determine age of the build
43 change="$(stat --format="%Y" "${build}")"
44 age=$(( ${NOW} - ${change} ))
45
46 # If the build is old enough we will delete it
47 if [[ ${age} -ge ${MAX_AGE} ]]; then
48 rm -rf "${build}"
49 fi
50 done
51 done
52
53 exit 0