]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
path changes
[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 rm -f "$LOCK_ACCEPTED"
242 rm -f "$LOCK_NEW"
243
244 state "indices"
245
246 GO=(
247     FUNC="dominate"
248     TIME="dominate"
249     ARGS=""
250     ERR=""
251 )
252 stage $GO
253
254 GO=(
255     FUNC="filelist"
256     TIME="generate-filelist"
257     ARGS=""
258     ERR=""
259 )
260 stage $GO
261
262 GO=(
263     FUNC="fingerprints"
264     TIME="import-keyring"
265     ARGS=""
266     ERR="false"
267 )
268 stage $GO &
269
270 GO=(
271     FUNC="overrides"
272     TIME="overrides"
273     ARGS=""
274     ERR=""
275 )
276 stage $GO
277
278 GO=(
279     FUNC="mpfm"
280     TIME="pkg-file-mapping"
281     ARGS=""
282     ERR="false"
283 )
284 stage $GO &
285
286 state "packages/contents"
287 GO=(
288     FUNC="packages"
289     TIME="apt-ftparchive"
290     ARGS=""
291     ERR=""
292 )
293 # Careful: When we ever go and remove this monster-long thing, we have to check the backgrounded
294 # functions before it. We no longer have a 1.5hour sync point then.
295 stage $GO
296
297 state "dists/"
298 GO=(
299     FUNC="pdiff"
300     TIME="pdiff"
301     ARGS=""
302     ERR=""
303 )
304 stage $GO
305
306 GO=(
307     FUNC="release"
308     TIME="release files"
309     ARGS=""
310     ERR=""
311 )
312 stage $GO
313
314 GO=(
315     FUNC="dakcleanup"
316     TIME="cleanup"
317     ARGS=""
318     ERR=""
319 )
320 stage $GO
321
322 GO=(
323     FUNC="buildd_dir"
324     TIME="buildd_dir"
325     ARGS=""
326     ERR=""
327 )
328 stage $GO
329
330 state "scripts"
331 GO=(
332     FUNC="mkmaintainers"
333     TIME="mkmaintainers"
334     ARGS=""
335     ERR=""
336 )
337 stage $GO
338
339 GO=(
340     FUNC="mkuploaders"
341     TIME="mkuploaders"
342     ARGS=""
343     ERR=""
344 )
345 stage $GO
346
347 GO=(
348     FUNC="copyoverrides"
349     TIME="copyoverrides"
350     ARGS=""
351     ERR=""
352 )
353 stage $GO
354
355 GO=(
356     FUNC="mklslar"
357     TIME="mklslar"
358     ARGS=""
359     ERR=""
360 )
361 stage $GO
362
363 GO=(
364     FUNC="mkfilesindices"
365     TIME="mkfilesindices"
366     ARGS=""
367     ERR=""
368 )
369 stage $GO
370
371 GO=(
372     FUNC="mkchecksums"
373     TIME="mkchecksums"
374     ARGS=""
375     ERR=""
376 )
377 stage $GO
378
379 GO=(
380     FUNC="mirror"
381     TIME="mirror hardlinks"
382     ARGS=""
383     ERR=""
384 )
385 stage $GO
386
387 rm -f "${LOCK_DAILY}"
388
389 ts "locked part finished"
390 state "postlock"
391
392 GO=(
393     FUNC="pgdump_post"
394     TIME="pg_dump2"
395     ARGS=""
396     ERR=""
397 )
398 stage $GO &
399
400 GO=(
401     FUNC="expire"
402     TIME="expire_dumps"
403     ARGS=""
404     ERR=""
405 )
406 stage $GO &
407
408 GO=(
409     FUNC="transitionsclean"
410     TIME="transitionsclean"
411     ARGS=""
412     ERR=""
413 )
414 stage $GO &
415
416 GO=(
417     FUNC="reports"
418     TIME="reports"
419     ARGS=""
420     ERR=""
421 )
422 stage $GO &
423
424 GO=(
425     FUNC="dm"
426     TIME=""
427     ARGS=""
428     ERR=""
429 )
430 stage $GO &
431
432 GO=(
433     FUNC="bts"
434     TIME=""
435     ARGS=""
436     ERR="false"
437 )
438 stage $GO &
439
440 GO=(
441     FUNC="merkel2"
442     TIME="merkel projectb push"
443     ARGS=""
444     ERR="false"
445 )
446 stage $GO &
447
448 GO=(
449     FUNC="mirrorpush"
450     TIME="mirrorpush"
451     ARGS=""
452     ERR="false"
453 )
454 stage $GO &
455
456 GO=(
457     FUNC="i18n2"
458     TIME="i18n 2"
459     ARGS=""
460     ERR="false"
461 )
462 stage $GO &
463
464 GO=(
465     FUNC="stats"
466     TIME="stats"
467     ARGS=""
468     ERR="false"
469 )
470 stage $GO &
471
472 GO=(
473     FUNC="testingsourcelist"
474     TIME=""
475     ARGS=""
476     ERR="false"
477 )
478 stage $GO &
479
480 rm -f "${LOCK_BRITNEY}"
481
482 GO=(
483     FUNC="pgdakdev"
484     TIME="dak-dev db"
485     ARGS=""
486     ERR="false"
487 )
488 stage $GO &
489
490 GO=(
491     FUNC="merkel3"
492     TIME="merkel ddaccessible sync"
493     ARGS=""
494     ERR="false"
495 )
496 stage $GO &
497
498 GO=(
499     FUNC="compress"
500     TIME="compress"
501     ARGS=""
502     ERR=""
503 )
504 stage $GO &
505
506 GO=(
507     FUNC="aptftpcleanup"
508     TIME="apt-ftparchive cleanup"
509     ARGS=""
510     ERR="false"
511 )
512 stage $GO
513
514 log "Daily cron scripts successful, all done"
515
516 exec > "$logdir/afterdinstall.log" 2>&1
517
518 GO=(
519     FUNC="renamelogfile"
520     TIME=""
521     ARGS=""
522     ERR="false"
523 )
524 stage $GO
525 state "all done"
526
527
528 # Now, at the very (successful) end of dinstall, make sure we remove
529 # our stage files, so the next dinstall run will do it all again.
530 rm -f ${stagedir}/*
531 touch "${DINSTALLEND}"