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.
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!
76 STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
77 STAGEFILE=${STAGEFILE// /_}
78 if [ -f "${STAGEFILE}" ]; then
79 stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
81 difference=$(( $unixtime - $stamptime ))
82 if [ ${difference} -ge 14400 ]; then
83 log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
85 log "Did already run ${FUNC}, not calling again..."
90 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
92 # Make sure we are always at the same place. If a function wants to be elsewhere,
96 # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
97 # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
98 # dinstall logfile. Short error mails ftw!
99 exec >> "${STAGEFILE}.log" 2>&1
101 if [ -f "${LOCK_STOP}" ]; then
102 log "${LOCK_STOP} exists, exiting immediately"
106 if [ "${error}" = "false" ]; then
111 # No matter what happened in the function, we make sure we have set -e default state back
114 # Make sure we are always at the same place.
117 # We always use the same umask. If a function wants to do different, fine, but we reset.
122 if [ -n "${TIME}" ]; then
126 # And the output goes back to the normal logfile
127 exec >> "$LOGFILE" 2>&1
129 # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
131 cat "${STAGEFILE}.log" >> "${LOGFILE}"
132 rm -f "${STAGEFILE}.log"
134 if [ -f "${LOCK_STOP}" ]; then
135 log "${LOCK_STOP} exists, exiting immediately"
140 ########################################################################
143 LOGFILE="$logdir/dinstall.log"
145 exec >> "$LOGFILE" 2>&1
147 # And now source our default config
148 . "${configdir}/dinstall.variables"
150 # Make sure we start out with a sane umask setting
153 # And use one locale, no matter what the caller has set
157 touch "${DINSTALLSTART}"
159 DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
162 lockfile -l 3600 "${LOCK_DAILY}"
164 trap remove_daily_lock EXIT TERM HUP INT QUIT
166 touch "${LOCK_BRITNEY}"
194 TIME="External Updates"
208 lockfile "$LOCK_ACCEPTED"
210 trap remove_all_locks EXIT TERM HUP INT QUIT
215 ARGS="proposedupdates"
223 ARGS="oldproposedupdates"
256 TIME="generate-filelist"
264 TIME="import-keyring"
280 TIME="pkg-file-mapping"
286 state "packages/contents"
289 TIME="apt-ftparchive"
362 FUNC="mkfilesindices"
363 TIME="mkfilesindices"
379 TIME="mirror hardlinks"
387 TIME="ddaccessible sync"
394 trap - EXIT TERM HUP INT QUIT
396 ts "locked part finished"
424 FUNC="transitionsclean"
425 TIME="transitionsclean"
472 FUNC="testingsourcelist"
479 rm -f "${LOCK_BRITNEY}"
482 FUNC="cleantransactions"
491 TIME="apt-ftparchive cleanup"
497 # we need to wait for the background processes before the end of dinstall
500 log "Daily cron scripts successful, all done"
502 exec > "$logdir/afterdinstall.log" 2>&1
514 # Now, at the very (successful) end of dinstall, make sure we remove
515 # our stage files, so the next dinstall run will do it all again.
517 touch "${DINSTALLEND}"