]> git.ipfire.org Git - people/ms/nightly-builds.git/blame - build.sh
Don't start new builds when an other one is already running
[people/ms/nightly-builds.git] / build.sh
CommitLineData
fd9f9810
MT
1#!/bin/bash -l
2
3BASEDIR="/build/nightly"
d2b7a495 4LOCKFILE="/tmp/.nightly-builds.lock"
fd9f9810
MT
5
6UPLOAD_DIR="${BASEDIR}/upload"
7UPLOAD_TO="pakfire@git.ipfire.org:/pub/nightly"
8RSYNC_ARGS="--bwlimit=1M"
9
10export MAKETUNING="-j2"
11
12extract_installer_from_iso() {
13 local dir="${1}"
14
15 local tmpdir="$(mktemp -d)"
16 mkdir -p "${dir}/images"
17
18 local file
19 for file in ${dir}/*.iso; do
20 if mount -o loop,ro "${file}" "${tmpdir}"; then
21 local f
22 for f in vmlinuz instroot; do
23 cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
24 done
25 umount "${tmpdir}"
81a5283c
MT
26
27 local ext
28 for ext in "" ".md5"; do
29 ln -s --relative "${file}${ext}" \
30 "${dir}/images/installer.iso${ext}"
31 done
fd9f9810
MT
32 break
33 fi
34 done 2>/dev/null
35
36 rm -rf "${tmpdir}"
37}
38
39build() {
40 local dir="${1}"
41 shift
42
fb8a369c
MT
43 # Check if this actually source of IPFire 2
44 [ -x "${dir}/make.sh" ] || return 1
45
fd9f9810
MT
46 pushd "${dir}"
47
48 local branch="$(git config build.branch)"
49 [ -z "${branch}" ] && branch="master"
50
51 local commit_old="$(git rev-parse HEAD)"
52 git fetch
53
54 # If the branch was not updated, we won't build
55 local commit_new="$(git rev-parse origin/${branch})"
56 [ "${commit_old}" = "${commit_new}" ] && return 2
57
58 # Checkout the latest commit
59 git reset --hard "${commit_new}"
60
61 #local now="$(date -u +"%Y-%m-%d-%H:%M")"
62 local now="$(git log --format="%cI" -1 "${commit_new}")"
63
64 local targets="$(git config build.targets)"
65 [ -z "${targets}" ] && targets="i586"
66
67 local target
68 for target in ${targets}; do
c42b9259
MT
69 local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}"
70 local build="${build_path}/${target}"
fd9f9810
MT
71
72 # Ready for build
73 ./make.sh --target="${target}" clean
74
75 # Download the toolchain if required
76 ./make.sh --target="${target}" gettoolchain || continue
77
78 # Download all sources
79 ./make.sh --target="${target}" downloadsrc || continue
80
81 # Execute the build
82 mkdir -p "${build}"
83 ./make.sh --target="${target}" build | tee "${build}/build.log"
84 local ret=${PIPESTATUS[0]}
85
86 # Save the result
87 if [ "${ret}" = "0" ]; then
88 mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}"
89 extract_installer_from_iso "${build}"
90 touch "${build}/.success"
91 fi
92 mv -v log/ "${build}"
93
94 # Upload the result
95 sync
96
97 # Cleanup in the end
98 ./make.sh --target="${target}" clean
c42b9259 99 rm -rf "${build_path}"
fd9f9810
MT
100 done
101
102 popd
103}
104
105sync() {
106 mkdir -p "${UPLOAD_DIR}"
107
108 rsync -avHz --progress ${RSYNC_ARGS} \
109 "${UPLOAD_DIR}/" "${UPLOAD_TO}"
110}
111
d2b7a495
MT
112is_locked() {
113 [ -e "${LOCKFILE}" ]
114}
115
116lock() {
117 touch "${LOCKFILE}"
118}
119
120unlock() {
121 rm -f "${LOCKFILE}"
122}
123
124
125# Don't start again if the script is already running
b9def775
MT
126# or if an other build script is running
127if is_locked || pgrep make.sh >/dev/null; then
d2b7a495
MT
128 exit 0
129fi
130
131# Lock
132trap unlock EXIT
133lock
134
6c6991a8 135for repo in $(find ${BASEDIR} -maxdepth 3 -type d -name ".git"); do
fd9f9810
MT
136 [ -d "${repo}" ] || continue
137
138 build "$(dirname ${repo})"
139done
d2b7a495
MT
140
141exit 0