2 # No way I try to deal with a crippled sh just for POSIX foo.
4 # Copyright (C) 2009, 2010 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.
31 # make sure to only use defined variables
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)
38 # import the general variable set.
39 export SCRIPTVARS=/srv/backports-master.debian.org/dak/config/backports/vars
42 ########################################################################
44 ########################################################################
45 # common functions are "outsourced"
46 . "${configdir}/common"
48 # source the dinstall functions
49 . "${configdir}/dinstall.functions"
51 ########################################################################
52 ########################################################################
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.
59 # This should be called with the first argument being an array, with the
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.
68 # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
69 # ADDED FOR DINSTALL FEATURES!
76 STAGEFILE="${stagedir}/${FUNC}"
77 if [ -f "${STAGEFILE}" ]; then
78 stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
80 difference=$(( $unixtime - $stamptime ))
81 if [ ${difference} -ge 14400 ]; then
82 log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
84 log "Did already run ${FUNC}, not calling again..."
89 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
91 # Make sure we are always at the same place. If a function wants to be elsewhere,
95 # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
96 # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
97 # dinstall logfile. Short error mails ftw!
98 exec >> "${STAGEFILE}.log" 2>&1
100 if [ -f "${LOCK_STOP}" ]; then
101 log "${LOCK_STOP} exists, exiting immediately"
105 if [ "${error}" = "false" ]; then
110 # No matter what happened in the function, we make sure we have set -e default state back
113 # Make sure we are always at the same place.
116 # We always use the same umask. If a function wants to do different, fine, but we reset.
121 if [ -n "${TIME}" ]; then
125 # And the output goes back to the normal logfile
126 exec >> "$LOGFILE" 2>&1
128 # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
130 cat "${STAGEFILE}.log" >> "${LOGFILE}"
131 rm -f "${STAGEFILE}.log"
133 if [ -f "${LOCK_STOP}" ]; then
134 log "${LOCK_STOP} exists, exiting immediately"
139 ########################################################################
142 LOGFILE="$logdir/dinstall.log"
144 exec >> "$LOGFILE" 2>&1
146 # And now source our default config
147 . "${configdir}/dinstall.variables"
149 # Make sure we start out with a sane umask setting
152 # And use one locale, no matter what the caller has set
156 # If we did not install new packages, we dont want to run.
157 if ! [ -f "${DINSTALLPACKAGES}" ]; then
161 rm -f "${DINSTALLPACKAGES}"
163 touch "${DINSTALLSTART}"
165 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
168 lockfile -l 3600 "${LOCK_DAILY}"
170 trap cleanup EXIT TERM HUP INT QUIT
172 touch "${LOCK_BRITNEY}"
190 lockfile "$LOCK_ACCEPTED"
196 ARGS="proposedupdates"
229 TIME="generate-filelist"
237 TIME="import-keyring"
253 TIME="pkg-file-mapping"
259 state "packages/contents"
262 TIME="apt-ftparchive"
266 # Careful: When we ever go and remove this monster-long thing, we have to check the backgrounded
267 # functions before it. We no longer have a 1.5hour sync point then.
338 TIME="mirror hardlinks"
344 rm -f "$LOCK_ACCEPTED"
346 rm -f "${LOCK_DAILY}"
348 ts "locked part finished"
399 rm -f "${LOCK_BRITNEY}"
402 FUNC="cleantransactions"
410 # FUNC="aptftpcleanup"
411 # TIME="apt-ftparchive cleanup"
417 # we need to wait for the background processes before the end of dinstall
420 log "Daily cron scripts successful, all done"
422 exec > "$logdir/afterdinstall.log" 2>&1
434 # Now, at the very (successful) end of dinstall, make sure we remove
435 # our stage files, so the next dinstall run will do it all again.
437 touch "${DINSTALLEND}"