--- /dev/null
+#!/bin/bash -l
+
+BASEDIR="/build/nightly"
+
+UPLOAD_DIR="${BASEDIR}/upload"
+UPLOAD_TO="pakfire@git.ipfire.org:/pub/nightly"
+RSYNC_ARGS="--bwlimit=1M"
+
+export MAKETUNING="-j2"
+
+extract_installer_from_iso() {
+ local dir="${1}"
+
+ local tmpdir="$(mktemp -d)"
+ mkdir -p "${dir}/images"
+
+ local file
+ for file in ${dir}/*.iso; do
+ if mount -o loop,ro "${file}" "${tmpdir}"; then
+ local f
+ for f in vmlinuz instroot; do
+ cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
+ done
+ umount "${tmpdir}"
+ break
+ fi
+ done 2>/dev/null
+
+ rm -rf "${tmpdir}"
+}
+
+build() {
+ local dir="${1}"
+ shift
+
+ pushd "${dir}"
+
+ local branch="$(git config build.branch)"
+ [ -z "${branch}" ] && branch="master"
+
+ local commit_old="$(git rev-parse HEAD)"
+ git fetch
+
+ # If the branch was not updated, we won't build
+ local commit_new="$(git rev-parse origin/${branch})"
+ [ "${commit_old}" = "${commit_new}" ] && return 2
+
+ # Checkout the latest commit
+ git reset --hard "${commit_new}"
+
+ #local now="$(date -u +"%Y-%m-%d-%H:%M")"
+ local now="$(git log --format="%cI" -1 "${commit_new}")"
+
+ local targets="$(git config build.targets)"
+ [ -z "${targets}" ] && targets="i586"
+
+ local target
+ for target in ${targets}; do
+ local build="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}/${target}"
+
+ # Ready for build
+ ./make.sh --target="${target}" clean
+
+ # Download the toolchain if required
+ ./make.sh --target="${target}" gettoolchain || continue
+
+ # Download all sources
+ ./make.sh --target="${target}" downloadsrc || continue
+
+ # Execute the build
+ mkdir -p "${build}"
+ ./make.sh --target="${target}" build | tee "${build}/build.log"
+ local ret=${PIPESTATUS[0]}
+
+ # Save the result
+ if [ "${ret}" = "0" ]; then
+ mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}"
+ extract_installer_from_iso "${build}"
+ touch "${build}/.success"
+ fi
+ mv -v log/ "${build}"
+
+ # Upload the result
+ sync
+
+ # Cleanup in the end
+ ./make.sh --target="${target}" clean
+ rm -rf "$(dirname "${build}")"
+ done
+
+ popd
+}
+
+sync() {
+ mkdir -p "${UPLOAD_DIR}"
+
+ rsync -avHz --progress ${RSYNC_ARGS} \
+ "${UPLOAD_DIR}/" "${UPLOAD_TO}"
+}
+
+for repo in $(find ${BASEDIR} -maxdepth 2 -type d -name ".git"); do
+ [ -d "${repo}" ] || continue
+
+ build "$(dirname ${repo})"
+done