]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
Merge commit 'twerner/msfl' into merge
[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
158 lockfile -l 3600 "${LOCK_DAILY}"
159 trap onerror ERR
160 trap cleanup EXIT TERM HUP INT QUIT
161
162 touch "${LOCK_BRITNEY}"
163
164 GO=(
165     FUNC="savetimestamp"
166     TIME=""
167     ARGS=""
168     ERR="false"
169 )
170 stage $GO
171
172 GO=(
173     FUNC="merkel1"
174     TIME="init"
175     ARGS=""
176     ERR="false"
177 )
178 stage $GO &
179
180 GO=(
181     FUNC="pgdump_pre"
182     TIME="pg_dump1"
183     ARGS=""
184     ERR=""
185 )
186 stage $GO
187
188 GO=(
189     FUNC="updates"
190     TIME="External Updates"
191     ARGS=""
192     ERR="false"
193 )
194 stage $GO &
195
196 GO=(
197     FUNC="punew"
198     TIME="p-u-new"
199     ARGS="p-u-new"
200     ERR=""
201 )
202 ### TODO: policy-new
203 #stage $GO
204
205 GO=(
206     FUNC="opunew"
207     TIME="o-p-u-new"
208     ARGS="o-p-u-new"
209     ERR=""
210 )
211 ### TODO: policy-new
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 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 GO=(
245     FUNC="msfl"
246     TIME="make-suite-file-list"
247     ARGS=""
248     ERR=""
249 )
250 stage $GO
251
252 GO=(
253     FUNC="filelist"
254     TIME="generate-filelist"
255     ARGS=""
256     ERR=""
257 )
258 stage $GO
259
260 GO=(
261     FUNC="fingerprints"
262     TIME="import-keyring"
263     ARGS=""
264     ERR="false"
265 )
266 stage $GO &
267
268 GO=(
269     FUNC="overrides"
270     TIME="overrides"
271     ARGS=""
272     ERR=""
273 )
274 stage $GO
275
276 GO=(
277     FUNC="mpfm"
278     TIME="pkg-file-mapping"
279     ARGS=""
280     ERR="false"
281 )
282 stage $GO
283
284 GO=(
285     FUNC="packages"
286     TIME="apt-ftparchive"
287     ARGS=""
288     ERR=""
289 )
290 stage $GO
291
292 GO=(
293     FUNC="pdiff"
294     TIME="pdiff"
295     ARGS=""
296     ERR=""
297 )
298 stage $GO
299
300 GO=(
301     FUNC="release"
302     TIME="release files"
303     ARGS=""
304     ERR=""
305 )
306 stage $GO
307
308 GO=(
309     FUNC="dakcleanup"
310     TIME="cleanup"
311     ARGS=""
312     ERR=""
313 )
314 ### TODO: clean-* fixup
315 #stage $GO
316
317 GO=(
318     FUNC="buildd"
319     TIME="buildd"
320     ARGS=""
321     ERR=""
322 )
323 stage $GO
324
325 GO=(
326     FUNC="scripts"
327     TIME="scripts"
328     ARGS=""
329     ERR=""
330 )
331 stage $GO
332
333 GO=(
334     FUNC="mirror"
335     TIME="mirror hardlinks"
336     ARGS=""
337     ERR=""
338 )
339 stage $GO
340
341 GO=(
342     FUNC="wb"
343     TIME="w-b"
344     ARGS=""
345     ERR=""
346 )
347 stage $GO &
348
349 rm -f "${LOCK_DAILY}"
350
351 ts "locked part finished"
352
353 GO=(
354     FUNC="pgdump_post"
355     TIME="pg_dump2"
356     ARGS=""
357     ERR=""
358 )
359 stage $GO &
360
361 GO=(
362     FUNC="expire"
363     TIME="expire_dumps"
364     ARGS=""
365     ERR=""
366 )
367 stage $GO &
368
369 GO=(
370     FUNC="transitionsclean"
371     TIME="transitionsclean"
372     ARGS=""
373     ERR=""
374 )
375 stage $GO &
376
377 GO=(
378     FUNC="reports"
379     TIME="reports"
380     ARGS=""
381     ERR=""
382 )
383 stage $GO &
384
385 GO=(
386     FUNC="dm"
387     TIME=""
388     ARGS=""
389     ERR=""
390 )
391 stage $GO &
392
393 GO=(
394     FUNC="bts"
395     TIME=""
396     ARGS=""
397     ERR="false"
398 )
399 stage $GO &
400
401 GO=(
402     FUNC="merkel2"
403     TIME="merkel projectb push"
404     ARGS=""
405     ERR="false"
406 )
407 stage $GO &
408
409 GO=(
410     FUNC="mirrorpush"
411     TIME="mirrorpush"
412     ARGS=""
413     ERR="false"
414 )
415 stage $GO
416
417 GO=(
418     FUNC="i18n2"
419     TIME="i18n 2"
420     ARGS=""
421     ERR="false"
422 )
423 stage $GO
424
425 GO=(
426     FUNC="stats"
427     TIME="stats"
428     ARGS=""
429     ERR="false"
430 )
431 stage $GO &
432
433 GO=(
434     FUNC="testingsourcelist"
435     TIME=""
436     ARGS=""
437     ERR="false"
438 )
439 stage $GO
440
441 rm -f ${LOCK_BRITNEY}
442
443 GO=(
444     FUNC="pgdakdev"
445     TIME="dak-dev db"
446     ARGS=""
447     ERR="false"
448 )
449 stage $GO &
450
451 GO=(
452     FUNC="merkel3"
453     TIME="merkel ddaccessible sync"
454     ARGS=""
455     ERR="false"
456 )
457 stage $GO &
458
459 GO=(
460     FUNC="compress"
461     TIME="compress"
462     ARGS=""
463     ERR=""
464 )
465 stage $GO &
466
467 GO=(
468     FUNC="aptftpcleanup"
469     TIME="apt-ftparchive cleanup"
470     ARGS=""
471     ERR="false"
472 )
473 stage $GO
474
475 log "Daily cron scripts successful, all done"
476
477 exec > "$logdir/afterdinstall.log" 2>&1
478
479 GO=(
480     FUNC="renamelogfile"
481     TIME=""
482     ARGS=""
483     ERR="false"
484 )
485 stage $GO
486
487
488 # Now, at the very (successful) end of dinstall, make sure we remove
489 # our stage files, so the next dinstall run will do it all again.
490 rm -f ${stagedir}/*
491 touch "${DINSTALLEND}"