]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
Add changelog generation code in dinstall
[dak.git] / config / debian / cron.dinstall
1 #!/bin/bash
2 # No way I try to deal with a crippled sh just for POSIX foo.
3
4 # Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Homer: Are you saying you're never going to eat any animal again? What
20 #        about bacon?
21 # Lisa: No.
22 # Homer: Ham?
23 # Lisa: No.
24 # Homer: Pork chops?
25 # Lisa: Dad, those all come from the same animal.
26 # Homer: Heh heh heh. Ooh, yeah, right, Lisa. A wonderful, magical animal.
27
28 # exit on errors
29 set -e
30 # make sure to only use defined variables
31 set -u
32 # ERR traps should be inherited from functions too. (And command
33 # substitutions and subshells and whatnot, but for us the functions is
34 # the important part here)
35 set -E
36
37 # import the general variable set.
38 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
39 . $SCRIPTVARS
40
41 ########################################################################
42 # Functions                                                            #
43 ########################################################################
44 # common functions are "outsourced"
45 . "${configdir}/common"
46
47 # source the dinstall functions
48 . "${configdir}/dinstall.functions"
49
50 ########################################################################
51 ########################################################################
52
53 # Function to save which stage we are in, so we can restart an interrupted
54 # dinstall. Or even run actions in parallel, if we dare to, by simply
55 # backgrounding the call to this function. But that should only really be
56 # done for things we don't care much about.
57 #
58 # This should be called with the first argument being an array, with the
59 # members
60 #  - FUNC - the function name to call
61 #  - ARGS - Possible arguments to hand to the function. Can be the empty string
62 #  - TIME - The timestamp name. Can be the empty string
63 #  - ERR  - if this is the string false, then the call will be surrounded by
64 #           set +e ... set -e calls, so errors in the function do not exit
65 #           dinstall. Can be the empty string, meaning true.
66 #
67 # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
68 # ADDED FOR DINSTALL FEATURES!
69 function stage() {
70     ARGS='GO[@]'
71     local "${!ARGS}"
72
73     error=${ERR:-"true"}
74
75     STAGEFILE="${stagedir}/${FUNC}"
76     if [ -f "${STAGEFILE}" ]; then
77         stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
78         unixtime=$(date +%s)
79         difference=$(( $unixtime - $stamptime ))
80         if [ ${difference} -ge 14400 ]; then
81             log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
82         else
83             log "Did already run ${FUNC}, not calling again..."
84         fi
85         return
86     fi
87
88     debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
89
90     # Make sure we are always at the same place. If a function wants to be elsewhere,
91     # it has to cd first!
92     cd ${configdir}
93
94     # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
95     # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
96     # dinstall logfile. Short error mails ftw!
97     exec >> "${STAGEFILE}.log" 2>&1
98
99     if [ -f "${LOCK_STOP}" ]; then
100         log "${LOCK_STOP} exists, exiting immediately"
101         exit 42
102     fi
103
104     if [ "${error}" = "false" ]; then
105         set +e
106     fi
107     ${FUNC} ${ARGS}
108
109     # No matter what happened in the function, we make sure we have set -e default state back
110     set -e
111
112     # Make sure we are always at the same place.
113     cd ${configdir}
114
115     # We always use the same umask. If a function wants to do different, fine, but we reset.
116     umask 022
117
118     touch "${STAGEFILE}"
119
120     if [ -n "${TIME}" ]; then
121         ts "${TIME}"
122     fi
123
124     # And the output goes back to the normal logfile
125     exec >> "$LOGFILE" 2>&1
126
127     # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
128     # to it.
129     cat "${STAGEFILE}.log" >> "${LOGFILE}"
130     rm -f "${STAGEFILE}.log"
131
132     if [ -f "${LOCK_STOP}" ]; then
133         log "${LOCK_STOP} exists, exiting immediately"
134         exit 42
135     fi
136 }
137
138 ########################################################################
139
140 # We need logs.
141 LOGFILE="$logdir/dinstall.log"
142
143 exec >> "$LOGFILE" 2>&1
144
145 # And now source our default config
146 . "${configdir}/dinstall.variables"
147
148 # Make sure we start out with a sane umask setting
149 umask 022
150
151 # And use one locale, no matter what the caller has set
152 export LANG=C
153 export LC_ALL=C
154
155 touch "${DINSTALLSTART}"
156 ts "startup"
157 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
158 state "Startup"
159
160 lockfile -l 3600 "${LOCK_DAILY}"
161 trap onerror ERR
162 trap cleanup EXIT TERM HUP INT QUIT
163
164 touch "${LOCK_BRITNEY}"
165
166 GO=(
167     FUNC="savetimestamp"
168     TIME=""
169     ARGS=""
170     ERR="false"
171 )
172 stage $GO
173
174 GO=(
175     FUNC="merkel1"
176     TIME="init"
177     ARGS=""
178     ERR="false"
179 )
180 stage $GO &
181
182 GO=(
183     FUNC="pgdump_pre"
184     TIME="pg_dump1"
185     ARGS=""
186     ERR=""
187 )
188 stage $GO
189
190 GO=(
191     FUNC="updates"
192     TIME="External Updates"
193     ARGS=""
194     ERR="false"
195 )
196 stage $GO
197
198 GO=(
199     FUNC="i18n1"
200     TIME="i18n 1"
201     ARGS=""
202     ERR="false"
203 )
204 stage $GO
205
206 lockfile "$LOCK_ACCEPTED"
207 lockfile "$LOCK_NEW"
208
209 GO=(
210     FUNC="punew"
211     TIME="p-u-new"
212     ARGS="proposedupdates"
213     ERR="false"
214 )
215 stage $GO
216
217 #GO=(
218 #    FUNC="opunew"
219 #    TIME="o-p-u-new"
220 #    ARGS="oldproposedupdates"
221 #    ERR="false"
222 #)
223 #stage $GO
224
225 GO=(
226     FUNC="newstage"
227     TIME="newstage"
228     ARGS=""
229     ERR=""
230 )
231 stage $GO
232
233 GO=(
234     FUNC="cruft"
235     TIME="cruft"
236     ARGS=""
237     ERR=""
238 )
239 stage $GO
240
241 state "indices"
242
243 GO=(
244     FUNC="dominate"
245     TIME="dominate"
246     ARGS=""
247     ERR=""
248 )
249 stage $GO
250
251 GO=(
252     FUNC="filelist"
253     TIME="generate-filelist"
254     ARGS=""
255     ERR=""
256 )
257 stage $GO
258
259 GO=(
260     FUNC="fingerprints"
261     TIME="import-keyring"
262     ARGS=""
263     ERR="false"
264 )
265 stage $GO
266
267 GO=(
268     FUNC="overrides"
269     TIME="overrides"
270     ARGS=""
271     ERR=""
272 )
273 stage $GO
274
275 GO=(
276     FUNC="mpfm"
277     TIME="pkg-file-mapping"
278     ARGS=""
279     ERR="false"
280 )
281 stage $GO
282
283 state "packages/contents"
284 GO=(
285     FUNC="packages"
286     TIME="apt-ftparchive"
287     ARGS=""
288     ERR=""
289 )
290 # Careful: When we ever go and remove this monster-long thing, we have to check the backgrounded
291 # functions before it. We no longer have a 1.5hour sync point then.
292 stage $GO
293
294 state "dists/"
295 GO=(
296     FUNC="pdiff"
297     TIME="pdiff"
298     ARGS=""
299     ERR=""
300 )
301 stage $GO
302
303 GO=(
304     FUNC="release"
305     TIME="release files"
306     ARGS=""
307     ERR=""
308 )
309 stage $GO
310
311 GO=(
312     FUNC="dakcleanup"
313     TIME="cleanup"
314     ARGS=""
315     ERR=""
316 )
317 stage $GO
318
319 GO=(
320     FUNC="buildd_dir"
321     TIME="buildd_dir"
322     ARGS=""
323     ERR=""
324 )
325 stage $GO
326
327 state "scripts"
328 GO=(
329     FUNC="mkmaintainers"
330     TIME="mkmaintainers"
331     ARGS=""
332     ERR=""
333 )
334 stage $GO
335
336 GO=(
337     FUNC="mkuploaders"
338     TIME="mkuploaders"
339     ARGS=""
340     ERR=""
341 )
342 stage $GO
343
344 GO=(
345     FUNC="copyoverrides"
346     TIME="copyoverrides"
347     ARGS=""
348     ERR=""
349 )
350 stage $GO
351
352 GO=(
353     FUNC="mklslar"
354     TIME="mklslar"
355     ARGS=""
356     ERR=""
357 )
358 stage $GO
359
360 GO=(
361     FUNC="mkfilesindices"
362     TIME="mkfilesindices"
363     ARGS=""
364     ERR=""
365 )
366 stage $GO
367
368 GO=(
369     FUNC="mkchecksums"
370     TIME="mkchecksums"
371     ARGS=""
372     ERR=""
373 )
374 stage $GO
375
376 GO=(
377     FUNC="mirror"
378     TIME="mirror hardlinks"
379     ARGS=""
380     ERR=""
381 )
382 stage $GO
383
384 rm -f "$LOCK_ACCEPTED"
385 rm -f "$LOCK_NEW"
386 rm -f "${LOCK_DAILY}"
387
388 ts "locked part finished"
389 state "postlock"
390
391 GO=(
392     FUNC="changelogs"
393     TIME="changelogs"
394     ARGS=""
395     ERR="false"
396 )
397 stage $GO &
398
399 GO=(
400     FUNC="pgdump_post"
401     TIME="pg_dump2"
402     ARGS=""
403     ERR=""
404 )
405 stage $GO &
406
407 GO=(
408     FUNC="expire"
409     TIME="expire_dumps"
410     ARGS=""
411     ERR=""
412 )
413 stage $GO &
414
415 GO=(
416     FUNC="transitionsclean"
417     TIME="transitionsclean"
418     ARGS=""
419     ERR=""
420 )
421 stage $GO &
422
423 GO=(
424     FUNC="reports"
425     TIME="reports"
426     ARGS=""
427     ERR=""
428 )
429 stage $GO &
430
431 GO=(
432     FUNC="dm"
433     TIME=""
434     ARGS=""
435     ERR=""
436 )
437 stage $GO &
438
439 GO=(
440     FUNC="bts"
441     TIME=""
442     ARGS=""
443     ERR="false"
444 )
445 stage $GO &
446
447 GO=(
448     FUNC="merkel2"
449     TIME="merkel projectb push"
450     ARGS=""
451     ERR="false"
452 )
453 stage $GO &
454
455 GO=(
456     FUNC="mirrorpush"
457     TIME="mirrorpush"
458     ARGS=""
459     ERR="false"
460 )
461 stage $GO &
462
463 GO=(
464     FUNC="i18n2"
465     TIME="i18n 2"
466     ARGS=""
467     ERR="false"
468 )
469 stage $GO &
470
471 GO=(
472     FUNC="stats"
473     TIME="stats"
474     ARGS=""
475     ERR="false"
476 )
477 stage $GO &
478
479 GO=(
480     FUNC="testingsourcelist"
481     TIME=""
482     ARGS=""
483     ERR="false"
484 )
485 stage $GO &
486
487 rm -f "${LOCK_BRITNEY}"
488
489 GO=(
490     FUNC="pgdakdev"
491     TIME="dak-dev db"
492     ARGS=""
493     ERR="false"
494 )
495 stage $GO &
496
497 GO=(
498     FUNC="merkel3"
499     TIME="merkel ddaccessible sync"
500     ARGS=""
501     ERR="false"
502 )
503 stage $GO &
504
505 GO=(
506     FUNC="compress"
507     TIME="compress"
508     ARGS=""
509     ERR=""
510 )
511 stage $GO &
512
513 GO=(
514     FUNC="aptftpcleanup"
515     TIME="apt-ftparchive cleanup"
516     ARGS=""
517     ERR="false"
518 )
519 stage $GO
520
521 log "Daily cron scripts successful, all done"
522
523 exec > "$logdir/afterdinstall.log" 2>&1
524
525 GO=(
526     FUNC="renamelogfile"
527     TIME=""
528     ARGS=""
529     ERR="false"
530 )
531 stage $GO
532 state "all done"
533
534
535 # Now, at the very (successful) end of dinstall, make sure we remove
536 # our stage files, so the next dinstall run will do it all again.
537 rm -f ${stagedir}/*
538 touch "${DINSTALLEND}"