]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
4e8c1f2849bc73f1c42e12560710f1f311ed5277
[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
78     log "########## DINSTALL BEGIN: ${FUNC} ${ARGS} ##########"
79     STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
80     STAGEFILE=${STAGEFILE// /_}
81     if [ -f "${STAGEFILE}" ]; then
82         stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
83         unixtime=$(date +%s)
84         difference=$(( $unixtime - $stamptime ))
85         if [ ${difference} -ge 14400 ]; then
86             log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
87         else
88             log "Did already run ${FUNC}, not calling again..."
89         fi
90         return
91     fi
92
93     debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
94
95     # Make sure we are always at the same place. If a function wants to be elsewhere,
96     # it has to cd first!
97     cd ${configdir}
98
99     # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
100     # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
101     # dinstall logfile. Short error mails ftw!
102     exec >> "${STAGEFILE}.log" 2>&1
103
104     if [ -f "${LOCK_STOP}" ]; then
105         log "${LOCK_STOP} exists, exiting immediately"
106         exit 42
107     fi
108
109     if [ "${error}" = "false" ]; then
110         set +e
111     fi
112     ${FUNC} ${ARGS}
113
114     # No matter what happened in the function, we make sure we have set -e default state back
115     set -e
116
117     # Make sure we are always at the same place.
118     cd ${configdir}
119
120     # We always use the same umask. If a function wants to do different, fine, but we reset.
121     umask 022
122
123     touch "${STAGEFILE}"
124
125     if [ -n "${TIME}" ]; then
126         ts "${TIME}"
127     fi
128
129     # And the output goes back to the normal logfile
130     exec >> "$LOGFILE" 2>&1
131
132     # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
133     # to it.
134     cat "${STAGEFILE}.log" >> "${LOGFILE}"
135     rm -f "${STAGEFILE}.log"
136
137     echo "########## DINSTALL END: ${FUNC} ##########"
138
139     if [ -f "${LOCK_STOP}" ]; then
140         log "${LOCK_STOP} exists, exiting immediately"
141         exit 42
142     fi
143 }
144
145 ########################################################################
146
147 # We need logs.
148 LOGFILE="$logdir/dinstall.log"
149
150 exec >> "$LOGFILE" 2>&1
151
152 # And now source our default config
153 . "${configdir}/dinstall.variables"
154
155 # Make sure we start out with a sane umask setting
156 umask 022
157
158 # And use one locale, no matter what the caller has set
159 export LANG=C
160 export LC_ALL=C
161
162 touch "${DINSTALLSTART}"
163 ts "startup"
164 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
165 state "Startup"
166
167 lockfile -l 3600 "${LOCK_DAILY}"
168 trap onerror ERR
169 trap remove_daily_lock EXIT TERM HUP INT QUIT
170
171 touch "${LOCK_BRITNEY}"
172
173 GO=(
174     FUNC="savetimestamp"
175     TIME=""
176     ARGS=""
177     ERR="false"
178 )
179 stage $GO
180
181 GO=(
182     FUNC="qa1"
183     TIME="init"
184     ARGS=""
185     ERR="false"
186 )
187 stage $GO &
188
189 GO=(
190     FUNC="pg_timestamp"
191     TIME="pg_dump1"
192     ARGS="predinstall"
193     ERR=""
194 )
195 stage $GO
196
197 GO=(
198     FUNC="updates"
199     TIME="External Updates"
200     ARGS=""
201     ERR="false"
202 )
203 stage $GO
204
205 GO=(
206     FUNC="i18n1"
207     TIME="i18n 1"
208     ARGS=""
209     ERR="false"
210 )
211 stage $GO
212
213 lockfile "$LOCK_ACCEPTED"
214 trap remove_all_locks EXIT TERM HUP INT QUIT
215
216 GO=(
217     FUNC="punew"
218     TIME="p-u-new"
219     ARGS="stable-new"
220     ERR="false"
221 )
222 stage $GO
223
224 GO=(
225     FUNC="opunew"
226     TIME="o-p-u-new"
227     ARGS="oldstable-new"
228     ERR="false"
229 )
230 stage $GO
231
232 GO=(
233     FUNC="backports_policy"
234     TIME="backports-policy"
235     ARGS=""
236     ERR="false"
237 )
238 stage $GO
239
240 GO=(
241     FUNC="cruft"
242     TIME="cruft"
243     ARGS=""
244     ERR=""
245 )
246 stage $GO
247
248 state "indices"
249
250 GO=(
251     FUNC="dominate"
252     TIME="dominate"
253     ARGS=""
254     ERR=""
255 )
256 stage $GO
257
258 GO=(
259     FUNC="autocruft"
260     TIME="autocruft"
261     ARGS="unstable experimental"
262     ERR=""
263 )
264 stage $GO
265
266 GO=(
267     FUNC="fingerprints"
268     TIME="import-keyring"
269     ARGS=""
270     ERR="false"
271 )
272 stage $GO
273
274 GO=(
275     FUNC="overrides"
276     TIME="overrides"
277     ARGS=""
278     ERR=""
279 )
280 stage $GO
281
282 GO=(
283     FUNC="mpfm"
284     TIME="pkg-file-mapping"
285     ARGS=""
286     ERR="false"
287 )
288 stage $GO
289
290 state "packages/contents"
291 GO=(
292     FUNC="packages"
293     TIME="apt-ftparchive"
294     ARGS=""
295     ERR=""
296 )
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="gitpdiff"
310     TIME="gitpdiff"
311     ARGS=""
312     ERR=""
313 )
314 #stage $GO
315
316 GO=(
317     FUNC="release"
318     TIME="release files"
319     ARGS=""
320     ERR=""
321 )
322 stage $GO
323
324 GO=(
325     FUNC="dakcleanup"
326     TIME="cleanup"
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 GO=(
382     FUNC="ddaccess"
383     TIME="ddaccessible sync"
384     ARGS=""
385     ERR="false"
386 )
387 stage $GO
388
389 remove_all_locks
390 trap - EXIT TERM HUP INT QUIT
391
392 ts "locked part finished"
393 state "postlock"
394
395 GO=(
396     FUNC="changelogs"
397     TIME="changelogs"
398     ARGS=""
399     ERR="false"
400 )
401 stage $GO &
402
403 GO=(
404     FUNC="pg_timestamp"
405     TIME="pg_dump2"
406     ARGS="postdinstall"
407     ERR=""
408 )
409 stage $GO
410
411 GO=(
412     FUNC="expire"
413     TIME="expire_dumps"
414     ARGS=""
415     ERR=""
416 )
417 stage $GO &
418
419 GO=(
420     FUNC="transitionsclean"
421     TIME="transitionsclean"
422     ARGS=""
423     ERR=""
424 )
425 stage $GO &
426
427 GO=(
428     FUNC="dm"
429     TIME=""
430     ARGS=""
431     ERR=""
432 )
433 stage $GO &
434
435 GO=(
436     FUNC="bts"
437     TIME=""
438     ARGS=""
439     ERR="false"
440 )
441 stage $GO &
442
443 GO=(
444     FUNC="mirrorpush"
445     TIME="mirrorpush"
446     ARGS=""
447     ERR="false"
448 )
449 stage $GO &
450
451 GO=(
452     FUNC="mirrorpush-backports"
453     TIME="mirrorpush-backports"
454     ARGS=""
455     ERR="false"
456 )
457 stage $GO &
458
459 GO=(
460     FUNC="i18n2"
461     TIME="i18n 2"
462     ARGS=""
463     ERR="false"
464 )
465 stage $GO &
466
467 GO=(
468     FUNC="stats"
469     TIME="stats"
470     ARGS=""
471     ERR="false"
472 )
473 stage $GO &
474
475 GO=(
476     FUNC="testingsourcelist"
477     TIME=""
478     ARGS=""
479     ERR="false"
480 )
481 stage $GO &
482
483 rm -f "${LOCK_BRITNEY}"
484
485 GO=(
486     FUNC="cleantransactions"
487     TIME=""
488     ARGS=""
489     ERR=""
490 )
491 stage $GO
492
493 # we need to wait for the background processes before the end of dinstall
494 wait
495
496 log "Daily cron scripts successful, all done"
497
498 exec > "$logdir/afterdinstall.log" 2>&1
499
500 GO=(
501     FUNC="renamelogfile"
502     TIME=""
503     ARGS=""
504     ERR="false"
505 )
506 stage $GO
507 state "all done"
508
509
510 # Now, at the very (successful) end of dinstall, make sure we remove
511 # our stage files, so the next dinstall run will do it all again.
512 rm -f ${stagedir}/*
513 touch "${DINSTALLEND}"