]>
Commit | Line | Data |
---|---|---|
fd9f9810 MT |
1 | #!/bin/bash -l |
2 | ||
3 | BASEDIR="/build/nightly" | |
d2b7a495 | 4 | LOCKFILE="/tmp/.nightly-builds.lock" |
fd9f9810 MT |
5 | |
6 | UPLOAD_DIR="${BASEDIR}/upload" | |
7899475b | 7 | UPLOAD_TO="pakfire@fs01.haj.ipfire.org:/pub/nightly" |
00e27fa7 | 8 | RSYNC_ARGS=( "-avH" "--progress" "--delay-updates" ) |
fd9f9810 | 9 | |
fd9f9810 MT |
10 | extract_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 |
37 | uriencode() { |
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 | ||
68 | send_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 | |
76 | From: IPFire Nightly Builder <nightly-builds@ipfire.org> | |
77 | To: Nightly Builds List <nightly-builds@lists.ipfire.org> | |
78 | Subject: [${status^^}] Nightly Build of ${branch} (${commit:0:7}) for ${target} on ${HOSTNAME} | |
79 | Date: $(date --rfc-2822) | |
80 | MIME-Version: 1.0 | |
81 | Content-Type: text/plain; charset="us-ascii" | |
82 | Content-Transfer-Encoding: 7bit | |
83 | ||
84 | https://nightly.ipfire.org$(uriencode "${build:${#UPLOAD_DIR}}") | |
85 | ||
86 | $(git log -1 "${commit}") | |
87 | ||
88 | https://git.ipfire.org/?p=ipfire-2.x.git;a=shortlog;h=${commit} | |
89 | ||
90 | $(<"${build}/build.log") | |
91 | END | |
92 | } | |
93 | ||
fd9f9810 MT |
94 | build() { |
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 | |
2272fea9 | 111 | branch="$(git branch -r | awk -F/ '{ print $NF }' | grep ^core | sort --version-sort | tail -n1)" |
ecab61ba MT |
112 | fi |
113 | ||
fd9f9810 | 114 | local commit_new="$(git rev-parse origin/${branch})" |
d1e3c705 MT |
115 | |
116 | # If the branch was not updated, we won't build | |
117 | if [ ! -e "${dir}/.force-build" ] && [ "${commit_old}" = "${commit_new}" ]; then | |
118 | return 2 | |
119 | fi | |
fd9f9810 | 120 | |
dc1916d9 MT |
121 | local current_branch="$(git rev-parse --abbrev-ref HEAD)" |
122 | if [ "${current_branch}" != "${branch}" ]; then | |
123 | git checkout -b "${branch}" "${commit_new}" | |
124 | fi | |
125 | ||
fd9f9810 MT |
126 | # Checkout the latest commit |
127 | git reset --hard "${commit_new}" | |
128 | ||
e685e88f | 129 | local now="$(git log --format="%ci" -1 "${commit_new}")" |
fd9f9810 | 130 | |
2272fea9 MT |
131 | local target="$(git config build.target)" |
132 | [ -z "${target}" ] && target="$(uname -m)" | |
fd9f9810 | 133 | |
2272fea9 MT |
134 | local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}" |
135 | local build="${build_path}/${target}" | |
136 | local status="failed" | |
abab5c14 | 137 | |
2272fea9 MT |
138 | # Remove marker |
139 | unlink "${dir}/.force-build" | |
d1e3c705 | 140 | |
2272fea9 MT |
141 | # Ready for build: Download toolchain and sources |
142 | local action | |
143 | for action in clean gettoolchain downloadsrc; do | |
144 | if ! ./make.sh --target="${target}" "${action}"; then | |
145 | touch "${dir}/.force-build" | |
146 | continue | |
147 | fi | |
fd9f9810 MT |
148 | done |
149 | ||
2272fea9 MT |
150 | # Execute the build |
151 | mkdir -p "${build}" | |
152 | ./make.sh --target="${target}" build | tee "${build}/build.log" | |
153 | local ret=${PIPESTATUS[0]} | |
154 | ||
155 | # Save the changelog | |
156 | git log -50 > "${build}/changelog.txt" | |
157 | ||
158 | # Save the result | |
159 | if [ "${ret}" = "0" ]; then | |
160 | status="success" | |
161 | touch "${build}/.success" | |
162 | ||
163 | # Copy images | |
164 | mv -v *.iso *.img.gz *.img.xz *.tar.bz2 *.md5 packages/ "${build}" | |
165 | extract_installer_from_iso "${build}" | |
166 | fi | |
167 | mv -v log/ "${build}" | |
168 | ||
169 | # Upload the result | |
170 | sync | |
171 | ||
172 | # Send an email notification | |
173 | send_email "${status}" "${target}" "${branch}" "${commit_new}" "${build}" | |
174 | ||
175 | # Cleanup the build environment | |
176 | ./make.sh --target="${target}" clean | |
177 | ||
fd9f9810 MT |
178 | popd |
179 | } | |
180 | ||
181 | sync() { | |
8e3d51d0 MT |
182 | # Do not attempt to upload anything if nothing exists |
183 | [ ! -d "${UPLOAD_DIR}" ] && return 0 | |
fd9f9810 | 184 | |
7899475b | 185 | # Acquire a Kerberos ticket for authentication |
a55d5bff | 186 | kinit -k -t /etc/krb5.keytab "host/${HOSTNAME}" |
7899475b | 187 | |
00e27fa7 MT |
188 | if rsync "${RSYNC_ARGS[@]}" "${UPLOAD_DIR}/" "${UPLOAD_TO}"; then |
189 | rm -rf "${UPLOAD_DIR}" | |
190 | fi | |
fd9f9810 MT |
191 | } |
192 | ||
d2b7a495 MT |
193 | is_locked() { |
194 | [ -e "${LOCKFILE}" ] | |
195 | } | |
196 | ||
197 | lock() { | |
198 | touch "${LOCKFILE}" | |
199 | } | |
200 | ||
201 | unlock() { | |
202 | rm -f "${LOCKFILE}" | |
203 | } | |
204 | ||
d2b7a495 | 205 | # Don't start again if the script is already running |
b9def775 MT |
206 | # or if an other build script is running |
207 | if is_locked || pgrep make.sh >/dev/null; then | |
d2b7a495 MT |
208 | exit 0 |
209 | fi | |
210 | ||
211 | # Lock | |
212 | trap unlock EXIT | |
213 | lock | |
214 | ||
51ab69f5 MT |
215 | for repo in ${BASEDIR}/*; do |
216 | [ -d "${repo}/.git" ] || continue | |
fd9f9810 | 217 | |
a70eabe7 | 218 | build "${repo}" |
fd9f9810 | 219 | done |
d2b7a495 | 220 | |
555260fa MT |
221 | # Try to sync even nothing was built for retrying failed uploads |
222 | sync | |
223 | ||
d2b7a495 | 224 | exit 0 |