1 |
commit: b291ea47548bf025259632a18d86e16d9bb0a886 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 16 01:11:44 2018 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 16 01:11:44 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/releng.git/commit/?id=b291ea47 |
7 |
|
8 |
catalyst-auto: move all code into functions |
9 |
|
10 |
Mixing inline funcs and executable code makes it hard to follow and |
11 |
shuffle ordering of operations. Put everything other than variables |
12 |
into functions. |
13 |
|
14 |
The delta here is large, but it's almost entirely indentation changes. |
15 |
|
16 |
This also makes updating the script (like `git pull`) more resilient. |
17 |
|
18 |
tools/catalyst-auto | 536 ++++++++++++++++++++++++++-------------------------- |
19 |
1 file changed, 273 insertions(+), 263 deletions(-) |
20 |
|
21 |
diff --git a/tools/catalyst-auto b/tools/catalyst-auto |
22 |
index 02115d1c..cf5a7c65 100755 |
23 |
--- a/tools/catalyst-auto |
24 |
+++ b/tools/catalyst-auto |
25 |
@@ -19,6 +19,17 @@ unset UNSHARE |
26 |
|
27 |
CATALYST_CONFIG=/etc/catalyst/catalyst.conf |
28 |
|
29 |
+# Probe the default source dir from this script name. |
30 |
+REPO_DIR=$(dirname "$(dirname "$(realpath "$0")")") |
31 |
+ |
32 |
+# Set up defaults that config files can override if they want. |
33 |
+SUBARCH=$(uname -m) |
34 |
+EMAIL_TO="releng@g.o,gentoo-releng-autobuilds@l.g.o" |
35 |
+# Use full hostname by default as Gentoo servers will reject short names. |
36 |
+EMAIL_FROM="catalyst@$(hostname -f)" |
37 |
+EMAIL_SUBJECT_PREPEND="[${SUBARCH}-auto]" |
38 |
+ |
39 |
+# Variables updated by command line arguments. |
40 |
declare -a config_files |
41 |
config_files=() |
42 |
verbose=0 |
43 |
@@ -28,9 +39,6 @@ preclean=0 |
44 |
lastrun=0 |
45 |
lock_file= |
46 |
|
47 |
-# Set pipefail so that run_cmd returns the right value in $? |
48 |
-set -o pipefail |
49 |
- |
50 |
usage() { |
51 |
local msg=$1 |
52 |
|
53 |
@@ -125,269 +133,271 @@ trigger_post_build() { |
54 |
fi |
55 |
} |
56 |
|
57 |
-# Parse args |
58 |
-while [ ${#} -gt 0 ] |
59 |
-do |
60 |
- a=${1} |
61 |
- shift |
62 |
- case "${a}" in |
63 |
- -h|--help) |
64 |
- usage |
65 |
- exit 0 |
66 |
- ;; |
67 |
- -c|--config) |
68 |
- config_files+=("$1") |
69 |
- shift |
70 |
- ;; |
71 |
- -v|--verbose) |
72 |
- verbose=$(($verbose+1)) |
73 |
- ;; |
74 |
- -k|--keep-tmpdir) |
75 |
- keep_tmpdir=1 |
76 |
- ;; |
77 |
- -t|--test) |
78 |
- testing=1 |
79 |
- ;; |
80 |
- -C|--preclean) |
81 |
- preclean=1 |
82 |
- ;; |
83 |
- --interval) |
84 |
- lastrun=$1 |
85 |
- shift |
86 |
- ;; |
87 |
- -l|--lock) |
88 |
- lock_file=$1 |
89 |
- shift |
90 |
- ;; |
91 |
- -*) |
92 |
- usage "ERROR: You have specified an invalid option: ${a}" |
93 |
- exit 1 |
94 |
- ;; |
95 |
- *) |
96 |
- usage "ERROR: This script takes no arguments: ${a}" |
97 |
- exit 1 |
98 |
- ;; |
99 |
- esac |
100 |
-done |
101 |
- |
102 |
-( |
103 |
- |
104 |
-if [[ -n ${lock_file} ]]; then |
105 |
- if ! flock -n 9; then |
106 |
- echo "catalyst-auto already running" |
107 |
- exit 1 |
108 |
- fi |
109 |
-fi |
110 |
- |
111 |
-# Probe the default source dir from this script name. |
112 |
-REPO_DIR=$(dirname "$(dirname "$(realpath "$0")")") |
113 |
- |
114 |
-# Set up defaults that config files can override if they want. |
115 |
-SUBARCH=$(uname -m) |
116 |
-EMAIL_TO="releng@g.o,gentoo-releng-autobuilds@l.g.o" |
117 |
-# Use full hostname by default as Gentoo servers will reject short names. |
118 |
-EMAIL_FROM="catalyst@$(hostname -f)" |
119 |
-EMAIL_SUBJECT_PREPEND="[${SUBARCH}-auto]" |
120 |
- |
121 |
-doneconfig=0 |
122 |
-for config_file in "${config_files[@]}"; do |
123 |
- # Make sure all required values were specified |
124 |
- if [ -z "${config_file}" -o ! -e "${config_file}" ]; then |
125 |
- usage "ERROR: You must specify a valid config file to use: '$config_file' is not valid" |
126 |
- exit 1 |
127 |
- fi |
128 |
- source "${config_file}" |
129 |
- doneconfig=1 |
130 |
-done |
131 |
-if [[ $doneconfig -eq 0 ]]; then |
132 |
- usage "ERROR: You must specify at least one valid config file to use" |
133 |
- exit 1 |
134 |
-fi |
135 |
- |
136 |
-# Some configs will set this explicitly, so don't clobber it. |
137 |
-: ${BUILD_SRCDIR_BASE:=$(catalyst_var storedir)} |
138 |
- |
139 |
-# See if we had a recent success. |
140 |
-if [[ ${lastrun} -ne 0 ]]; then |
141 |
- last_success_file="${BUILD_SRCDIR_BASE}/.last_success" |
142 |
- delay=$(( lastrun * 24 * 60 * 60 )) |
143 |
- last_success=$(head -1 "${last_success_file}" 2>/dev/null || echo 0) |
144 |
- if [[ $(date +%s) -lt $(( last_success + delay )) ]]; then |
145 |
- exit 0 |
146 |
- fi |
147 |
-fi |
148 |
- |
149 |
-DATESTAMP=$(date -u +%Y%m%d) |
150 |
-TIMESTAMP=$(date -u +%Y%m%dT%H%M%SZ) |
151 |
-TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" "catalyst-auto.${TIMESTAMP}.XXXXXX") |
152 |
- |
153 |
-# Nuke any previous tmpdirs to keep them from accumulating. |
154 |
-if [[ ${preclean} -eq 1 ]]; then |
155 |
- rm -rf "${TMPDIR%.??????}".* |
156 |
- mkdir "${TMPDIR}" |
157 |
-fi |
158 |
- |
159 |
-if [ ${verbose} -ge 1 ]; then |
160 |
- echo "TMPDIR = ${TMPDIR}" |
161 |
- echo "DATESTAMP = ${DATESTAMP}" |
162 |
- echo "TIMESTAMP = ${TIMESTAMP}" |
163 |
-fi |
164 |
- |
165 |
-if ! mkdir -p "${TMPDIR}"/{specs,kconfig,log}; then |
166 |
- echo "Couldn't create tempdirs!" |
167 |
- exit 1 |
168 |
-fi |
169 |
- |
170 |
-if ! run_cmd "${TMPDIR}/log/pre_build.log" pre_build; then |
171 |
- send_email "Catalyst build error - pre_build" "The pre_build function failed" "${TMPDIR}/log/pre_build.log" |
172 |
- exit 1 |
173 |
-fi |
174 |
- |
175 |
-cd "${SPECS_DIR}" || exit 1 |
176 |
- |
177 |
-for a in "" ${SETS}; do |
178 |
- if [ -z "${a}" ]; then |
179 |
- specs_var="SPECS" |
180 |
- optional_specs_var="OPTIONAL_SPECS" |
181 |
- else |
182 |
- specs_var="SET_${a}_SPECS" |
183 |
- optional_specs_var="SET_${a}_OPTIONAL_SPECS" |
184 |
- fi |
185 |
- |
186 |
- for i in ${!specs_var} ${!optional_specs_var}; do |
187 |
- cp --parents "${i}" "${TMPDIR}"/specs/ |
188 |
- done |
189 |
-done |
190 |
- |
191 |
-find "${KCONFIG_DIR}" -type f -exec cp {} "${TMPDIR}"/kconfig \; |
192 |
- |
193 |
-cd "${TMPDIR}/specs" || exit 1 |
194 |
- |
195 |
-# Fix up specs with datestamp |
196 |
-for i in $(find -name '*.spec'); do |
197 |
- # Grab current version_stamp and source_subpath |
198 |
- old_version_stamp=$(grep version_stamp "${i}" | sed -e 's|^version_stamp: *||') |
199 |
- old_source_subpath=$(grep source_subpath "${i}" | sed -e 's|^source_subpath: *||') |
200 |
- |
201 |
- new_version_stamp=$(echo "${old_version_stamp}" | sed -e "s|^\(.*-\)\?.*$|\1${TIMESTAMP}|") |
202 |
- new_source_subpath=$(echo "${old_source_subpath}" | sed -e "s|${old_version_stamp}|${new_version_stamp}|") |
203 |
- |
204 |
- sed -i "s|^version_stamp:.*$|version_stamp: ${new_version_stamp}|" "${i}" |
205 |
- sed -i "s|^snapshot:.*$|snapshot: ${TIMESTAMP}|" "${i}" |
206 |
- |
207 |
- # We don't want to mangle the source_subpath for our stage1 spec |
208 |
- if ! grep -q '^target: *stage[14]$' "${i}"; then |
209 |
- sed -i "s|^source_subpath:.*$|source_subpath: ${new_source_subpath}|" "${i}" |
210 |
- fi |
211 |
- |
212 |
- sed -i "/^livecd\/iso/s|${old_version_stamp}|${new_version_stamp}|" "${i}" |
213 |
- sed -i "/^livecd\/volid/s|${old_version_stamp}|${new_version_stamp}|" "${i}" |
214 |
- |
215 |
- kconfig_lines=$(grep '^boot/kernel/[^/]\+/config:' "${i}") |
216 |
- if [ -n "${kconfig_lines}" ]; then |
217 |
- echo "${kconfig_lines}" | while read line; do |
218 |
- key=$(echo "${line}" | cut -d: -f1) |
219 |
- filename=$(basename $(echo "${line}" | cut -d: -f2)) |
220 |
- sed -i "s|^${key}:.*\$|${key}: ${TMPDIR}/kconfig/${filename}|" "${i}" |
221 |
- done |
222 |
- fi |
223 |
- |
224 |
- # Expand vars that the spec expects us to. |
225 |
- sed -i \ |
226 |
- -e "s:@DATESTAMP@:${DATESTAMP}:g" \ |
227 |
- -e "s:@TIMESTAMP@:${TIMESTAMP}:g" \ |
228 |
- -e "s:@REPO_DIR@:${REPO_DIR}:g" \ |
229 |
- "${i}" |
230 |
-done |
231 |
- |
232 |
-if [ "${testing}" -eq 1 ]; then |
233 |
- echo "Exiting due to --test" |
234 |
- exit |
235 |
-fi |
236 |
- |
237 |
-if [[ ${preclean} -eq 1 ]]; then |
238 |
- snapshot_cache=$(catalyst_var snapshot_cache) |
239 |
- if [[ -z ${snapshot_cache} ]]; then |
240 |
- echo "error: snapshot_cache not set in config file" |
241 |
- exit 1 |
242 |
- fi |
243 |
- pushd "${BUILD_SRCDIR_BASE}" >/dev/null || exit 1 |
244 |
- rm -rf --one-file-system \ |
245 |
- kerncache packages snapshots tmp "${snapshot_cache}"/* |
246 |
- popd >/dev/null |
247 |
-fi |
248 |
- |
249 |
-# Create snapshot |
250 |
-if ! run_cmd "${TMPDIR}/log/snapshot.log" catalyst -c "${CATALYST_CONFIG}" -s "${TIMESTAMP}"; then |
251 |
- send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log" |
252 |
- exit 1 |
253 |
-fi |
254 |
- |
255 |
-build_failure=0 |
256 |
+parse_args() { |
257 |
+ local a |
258 |
+ while [[ $# -gt 0 ]] ; do |
259 |
+ a=$1 |
260 |
+ shift |
261 |
+ case "${a}" in |
262 |
+ -h|--help) |
263 |
+ usage |
264 |
+ exit 0 |
265 |
+ ;; |
266 |
+ -c|--config) |
267 |
+ config_files+=("$1") |
268 |
+ shift |
269 |
+ ;; |
270 |
+ -v|--verbose) |
271 |
+ verbose=$(($verbose+1)) |
272 |
+ ;; |
273 |
+ -k|--keep-tmpdir) |
274 |
+ keep_tmpdir=1 |
275 |
+ ;; |
276 |
+ -t|--test) |
277 |
+ testing=1 |
278 |
+ ;; |
279 |
+ -C|--preclean) |
280 |
+ preclean=1 |
281 |
+ ;; |
282 |
+ --interval) |
283 |
+ lastrun=$1 |
284 |
+ shift |
285 |
+ ;; |
286 |
+ -l|--lock) |
287 |
+ lock_file=$1 |
288 |
+ shift |
289 |
+ ;; |
290 |
+ -*) |
291 |
+ usage "ERROR: You have specified an invalid option: ${a}" |
292 |
+ exit 1 |
293 |
+ ;; |
294 |
+ *) |
295 |
+ usage "ERROR: This script takes no arguments: ${a}" |
296 |
+ exit 1 |
297 |
+ ;; |
298 |
+ esac |
299 |
+ done |
300 |
+} |
301 |
|
302 |
-timeprefix=() |
303 |
-which time >/dev/null && timeprefix=( "time" ) |
304 |
+run_catalyst_commands() { |
305 |
+ doneconfig=0 |
306 |
+ for config_file in "${config_files[@]}"; do |
307 |
+ # Make sure all required values were specified. |
308 |
+ if [[ -z "${config_file}" || ! -e "${config_file}" ]]; then |
309 |
+ usage "ERROR: You must specify a valid config file to use: '$config_file' is not valid" |
310 |
+ exit 1 |
311 |
+ fi |
312 |
+ source "${config_file}" |
313 |
+ doneconfig=1 |
314 |
+ done |
315 |
+ if [[ ${doneconfig} == 0 ]]; then |
316 |
+ usage "ERROR: You must specify at least one valid config file to use" |
317 |
+ exit 1 |
318 |
+ fi |
319 |
+ |
320 |
+ # Some configs will set this explicitly, so don't clobber it. |
321 |
+ : ${BUILD_SRCDIR_BASE:=$(catalyst_var storedir)} |
322 |
+ |
323 |
+ # See if we had a recent success. |
324 |
+ if [[ ${lastrun} != 0 ]]; then |
325 |
+ last_success_file="${BUILD_SRCDIR_BASE}/.last_success" |
326 |
+ delay=$(( lastrun * 24 * 60 * 60 )) |
327 |
+ last_success=$(head -1 "${last_success_file}" 2>/dev/null || echo 0) |
328 |
+ if [[ $(date +%s) -lt $(( last_success + delay )) ]]; then |
329 |
+ exit 0 |
330 |
+ fi |
331 |
+ fi |
332 |
+ |
333 |
+ DATESTAMP=$(date -u +%Y%m%d) |
334 |
+ TIMESTAMP=$(date -u +%Y%m%dT%H%M%SZ) |
335 |
+ TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" "catalyst-auto.${TIMESTAMP}.XXXXXX") |
336 |
+ |
337 |
+ # Nuke any previous tmpdirs to keep them from accumulating. |
338 |
+ if [[ ${preclean} == 1 ]]; then |
339 |
+ rm -rf "${TMPDIR%.??????}".* |
340 |
+ mkdir "${TMPDIR}" |
341 |
+ fi |
342 |
+ |
343 |
+ if [[ ${verbose} -ge 1 ]]; then |
344 |
+ echo "TMPDIR = ${TMPDIR}" |
345 |
+ echo "DATESTAMP = ${DATESTAMP}" |
346 |
+ echo "TIMESTAMP = ${TIMESTAMP}" |
347 |
+ fi |
348 |
+ |
349 |
+ if ! mkdir -p "${TMPDIR}"/{specs,kconfig,log}; then |
350 |
+ echo "Couldn't create tempdirs!" |
351 |
+ exit 1 |
352 |
+ fi |
353 |
+ |
354 |
+ if ! run_cmd "${TMPDIR}/log/pre_build.log" pre_build; then |
355 |
+ send_email "Catalyst build error - pre_build" "The pre_build function failed" "${TMPDIR}/log/pre_build.log" |
356 |
+ exit 1 |
357 |
+ fi |
358 |
+ |
359 |
+ cd "${SPECS_DIR}" || exit 1 |
360 |
+ |
361 |
+ for a in "" ${SETS}; do |
362 |
+ if [[ -z "${a}" ]]; then |
363 |
+ specs_var="SPECS" |
364 |
+ optional_specs_var="OPTIONAL_SPECS" |
365 |
+ else |
366 |
+ specs_var="SET_${a}_SPECS" |
367 |
+ optional_specs_var="SET_${a}_OPTIONAL_SPECS" |
368 |
+ fi |
369 |
+ |
370 |
+ for i in ${!specs_var} ${!optional_specs_var}; do |
371 |
+ cp --parents "${i}" "${TMPDIR}"/specs/ |
372 |
+ done |
373 |
+ done |
374 |
+ |
375 |
+ find "${KCONFIG_DIR}" -type f -exec cp {} "${TMPDIR}"/kconfig \; |
376 |
+ |
377 |
+ cd "${TMPDIR}/specs" || exit 1 |
378 |
+ |
379 |
+ # Fix up specs with datestamp |
380 |
+ for i in $(find -name '*.spec'); do |
381 |
+ # Grab current version_stamp and source_subpath |
382 |
+ old_version_stamp=$(grep version_stamp "${i}" | sed -e 's|^version_stamp: *||') |
383 |
+ old_source_subpath=$(grep source_subpath "${i}" | sed -e 's|^source_subpath: *||') |
384 |
+ |
385 |
+ new_version_stamp=$(echo "${old_version_stamp}" | sed -e "s|^\(.*-\)\?.*$|\1${TIMESTAMP}|") |
386 |
+ new_source_subpath=$(echo "${old_source_subpath}" | sed -e "s|${old_version_stamp}|${new_version_stamp}|") |
387 |
+ |
388 |
+ sed -i "s|^version_stamp:.*$|version_stamp: ${new_version_stamp}|" "${i}" |
389 |
+ sed -i "s|^snapshot:.*$|snapshot: ${TIMESTAMP}|" "${i}" |
390 |
+ |
391 |
+ # We don't want to mangle the source_subpath for our stage1 spec |
392 |
+ if ! grep -q '^target: *stage[14]$' "${i}"; then |
393 |
+ sed -i "s|^source_subpath:.*$|source_subpath: ${new_source_subpath}|" "${i}" |
394 |
+ fi |
395 |
+ |
396 |
+ sed -i "/^livecd\/iso/s|${old_version_stamp}|${new_version_stamp}|" "${i}" |
397 |
+ sed -i "/^livecd\/volid/s|${old_version_stamp}|${new_version_stamp}|" "${i}" |
398 |
+ |
399 |
+ kconfig_lines=$(grep '^boot/kernel/[^/]\+/config:' "${i}") |
400 |
+ if [[ -n ${kconfig_lines} ]]; then |
401 |
+ echo "${kconfig_lines}" | while read line; do |
402 |
+ key=$(echo "${line}" | cut -d: -f1) |
403 |
+ filename=$(basename $(echo "${line}" | cut -d: -f2)) |
404 |
+ sed -i "s|^${key}:.*\$|${key}: ${TMPDIR}/kconfig/${filename}|" "${i}" |
405 |
+ done |
406 |
+ fi |
407 |
+ |
408 |
+ # Expand vars that the spec expects us to. |
409 |
+ sed -i \ |
410 |
+ -e "s:@DATESTAMP@:${DATESTAMP}:g" \ |
411 |
+ -e "s:@TIMESTAMP@:${TIMESTAMP}:g" \ |
412 |
+ -e "s:@REPO_DIR@:${REPO_DIR}:g" \ |
413 |
+ "${i}" |
414 |
+ done |
415 |
+ |
416 |
+ if [[ ${testing} == 1 ]]; then |
417 |
+ echo "Exiting due to --test" |
418 |
+ exit |
419 |
+ fi |
420 |
+ |
421 |
+ if [[ ${preclean} == 1 ]]; then |
422 |
+ snapshot_cache=$(catalyst_var snapshot_cache) |
423 |
+ if [[ -z ${snapshot_cache} ]]; then |
424 |
+ echo "error: snapshot_cache not set in config file" |
425 |
+ exit 1 |
426 |
+ fi |
427 |
+ pushd "${BUILD_SRCDIR_BASE}" >/dev/null || exit 1 |
428 |
+ rm -rf --one-file-system \ |
429 |
+ kerncache packages snapshots tmp "${snapshot_cache}"/* |
430 |
+ popd >/dev/null |
431 |
+ fi |
432 |
+ |
433 |
+ # Create snapshot |
434 |
+ if ! run_cmd "${TMPDIR}/log/snapshot.log" catalyst -c "${CATALYST_CONFIG}" -s "${TIMESTAMP}"; then |
435 |
+ send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log" |
436 |
+ exit 1 |
437 |
+ fi |
438 |
+ |
439 |
+ build_failure=0 |
440 |
+ |
441 |
+ timeprefix=() |
442 |
+ which time >/dev/null && timeprefix=( "time" ) |
443 |
+ |
444 |
+ for a in "" ${SETS}; do |
445 |
+ if [[ -z ${a} ]]; then |
446 |
+ specs_var="SPECS" |
447 |
+ optional_specs_var="OPTIONAL_SPECS" |
448 |
+ else |
449 |
+ specs_var="SET_${a}_SPECS" |
450 |
+ optional_specs_var="SET_${a}_OPTIONAL_SPECS" |
451 |
+ fi |
452 |
+ |
453 |
+ for i in ${!specs_var}; do |
454 |
+ LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" |
455 |
+ run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -c "${CATALYST_CONFIG}" -f "${i}" |
456 |
+ if [[ $? != 0 ]]; then |
457 |
+ build_failure=1 |
458 |
+ send_email "Catalyst fatal build error - ${i}" "" "${LOGFILE}" |
459 |
+ continue 2 |
460 |
+ else |
461 |
+ trigger_post_build |
462 |
+ fi |
463 |
+ done |
464 |
+ |
465 |
+ for i in ${!optional_specs_var}; do |
466 |
+ LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" |
467 |
+ run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -c "${CATALYST_CONFIG}" -f "${i}" |
468 |
+ if [[ $? != 0 ]]; then |
469 |
+ build_failure=1 |
470 |
+ send_email "Catalyst non-fatal build error - ${i}" "" "${LOGFILE}" |
471 |
+ break |
472 |
+ else |
473 |
+ trigger_post_build |
474 |
+ fi |
475 |
+ done |
476 |
+ |
477 |
+ for i in ${!specs_var} ${!optional_specs_var}; do |
478 |
+ LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::')_purge.log" |
479 |
+ run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst --purgetmponly -c "${CATALYST_CONFIG}" -f "${i}" |
480 |
+ done |
481 |
+ |
482 |
+ update_symlinks |
483 |
+ done |
484 |
+ |
485 |
+ trigger_post_build |
486 |
+ |
487 |
+ if [[ ${build_failure} == 0 ]]; then |
488 |
+ if [[ ${lastrun} != 0 ]]; then |
489 |
+ stamp=$(date) |
490 |
+ (date -d"${stamp}" +%s; echo "${stamp}") >"${last_success_file}" |
491 |
+ fi |
492 |
+ |
493 |
+ send_email "Catalyst build success" "Build process complete." |
494 |
+ |
495 |
+ if [[ ${keep_tmpdir} == 0 ]]; then |
496 |
+ if ! rm -rf "${TMPDIR}"; then |
497 |
+ echo "Could not remove tmpdir ${TMPDIR}!" |
498 |
+ exit 1 |
499 |
+ fi |
500 |
+ fi |
501 |
+ else |
502 |
+ send_email "Catalyst build complete, but with errors" "Build process has completed, but there were errors. Please consult previous emails to determine the problem." |
503 |
+ fi |
504 |
+} |
505 |
|
506 |
-for a in "" ${SETS}; do |
507 |
- if [ -z "${a}" ]; then |
508 |
- specs_var="SPECS" |
509 |
- optional_specs_var="OPTIONAL_SPECS" |
510 |
- else |
511 |
- specs_var="SET_${a}_SPECS" |
512 |
- optional_specs_var="SET_${a}_OPTIONAL_SPECS" |
513 |
- fi |
514 |
+main() { |
515 |
+ # Set pipefail so that run_cmd returns the right value in $?. |
516 |
+ set -o pipefail |
517 |
|
518 |
- for i in ${!specs_var}; do |
519 |
- LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" |
520 |
- run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -c "${CATALYST_CONFIG}" -f "${i}" |
521 |
- if [ $? != 0 ]; then |
522 |
- build_failure=1 |
523 |
- send_email "Catalyst fatal build error - ${i}" "" "${LOGFILE}" |
524 |
- continue 2 |
525 |
- else |
526 |
- trigger_post_build |
527 |
- fi |
528 |
- done |
529 |
- |
530 |
- for i in ${!optional_specs_var}; do |
531 |
- LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" |
532 |
- run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -c "${CATALYST_CONFIG}" -f "${i}" |
533 |
- if [ $? != 0 ]; then |
534 |
- build_failure=1 |
535 |
- send_email "Catalyst non-fatal build error - ${i}" "" "${LOGFILE}" |
536 |
- break |
537 |
- else |
538 |
- trigger_post_build |
539 |
- fi |
540 |
- done |
541 |
- |
542 |
- for i in ${!specs_var} ${!optional_specs_var}; do |
543 |
- LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::')_purge.log" |
544 |
- run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst --purgetmponly -c "${CATALYST_CONFIG}" -f "${i}" |
545 |
- done |
546 |
- |
547 |
- update_symlinks |
548 |
-done |
549 |
- |
550 |
-trigger_post_build |
551 |
- |
552 |
-if [ ${build_failure} = 0 ]; then |
553 |
- if [[ ${lastrun} -ne 0 ]]; then |
554 |
- stamp=$(date) |
555 |
- (date -d"${stamp}" +%s; echo "${stamp}") >"${last_success_file}" |
556 |
- fi |
557 |
+ # Parse user arguments before we try doing container logic. |
558 |
+ parse_args "$@" |
559 |
|
560 |
- send_email "Catalyst build success" "Build process complete." |
561 |
+ ( |
562 |
+ if [[ -n ${lock_file} ]]; then |
563 |
+ if ! flock -n 9; then |
564 |
+ echo "catalyst-auto already running" |
565 |
+ exit 1 |
566 |
+ fi |
567 |
+ fi |
568 |
|
569 |
- if [ "${keep_tmpdir}" = 0 ]; then |
570 |
- if ! rm -rf "${TMPDIR}"; then |
571 |
- echo "Could not remove tmpdir ${TMPDIR}!" |
572 |
- exit 1 |
573 |
- fi |
574 |
- fi |
575 |
- |
576 |
-else |
577 |
- send_email "Catalyst build complete, but with errors" "Build process has completed, but there were errors. Please consult previous emails to determine the problem." |
578 |
-fi |
579 |
+ run_catalyst_commands |
580 |
+ ) 9>"${lock_file:-/dev/null}" |
581 |
+} |
582 |
|
583 |
-) 9>"${lock_file:-/dev/null}" |
584 |
+main "$@" |