]> git.decadent.org.uk Git - dak.git/blob - config/backports/cron.dinstall
add pickle file db-metadata-0.5.2.pkl
[dak.git] / config / backports / 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, 2010 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/backports-master.debian.org/dak/config/backports/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 # If we did not install new packages, we dont want to run.
156 if ! [ -f "${DINSTALLPACKAGES}" ]; then
157     log "nothing to do"
158     exit 0
159 fi
160 rm -f "${DINSTALLPACKAGES}"
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 cleanup 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="pgdump_pre"
183     TIME="pg_dump1"
184     ARGS=""
185     ERR=""
186 )
187 stage $GO
188
189 lockfile "$LOCK_ACCEPTED"
190 lockfile "$LOCK_NEW"
191
192 GO=(
193     FUNC="newstage"
194     TIME="newstage"
195     ARGS=""
196     ERR=""
197 )
198 stage $GO
199
200 GO=(
201     FUNC="cruft"
202     TIME="cruft"
203     ARGS=""
204     ERR=""
205 )
206 stage $GO
207
208 state "indices"
209
210 GO=(
211     FUNC="dominate"
212     TIME="dominate"
213     ARGS=""
214     ERR=""
215 )
216 stage $GO
217
218 GO=(
219     FUNC="filelist"
220     TIME="generate-filelist"
221     ARGS=""
222     ERR=""
223 )
224 stage $GO
225
226 # GO=(
227 #     FUNC="fingerprints"
228 #     TIME="import-keyring"
229 #     ARGS=""
230 #     ERR="false"
231 # )
232 # stage $GO
233
234 GO=(
235     FUNC="overrides"
236     TIME="overrides"
237     ARGS=""
238     ERR=""
239 )
240 stage $GO
241
242 GO=(
243     FUNC="mpfm"
244     TIME="pkg-file-mapping"
245     ARGS=""
246     ERR="false"
247 )
248 stage $GO
249
250 state "packages/contents"
251 GO=(
252     FUNC="packages"
253     TIME="apt-ftparchive"
254     ARGS=""
255     ERR=""
256 )
257 # Careful: When we ever go and remove this monster-long thing, we have to check the backgrounded
258 # functions before it. We no longer have a 1.5hour sync point then.
259 stage $GO
260
261 state "dists/"
262 GO=(
263     FUNC="pdiff"
264     TIME="pdiff"
265     ARGS=""
266     ERR=""
267 )
268 stage $GO
269
270 GO=(
271     FUNC="release"
272     TIME="release files"
273     ARGS=""
274     ERR=""
275 )
276 stage $GO
277
278 GO=(
279     FUNC="dakcleanup"
280     TIME="cleanup"
281     ARGS=""
282     ERR=""
283 )
284 stage $GO
285
286 GO=(
287     FUNC="buildd_dir"
288     TIME="buildd_dir"
289     ARGS=""
290     ERR=""
291 )
292 stage $GO
293
294 state "scripts"
295 GO=(
296     FUNC="mkmaintainers"
297     TIME="mkmaintainers"
298     ARGS=""
299     ERR=""
300 )
301 stage $GO
302
303 GO=(
304     FUNC="mkuploaders"
305     TIME="mkuploaders"
306     ARGS=""
307     ERR=""
308 )
309 stage $GO
310
311 GO=(
312     FUNC="copyoverrides"
313     TIME="copyoverrides"
314     ARGS=""
315     ERR=""
316 )
317 stage $GO
318
319 GO=(
320     FUNC="mklslar"
321     TIME="mklslar"
322     ARGS=""
323     ERR=""
324 )
325 stage $GO
326
327 GO=(
328     FUNC="mkchecksums"
329     TIME="mkchecksums"
330     ARGS=""
331     ERR=""
332 )
333 stage $GO
334
335 GO=(
336     FUNC="mirror"
337     TIME="mirror hardlinks"
338     ARGS=""
339     ERR=""
340 )
341 stage $GO
342
343 rm -f "$LOCK_ACCEPTED"
344 rm -f "$LOCK_NEW"
345 rm -f "${LOCK_DAILY}"
346
347 ts "locked part finished"
348 state "postlock"
349
350 GO=(
351     FUNC="pgdump_post"
352     TIME="pg_dump2"
353     ARGS=""
354     ERR=""
355 )
356 stage $GO &
357
358 GO=(
359     FUNC="expire"
360     TIME="expire_dumps"
361     ARGS=""
362     ERR=""
363 )
364 stage $GO &
365
366 # GO=(
367 #     FUNC="dm"
368 #     TIME=""
369 #     ARGS=""
370 #     ERR=""
371 # )
372 # stage $GO &
373
374 GO=(
375     FUNC="mirrorpush"
376     TIME="mirrorpush"
377     ARGS=""
378     ERR="false"
379 )
380 stage $GO &
381
382 GO=(
383     FUNC="stats"
384     TIME="stats"
385     ARGS=""
386     ERR="false"
387 )
388 stage $GO &
389
390 rm -f "${LOCK_BRITNEY}"
391
392 GO=(
393     FUNC="compress"
394     TIME="compress"
395     ARGS=""
396     ERR=""
397 )
398 stage $GO &
399
400 # GO=(
401 #     FUNC="aptftpcleanup"
402 #     TIME="apt-ftparchive cleanup"
403 #     ARGS=""
404 #     ERR="false"
405 # )
406 # stage $GO
407
408 log "Daily cron scripts successful, all done"
409
410 exec > "$logdir/afterdinstall.log" 2>&1
411
412 GO=(
413     FUNC="renamelogfile"
414     TIME=""
415     ARGS=""
416     ERR="false"
417 )
418 stage $GO
419 state "all done"
420
421
422 # Now, at the very (successful) end of dinstall, make sure we remove
423 # our stage files, so the next dinstall run will do it all again.
424 rm -f ${stagedir}/*
425 touch "${DINSTALLEND}"