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