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!
78 log "########## DINSTALL BEGIN: ${FUNC} ${ARGS} ##########"
79 STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
80 STAGEFILE=${STAGEFILE// /_}
81 if [ -f "${STAGEFILE}" ]; then
82 stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
84 difference=$(( $unixtime - $stamptime ))
85 if [ ${difference} -ge 14400 ]; then
86 log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
88 log "Did already run ${FUNC}, not calling again..."
93 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
95 # Make sure we are always at the same place. If a function wants to be elsewhere,
99 # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
100 # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
101 # dinstall logfile. Short error mails ftw!
102 exec >> "${STAGEFILE}.log" 2>&1
104 if [ -f "${LOCK_STOP}" ]; then
105 log "${LOCK_STOP} exists, exiting immediately"
109 if [ "${error}" = "false" ]; then
114 # No matter what happened in the function, we make sure we have set -e default state back
117 # Make sure we are always at the same place.
120 # We always use the same umask. If a function wants to do different, fine, but we reset.
125 if [ -n "${TIME}" ]; then
129 # And the output goes back to the normal logfile
130 exec >> "$LOGFILE" 2>&1
132 # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
134 cat "${STAGEFILE}.log" >> "${LOGFILE}"
135 rm -f "${STAGEFILE}.log"
137 echo "########## DINSTALL END: ${FUNC} ##########"
139 if [ -f "${LOCK_STOP}" ]; then
140 log "${LOCK_STOP} exists, exiting immediately"
145 ########################################################################
148 LOGFILE="$logdir/dinstall.log"
150 exec >> "$LOGFILE" 2>&1
152 # And now source our default config
153 . "${configdir}/dinstall.variables"
155 # Make sure we start out with a sane umask setting
158 # And use one locale, no matter what the caller has set
162 touch "${DINSTALLSTART}"
164 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
167 lockfile -l 3600 "${LOCK_DAILY}"
169 trap remove_daily_lock EXIT TERM HUP INT QUIT
171 touch "${LOCK_BRITNEY}"
199 TIME="External Updates"
213 lockfile "$LOCK_ACCEPTED"
214 trap remove_all_locks EXIT TERM HUP INT QUIT
233 FUNC="backports_policy"
234 TIME="backports-policy"
261 ARGS="unstable experimental"
268 TIME="import-keyring"
284 TIME="pkg-file-mapping"
290 state "packages/contents"
293 TIME="apt-ftparchive"
358 FUNC="mkfilesindices"
359 TIME="mkfilesindices"
375 TIME="mirror hardlinks"
383 TIME="ddaccessible sync"
390 trap - EXIT TERM HUP INT QUIT
392 ts "locked part finished"
420 FUNC="transitionsclean"
421 TIME="transitionsclean"
452 FUNC="mirrorpush-backports"
453 TIME="mirrorpush-backports"
476 FUNC="testingsourcelist"
483 rm -f "${LOCK_BRITNEY}"
486 FUNC="cleantransactions"
493 # we need to wait for the background processes before the end of dinstall
496 log "Daily cron scripts successful, all done"
498 exec > "$logdir/afterdinstall.log" 2>&1
510 # Now, at the very (successful) end of dinstall, make sure we remove
511 # our stage files, so the next dinstall run will do it all again.
513 touch "${DINSTALLEND}"