]> git.ipfire.org Git - people/ms/nightly-builds.git/commitdiff
Merge remote-tracking branch 'origin/master'
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 May 2016 22:31:41 +0000 (00:31 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 May 2016 22:31:41 +0000 (00:31 +0200)
server-scripts/ipfire-cleanup-nightly-builds.sh [new file with mode: 0755]
server-scripts/ipfire-nightly-latest.sh [new file with mode: 0755]

diff --git a/server-scripts/ipfire-cleanup-nightly-builds.sh b/server-scripts/ipfire-cleanup-nightly-builds.sh
new file mode 100755 (executable)
index 0000000..711a852
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash -l
+
+BASEDIR="/pub/nightly"
+declare -A ARCHES
+ARCHES["master"]="x86_64 i586"
+ARCHES["next"]="x86_64 i586 armv5tel"
+
+MAX_AGE=$(( 7 * 24 * 3600 )) # 7 days
+
+NOW="$(date +"%s")"
+
+all_successful() {
+       local branch="${1}"
+       local release="${2}"
+
+       local arches="${ARCHES[${branch}]}"
+       [ -z "${arches}" ] && return 0
+
+       local arch
+       for arch in ${arches}; do
+               if [ ! -e "${release}/${arch}/.success" ]; then
+                       return 1
+               fi
+       done
+
+       return 0
+}
+
+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 ] && all_successful "$(basename ${branch})" "${build}"; 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
diff --git a/server-scripts/ipfire-nightly-latest.sh b/server-scripts/ipfire-nightly-latest.sh
new file mode 100755 (executable)
index 0000000..a832333
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash -l
+
+BASEDIR="/pub/nightly"
+
+main() {
+       local branch
+       for branch in ${BASEDIR}/*; do
+               [ -d "${branch}" ] || continue
+
+               local -A successful_releases=()
+
+               local arch
+               local release
+               for release in ${branch}/*/*; do
+                       arch="$(basename "${release}")"
+
+                       # Remember that we have seen the architecture
+                       if [ -z "${successful_releases[${arch}]}" ]; then
+                               successful_releases["${arch}"]=""
+                       fi
+
+                       # Skip the "latest" symlink
+                       local time="$(basename "$(dirname "${release}")")"
+                       [ "${time}" = "latest" ] && continue
+
+                       if [ -e "${release}/.success" ]; then
+                               successful_releases["${arch}"]="${release}"
+                       fi
+               done 2>/dev/null
+
+               for arch in ${!successful_releases[@]}; do
+                       release="${successful_releases[${arch}]}"
+
+                       mkdir -p "${branch}/latest"
+                       rm -f "${branch}/latest/${arch}"
+
+                       if [ -n "${release}" ]; then
+                               ln -sf --relative "${release}" "${branch}/latest/${arch}"
+                       fi
+               done
+       done
+
+       return 0
+}
+
+main || exit $?