]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
701754caf722f02355d0deea8555d9df96cf89c6
[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-2012 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 set -o pipefail
31 # make sure to only use defined variables
32 set -u
33 # ERR traps should be inherited from functions too. (And command
34 # substitutions and subshells and whatnot, but for us the functions is
35 # the important part here)
36 set -E
37
38 # import the general variable set.
39 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
40 . $SCRIPTVARS
41
42 ########################################################################
43 # Functions                                                            #
44 ########################################################################
45 # common functions are "outsourced"
46 . "${configdir}/common"
47
48 # source the dinstall functions
49 . "${configdir}/dinstall.functions"
50
51 ########################################################################
52 ########################################################################
53
54 # Function to save which stage we are in, so we can restart an interrupted
55 # dinstall. Or even run actions in parallel, if we dare to, by simply
56 # backgrounding the call to this function. But that should only really be
57 # done for things we don't care much about.
58 #
59 # This should be called with the first argument being an array, with the
60 # members
61 #  - FUNC - the function name to call
62 #  - ARGS - Possible arguments to hand to the function. Can be the empty string
63 #  - TIME - The timestamp name. Can be the empty string
64 #  - ERR  - if this is the string false, then the call will be surrounded by
65 #           set +e ... set -e calls, so errors in the function do not exit
66 #           dinstall. Can be the empty string, meaning true.
67 #
68 # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
69 # ADDED FOR DINSTALL FEATURES!
70 function stage() {
71     ARGS='GO[@]'
72     local "${!ARGS}"
73
74     error=${ERR:-"true"}
75
76     ARGS=${ARGS:-""}
77     STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
78     STAGEFILE=${STAGEFILE// /_}
79     if [ -f "${STAGEFILE}" ]; then
80         stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
81         unixtime=$(date +%s)
82         difference=$(( $unixtime - $stamptime ))
83         if [ ${difference} -ge 14400 ]; then
84             log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
85         else
86             log "Did already run ${FUNC}, not calling again..."
87         fi
88         return
89     fi
90
91     debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
92
93     # Make sure we are always at the same place. If a function wants to be elsewhere,
94     # it has to cd first!
95     cd ${configdir}
96
97     # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
98     # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
99     # dinstall logfile. Short error mails ftw!
100     exec >> "${STAGEFILE}.log" 2>&1
101
102     if [ -f "${LOCK_STOP}" ]; then
103         log "${LOCK_STOP} exists, exiting immediately"
104         exit 42
105     fi
106
107     if [ "${error}" = "false" ]; then
108         set +e
109     fi
110     ${FUNC} ${ARGS}
111
112     # No matter what happened in the function, we make sure we have set -e default state back
113     set -e
114
115     # Make sure we are always at the same place.
116     cd ${configdir}
117
118     # We always use the same umask. If a function wants to do different, fine, but we reset.
119     umask 022
120
121     touch "${STAGEFILE}"
122
123     if [ -n "${TIME}" ]; then
124         ts "${TIME}"
125     fi
126
127     # And the output goes back to the normal logfile
128     exec >> "$LOGFILE" 2>&1
129
130     # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
131     # to it.
132     cat "${STAGEFILE}.log" >> "${LOGFILE}"
133     rm -f "${STAGEFILE}.log"
134
135     if [ -f "${LOCK_STOP}" ]; then
136         log "${LOCK_STOP} exists, exiting immediately"
137         exit 42
138     fi
139 }
140
141 ########################################################################
142
143 # We need logs.
144 LOGFILE="$logdir/dinstall.log"
145
146 exec >> "$LOGFILE" 2>&1
147
148 # And now source our default config
149 . "${configdir}/dinstall.variables"
150
151 # Make sure we start out with a sane umask setting
152 umask 022
153
154 # And use one locale, no matter what the caller has set
155 export LANG=C
156 export LC_ALL=C
157
158 touch "${DINSTALLSTART}"
159 ts "startup"
160 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
161 state "Startup"
162
163 lockfile -l 3600 "${LOCK_DAILY}"
164 trap onerror ERR
165 trap remove_daily_lock EXIT TERM HUP INT QUIT
166
167 touch "${LOCK_BRITNEY}"
168
169 GO=(
170     FUNC="savetimestamp"
171     TIME=""
172     ARGS=""
173     ERR="false"
174 )
175 stage $GO
176
177 GO=(
178     FUNC="qa1"
179     TIME="init"
180     ARGS=""
181     ERR="false"
182 )
183 stage $GO &
184
185 GO=(
186     FUNC="pg_timestamp"
187     TIME="pg_dump1"
188     ARGS="predinstall"
189     ERR=""
190 )
191 stage $GO
192
193 GO=(
194     FUNC="updates"
195     TIME="External Updates"
196     ARGS=""
197     ERR="false"
198 )
199 stage $GO
200
201 GO=(
202     FUNC="i18n1"
203     TIME="i18n 1"
204     ARGS=""
205     ERR="false"
206 )
207 stage $GO
208
209 lockfile "$LOCK_ACCEPTED"
210 trap remove_all_locks EXIT TERM HUP INT QUIT
211
212 GO=(
213     FUNC="punew"
214     TIME="p-u-new"
215     ARGS="stable-new"
216     ERR="false"
217 )
218 stage $GO
219
220 GO=(
221     FUNC="opunew"
222     TIME="o-p-u-new"
223     ARGS="oldstable-new"
224     ERR="false"
225 )
226 stage $GO
227
228 GO=(
229     FUNC="backports_policy"
230     TIME="backports-policy"
231     ARGS=""
232     ERR="false"
233 )
234 stage $GO
235
236 GO=(
237     FUNC="cruft"
238     TIME="cruft"
239     ARGS=""
240     ERR=""
241 )
242 stage $GO
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 stage $GO
294
295 state "dists/"
296 GO=(
297     FUNC="pdiff"
298     TIME="pdiff"
299     ARGS=""
300     ERR=""
301 )
302 stage $GO
303
304 GO=(
305     FUNC="gitpdiff"
306     TIME="gitpdiff"
307     ARGS=""
308     ERR=""
309 )
310 #stage $GO
311
312 GO=(
313     FUNC="release"
314     TIME="release files"
315     ARGS=""
316     ERR=""
317 )
318 stage $GO
319
320 GO=(
321     FUNC="dakcleanup"
322     TIME="cleanup"
323     ARGS=""
324     ERR=""
325 )
326 stage $GO
327
328 state "scripts"
329 GO=(
330     FUNC="mkmaintainers"
331     TIME="mkmaintainers"
332     ARGS=""
333     ERR=""
334 )
335 stage $GO
336
337 GO=(
338     FUNC="copyoverrides"
339     TIME="copyoverrides"
340     ARGS=""
341     ERR=""
342 )
343 stage $GO
344
345 GO=(
346     FUNC="mklslar"
347     TIME="mklslar"
348     ARGS=""
349     ERR=""
350 )
351 stage $GO
352
353 GO=(
354     FUNC="mkfilesindices"
355     TIME="mkfilesindices"
356     ARGS=""
357     ERR=""
358 )
359 stage $GO
360
361 GO=(
362     FUNC="mkchecksums"
363     TIME="mkchecksums"
364     ARGS=""
365     ERR=""
366 )
367 stage $GO
368
369 GO=(
370     FUNC="mirror"
371     TIME="mirror hardlinks"
372     ARGS=""
373     ERR=""
374 )
375 stage $GO
376
377 GO=(
378     FUNC="ddaccess"
379     TIME="ddaccessible sync"
380     ARGS=""
381     ERR="false"
382 )
383 stage $GO
384
385 remove_all_locks
386 trap - EXIT TERM HUP INT QUIT
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="pg_timestamp"
401     TIME="pg_dump2"
402     ARGS="postdinstall"
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="dm"
425     TIME=""
426     ARGS=""
427     ERR=""
428 )
429 stage $GO &
430
431 GO=(
432     FUNC="bts"
433     TIME=""
434     ARGS=""
435     ERR="false"
436 )
437 stage $GO &
438
439 GO=(
440     FUNC="mirrorpush"
441     TIME="mirrorpush"
442     ARGS=""
443     ERR="false"
444 )
445 stage $GO &
446
447 GO=(
448     FUNC="mirrorpush-backports"
449     TIME="mirrorpush-backports"
450     ARGS=""
451     ERR="false"
452 )
453 stage $GO &
454
455 GO=(
456     FUNC="i18n2"
457     TIME="i18n 2"
458     ARGS=""
459     ERR="false"
460 )
461 stage $GO &
462
463 GO=(
464     FUNC="stats"
465     TIME="stats"
466     ARGS=""
467     ERR="false"
468 )
469 stage $GO &
470
471 GO=(
472     FUNC="testingsourcelist"
473     TIME=""
474     ARGS=""
475     ERR="false"
476 )
477 stage $GO &
478
479 rm -f "${LOCK_BRITNEY}"
480
481 GO=(
482     FUNC="cleantransactions"
483     TIME=""
484     ARGS=""
485     ERR=""
486 )
487 stage $GO
488
489 # we need to wait for the background processes before the end of dinstall
490 wait
491
492 log "Daily cron scripts successful, all done"
493
494 exec > "$logdir/afterdinstall.log" 2>&1
495
496 GO=(
497     FUNC="renamelogfile"
498     TIME=""
499     ARGS=""
500     ERR="false"
501 )
502 stage $GO
503 state "all done"
504
505
506 # Now, at the very (successful) end of dinstall, make sure we remove
507 # our stage files, so the next dinstall run will do it all again.
508 rm -f ${stagedir}/*
509 touch "${DINSTALLEND}"