2 # No way I try to deal with a crippled sh just for POSIX foo.
4 # Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
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.
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.
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.
19 # Homer: Are you saying you're never going to eat any animal again? What
25 # Lisa: Dad, those all come from the same animal.
26 # Homer: Heh heh heh. Ooh, yeah, right, Lisa. A wonderful, magical animal.
30 # make sure to only use defined variables
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)
37 # import the general variable set.
38 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
41 ########################################################################
43 ########################################################################
44 # common functions are "outsourced"
45 . "${configdir}/common"
47 # source the dinstall functions
48 . "${configdir}/dinstall.functions"
50 ########################################################################
51 ########################################################################
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.
58 # This should be called with the first argument being an array, with the
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.
67 # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
68 # ADDED FOR DINSTALL FEATURES!
75 STAGEFILE="${stagedir}/${FUNC}"
76 if [ -f "${STAGEFILE}" ]; then
77 stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
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."
83 log "Did already run ${FUNC}, not calling again..."
88 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
90 # Make sure we are always at the same place. If a function wants to be elsewhere,
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
99 if [ -f "${LOCK_STOP}" ]; then
100 log "${LOCK_STOP} exists, exiting immediately"
104 if [ "${error}" = "false" ]; then
109 # No matter what happened in the function, we make sure we have set -e default state back
112 # Make sure we are always at the same place.
115 # We always use the same umask. If a function wants to do different, fine, but we reset.
120 if [ -n "${TIME}" ]; then
124 # And the output goes back to the normal logfile
125 exec >> "$LOGFILE" 2>&1
127 # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
129 cat "${STAGEFILE}.log" >> "${LOGFILE}"
130 rm -f "${STAGEFILE}.log"
132 if [ -f "${LOCK_STOP}" ]; then
133 log "${LOCK_STOP} exists, exiting immediately"
138 ########################################################################
141 LOGFILE="$logdir/dinstall.log"
143 exec >> "$LOGFILE" 2>&1
145 # And now source our default config
146 . "${configdir}/dinstall.variables"
148 # Make sure we start out with a sane umask setting
151 # And use one locale, no matter what the caller has set
155 touch "${DINSTALLSTART}"
157 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
160 lockfile -l 3600 "${LOCK_DAILY}"
162 trap cleanup EXIT TERM HUP INT QUIT
164 touch "${LOCK_BRITNEY}"
192 TIME="External Updates"
206 lockfile "$LOCK_ACCEPTED"
212 ARGS="proposedupdates"
220 # ARGS="oldproposedupdates"
253 TIME="generate-filelist"
261 TIME="import-keyring"
277 TIME="pkg-file-mapping"
283 state "packages/contents"
286 TIME="apt-ftparchive"
290 # Careful: When we ever go and remove this monster-long thing, we have to check the backgrounded
291 # functions before it. We no longer have a 1.5hour sync point then.
361 FUNC="mkfilesindices"
362 TIME="mkfilesindices"
378 TIME="mirror hardlinks"
384 rm -f "$LOCK_ACCEPTED"
386 rm -f "${LOCK_DAILY}"
388 ts "locked part finished"
408 FUNC="transitionsclean"
409 TIME="transitionsclean"
441 TIME="merkel projectb push"
472 FUNC="testingsourcelist"
479 rm -f "${LOCK_BRITNEY}"
491 TIME="merkel ddaccessible sync"
507 TIME="apt-ftparchive cleanup"
513 log "Daily cron scripts successful, all done"
515 exec > "$logdir/afterdinstall.log" 2>&1
527 # Now, at the very (successful) end of dinstall, make sure we remove
528 # our stage files, so the next dinstall run will do it all again.
530 touch "${DINSTALLEND}"