2 # No way I try to deal with a crippled sh just for POSIX foo.
4 # Copyright (C) 2009-2012 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/ftp-master.debian.org/dak/config/debian/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!
77 STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
78 STAGEFILE=${STAGEFILE// /_}
79 if [ -f "${STAGEFILE}" ]; then
80 stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
82 difference=$(( $unixtime - $stamptime ))
83 if [ ${difference} -ge 14400 ]; then
84 log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
86 log "Did already run ${FUNC}, not calling again..."
91 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
93 # Make sure we are always at the same place. If a function wants to be elsewhere,
97 # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
98 # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
99 # dinstall logfile. Short error mails ftw!
100 exec >> "${STAGEFILE}.log" 2>&1
102 if [ -f "${LOCK_STOP}" ]; then
103 log "${LOCK_STOP} exists, exiting immediately"
107 if [ "${error}" = "false" ]; then
112 # No matter what happened in the function, we make sure we have set -e default state back
115 # Make sure we are always at the same place.
118 # We always use the same umask. If a function wants to do different, fine, but we reset.
123 if [ -n "${TIME}" ]; then
127 # And the output goes back to the normal logfile
128 exec >> "$LOGFILE" 2>&1
130 # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
132 cat "${STAGEFILE}.log" >> "${LOGFILE}"
133 rm -f "${STAGEFILE}.log"
135 if [ -f "${LOCK_STOP}" ]; then
136 log "${LOCK_STOP} exists, exiting immediately"
141 ########################################################################
144 LOGFILE="$logdir/dinstall.log"
146 exec >> "$LOGFILE" 2>&1
148 # And now source our default config
149 . "${configdir}/dinstall.variables"
151 # Make sure we start out with a sane umask setting
154 # And use one locale, no matter what the caller has set
158 touch "${DINSTALLSTART}"
160 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
163 lockfile -l 3600 "${LOCK_DAILY}"
165 trap remove_daily_lock EXIT TERM HUP INT QUIT
167 touch "${LOCK_BRITNEY}"
195 TIME="External Updates"
209 lockfile "$LOCK_ACCEPTED"
210 trap remove_all_locks EXIT TERM HUP INT QUIT
229 FUNC="backports_policy"
230 TIME="backports-policy"
257 ARGS="unstable experimental"
264 TIME="import-keyring"
280 TIME="pkg-file-mapping"
286 state "packages/contents"
289 TIME="apt-ftparchive"
354 FUNC="mkfilesindices"
355 TIME="mkfilesindices"
371 TIME="mirror hardlinks"
379 TIME="ddaccessible sync"
386 trap - EXIT TERM HUP INT QUIT
388 ts "locked part finished"
416 FUNC="transitionsclean"
417 TIME="transitionsclean"
448 FUNC="mirrorpush-backports"
449 TIME="mirrorpush-backports"
472 FUNC="testingsourcelist"
479 rm -f "${LOCK_BRITNEY}"
482 FUNC="cleantransactions"
489 # we need to wait for the background processes before the end of dinstall
492 log "Daily cron scripts successful, all done"
494 exec > "$logdir/afterdinstall.log" 2>&1
506 # Now, at the very (successful) end of dinstall, make sure we remove
507 # our stage files, so the next dinstall run will do it all again.
509 touch "${DINSTALLEND}"