]> git.ipfire.org Git - people/ms/nightly-builds.git/blame - build.sh
Build all branches in alphabetical order
[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"
7899475b 7UPLOAD_TO="pakfire@fs01.haj.ipfire.org:/pub/nightly"
00e27fa7 8RSYNC_ARGS=( "-avH" "--progress" "--delay-updates" )
fd9f9810 9
fd9f9810
MT
10extract_installer_from_iso() {
11 local dir="${1}"
12
13 local tmpdir="$(mktemp -d)"
14 mkdir -p "${dir}/images"
15
16 local file
17 for file in ${dir}/*.iso; do
18 if mount -o loop,ro "${file}" "${tmpdir}"; then
19 local f
20 for f in vmlinuz instroot; do
21 cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
22 done
23 umount "${tmpdir}"
81a5283c
MT
24
25 local ext
26 for ext in "" ".md5"; do
27 ln -s --relative "${file}${ext}" \
28 "${dir}/images/installer.iso${ext}"
29 done
fd9f9810
MT
30 break
31 fi
32 done 2>/dev/null
33
34 rm -rf "${tmpdir}"
35}
36
e5c0113d
MT
37uriencode() {
38 local path="${1}"
39
40 local IFS="/"
41
42 local s
43 local segments=()
44 for s in ${path}; do
45 s="${s//'%'/%25}"
46 s="${s//' '/%20}"
47 s="${s//'"'/%22}"
48 s="${s//'#'/%23}"
49 s="${s//'$'/%24}"
50 s="${s//'&'/%26}"
51 s="${s//'+'/%2B}"
52 s="${s//','/%2C}"
53 s="${s//'/'/%2F}"
54 s="${s//':'/%3A}"
55 s="${s//';'/%3B}"
56 s="${s//'='/%3D}"
57 s="${s//'?'/%3F}"
58 s="${s//'@'/%40}"
59 s="${s//'['/%5B}"
60 s="${s//']'/%5D}"
61
62 segments+=( "${s}" )
63 done
64
65 echo "${segments[*]}"
66}
67
68send_email() {
69 local status="${1}"
70 local target="${2}"
71 local branch="${3}"
72 local commit="${4}"
73 local build="${5}"
74
75 sendmail -ti <<END
76From: IPFire Nightly Builder <nightly-builds@ipfire.org>
77To: Nightly Builds List <nightly-builds@lists.ipfire.org>
78Subject: [${status^^}] Nightly Build of ${branch} (${commit:0:7}) for ${target} on ${HOSTNAME}
79Date: $(date --rfc-2822)
80MIME-Version: 1.0
81Content-Type: text/plain; charset="us-ascii"
82Content-Transfer-Encoding: 7bit
83
84https://nightly.ipfire.org$(uriencode "${build:${#UPLOAD_DIR}}")
85
86$(git log -1 "${commit}")
87
88https://git.ipfire.org/?p=ipfire-2.x.git;a=shortlog;h=${commit}
89
90$(<"${build}/build.log")
91END
92}
93
fd9f9810
MT
94build() {
95 local dir="${1}"
96 shift
97
fb8a369c
MT
98 # Check if this actually source of IPFire 2
99 [ -x "${dir}/make.sh" ] || return 1
100
fd9f9810
MT
101 pushd "${dir}"
102
103 local branch="$(git config build.branch)"
104 [ -z "${branch}" ] && branch="master"
105
106 local commit_old="$(git rev-parse HEAD)"
107 git fetch
108
ecab61ba
MT
109 # Search for the latest core branch
110 if [ "${branch}" = "core" ]; then
111 branch=$(git branch -r | awk -F/ '{ print $NF }' | grep ^core | sort --version-sort | tail -n1)
112 fi
113
fd9f9810
MT
114 # If the branch was not updated, we won't build
115 local commit_new="$(git rev-parse origin/${branch})"
116 [ "${commit_old}" = "${commit_new}" ] && return 2
117
dc1916d9
MT
118 local current_branch="$(git rev-parse --abbrev-ref HEAD)"
119 if [ "${current_branch}" != "${branch}" ]; then
120 git checkout -b "${branch}" "${commit_new}"
121 fi
122
fd9f9810
MT
123 # Checkout the latest commit
124 git reset --hard "${commit_new}"
125
e685e88f 126 local now="$(git log --format="%ci" -1 "${commit_new}")"
fd9f9810
MT
127
128 local targets="$(git config build.targets)"
129 [ -z "${targets}" ] && targets="i586"
130
131 local target
132 for target in ${targets}; do
c42b9259
MT
133 local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}"
134 local build="${build_path}/${target}"
e5c0113d 135 local status="failed"
fd9f9810
MT
136
137 # Ready for build
138 ./make.sh --target="${target}" clean
139
140 # Download the toolchain if required
141 ./make.sh --target="${target}" gettoolchain || continue
142
143 # Download all sources
144 ./make.sh --target="${target}" downloadsrc || continue
145
146 # Execute the build
147 mkdir -p "${build}"
148 ./make.sh --target="${target}" build | tee "${build}/build.log"
149 local ret=${PIPESTATUS[0]}
150
83c069b6
MT
151 # Save the changelog
152 git log -50 > "${build}/changelog.txt"
153
fd9f9810
MT
154 # Save the result
155 if [ "${ret}" = "0" ]; then
e5c0113d
MT
156 status="success"
157 touch "${build}/.success"
158
159 # Copy images
36213bbc 160 mv -v *.iso *.img.gz *.img.xz *.tar.bz2 *.md5 packages/ "${build}"
fd9f9810 161 extract_installer_from_iso "${build}"
fd9f9810
MT
162 fi
163 mv -v log/ "${build}"
164
ef1ba4c9 165 # Cleanup the build environment
fd9f9810 166 ./make.sh --target="${target}" clean
ef1ba4c9
MT
167
168 # Upload the result
00e27fa7 169 sync
abab5c14
MT
170
171 # Send an email notification
172 send_email "${status}" "${target}" "${branch}" "${commit_new}" "${build}"
fd9f9810
MT
173 done
174
175 popd
176}
177
178sync() {
8e3d51d0
MT
179 # Do not attempt to upload anything if nothing exists
180 [ ! -d "${UPLOAD_DIR}" ] && return 0
fd9f9810 181
7899475b 182 # Acquire a Kerberos ticket for authentication
a55d5bff 183 kinit -k -t /etc/krb5.keytab "host/${HOSTNAME}"
7899475b 184
00e27fa7
MT
185 if rsync "${RSYNC_ARGS[@]}" "${UPLOAD_DIR}/" "${UPLOAD_TO}"; then
186 rm -rf "${UPLOAD_DIR}"
187 fi
fd9f9810
MT
188}
189
d2b7a495
MT
190is_locked() {
191 [ -e "${LOCKFILE}" ]
192}
193
194lock() {
195 touch "${LOCKFILE}"
196}
197
198unlock() {
199 rm -f "${LOCKFILE}"
200}
201
d2b7a495 202# Don't start again if the script is already running
b9def775
MT
203# or if an other build script is running
204if is_locked || pgrep make.sh >/dev/null; then
d2b7a495
MT
205 exit 0
206fi
207
208# Lock
209trap unlock EXIT
210lock
211
51ab69f5
MT
212for repo in ${BASEDIR}/*; do
213 [ -d "${repo}/.git" ] || continue
fd9f9810 214
51ab69f5 215 echo build "${repo}"
fd9f9810 216done
d2b7a495 217
555260fa
MT
218# Try to sync even nothing was built for retrying failed uploads
219sync
220
d2b7a495 221exit 0