]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.dinstall
make args a part of stagefile
[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 # 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     ARGS=${ARGS:-""}
76     STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
77     STAGEFILE=${STAGEFILE// /_}
78     if [ -f "${STAGEFILE}" ]; then
79         stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
80         unixtime=$(date +%s)
81         difference=$(( $unixtime - $stamptime ))
82         if [ ${difference} -ge 14400 ]; then
83             log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
84         else
85             log "Did already run ${FUNC}, not calling again..."
86         fi
87         return
88     fi
89
90     debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
91
92     # Make sure we are always at the same place. If a function wants to be elsewhere,
93     # it has to cd first!
94     cd ${configdir}
95
96     # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
97     # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
98     # dinstall logfile. Short error mails ftw!
99     exec >> "${STAGEFILE}.log" 2>&1
100
101     if [ -f "${LOCK_STOP}" ]; then
102         log "${LOCK_STOP} exists, exiting immediately"
103         exit 42
104     fi
105
106     if [ "${error}" = "false" ]; then
107         set +e
108     fi
109     ${FUNC} ${ARGS}
110
111     # No matter what happened in the function, we make sure we have set -e default state back
112     set -e
113
114     # Make sure we are always at the same place.
115     cd ${configdir}
116
117     # We always use the same umask. If a function wants to do different, fine, but we reset.
118     umask 022
119
120     touch "${STAGEFILE}"
121
122     if [ -n "${TIME}" ]; then
123         ts "${TIME}"
124     fi
125
126     # And the output goes back to the normal logfile
127     exec >> "$LOGFILE" 2>&1
128
129     # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
130     # to it.
131     cat "${STAGEFILE}.log" >> "${LOGFILE}"
132     rm -f "${STAGEFILE}.log"
133
134     if [ -f "${LOCK_STOP}" ]; then
135         log "${LOCK_STOP} exists, exiting immediately"
136         exit 42
137     fi
138 }
139
140 ########################################################################
141
142 # We need logs.
143 LOGFILE="$logdir/dinstall.log"
144
145 exec >> "$LOGFILE" 2>&1
146
147 # And now source our default config
148 . "${configdir}/dinstall.variables"
149
150 # Make sure we start out with a sane umask setting
151 umask 022
152
153 # And use one locale, no matter what the caller has set
154 export LANG=C
155 export LC_ALL=C
156
157 touch "${DINSTALLSTART}"
158 ts "startup"
159 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
160 state "Startup"
161
162 lockfile -l 3600 "${LOCK_DAILY}"
163 trap onerror ERR
164 trap remove_daily_lock EXIT TERM HUP INT QUIT
165
166 touch "${LOCK_BRITNEY}"
167
168 GO=(
169     FUNC="savetimestamp"
170     TIME=""
171     ARGS=""
172     ERR="false"
173 )
174 stage $GO
175
176 GO=(
177     FUNC="qa1"
178     TIME="init"
179     ARGS=""
180     ERR="false"
181 )
182 stage $GO &
183
184 GO=(
185     FUNC="pg_timestamp"
186     TIME="pg_dump1"
187     ARGS="predinstall"
188     ERR=""
189 )
190 stage $GO
191
192 GO=(
193     FUNC="updates"
194     TIME="External Updates"
195     ARGS=""
196     ERR="false"
197 )
198 stage $GO
199
200 GO=(
201     FUNC="i18n1"
202     TIME="i18n 1"
203     ARGS=""
204     ERR="false"
205 )
206 stage $GO
207
208 lockfile "$LOCK_ACCEPTED"
209 lockfile "$LOCK_NEW"
210 trap remove_all_locks EXIT TERM HUP INT QUIT
211
212 GO=(
213     FUNC="punew"
214     TIME="p-u-new"
215     ARGS="proposedupdates"
216     ERR="false"
217 )
218 stage $GO
219
220 GO=(
221     FUNC="opunew"
222     TIME="o-p-u-new"
223     ARGS="oldproposedupdates"
224     ERR="false"
225 )
226 stage $GO
227
228 GO=(
229     FUNC="newstage"
230     TIME="newstage"
231     ARGS=""
232     ERR=""
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 GO=(
329     FUNC="buildd_dir"
330     TIME="buildd_dir"
331     ARGS=""
332     ERR=""
333 )
334 stage $GO
335
336 state "scripts"
337 GO=(
338     FUNC="mkmaintainers"
339     TIME="mkmaintainers"
340     ARGS=""
341     ERR=""
342 )
343 stage $GO
344
345 GO=(
346     FUNC="copyoverrides"
347     TIME="copyoverrides"
348     ARGS=""
349     ERR=""
350 )
351 stage $GO
352
353 GO=(
354     FUNC="mklslar"
355     TIME="mklslar"
356     ARGS=""
357     ERR=""
358 )
359 stage $GO
360
361 GO=(
362     FUNC="mkfilesindices"
363     TIME="mkfilesindices"
364     ARGS=""
365     ERR=""
366 )
367 stage $GO
368
369 GO=(
370     FUNC="mkchecksums"
371     TIME="mkchecksums"
372     ARGS=""
373     ERR=""
374 )
375 stage $GO
376
377 GO=(
378     FUNC="mirror"
379     TIME="mirror hardlinks"
380     ARGS=""
381     ERR=""
382 )
383 stage $GO
384
385 GO=(
386     FUNC="ddaccess"
387     TIME="ddaccessible sync"
388     ARGS=""
389     ERR="false"
390 )
391 stage $GO
392
393 remove_all_locks
394 trap - EXIT TERM HUP INT QUIT
395
396 ts "locked part finished"
397 state "postlock"
398
399 GO=(
400     FUNC="changelogs"
401     TIME="changelogs"
402     ARGS=""
403     ERR="false"
404 )
405 stage $GO &
406
407 GO=(
408     FUNC="pg_timestamp"
409     TIME="pg_dump2"
410     ARGS="postdinstall"
411     ERR=""
412 )
413 stage $GO
414
415 GO=(
416     FUNC="expire"
417     TIME="expire_dumps"
418     ARGS=""
419     ERR=""
420 )
421 stage $GO &
422
423 GO=(
424     FUNC="transitionsclean"
425     TIME="transitionsclean"
426     ARGS=""
427     ERR=""
428 )
429 stage $GO &
430
431 GO=(
432     FUNC="dm"
433     TIME=""
434     ARGS=""
435     ERR=""
436 )
437 stage $GO &
438
439 GO=(
440     FUNC="bts"
441     TIME=""
442     ARGS=""
443     ERR="false"
444 )
445 stage $GO &
446
447 GO=(
448     FUNC="mirrorpush"
449     TIME="mirrorpush"
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 GO=(
490     FUNC="aptftpcleanup"
491     TIME="apt-ftparchive cleanup"
492     ARGS=""
493     ERR="false"
494 )
495 #stage $GO
496
497 # we need to wait for the background processes before the end of dinstall
498 wait
499
500 log "Daily cron scripts successful, all done"
501
502 exec > "$logdir/afterdinstall.log" 2>&1
503
504 GO=(
505     FUNC="renamelogfile"
506     TIME=""
507     ARGS=""
508     ERR="false"
509 )
510 stage $GO
511 state "all done"
512
513
514 # Now, at the very (successful) end of dinstall, make sure we remove
515 # our stage files, so the next dinstall run will do it all again.
516 rm -f ${stagedir}/*
517 touch "${DINSTALLEND}"