+
+function get_archiveroot() {
+ local archivename="$1"
+ local query="SELECT path FROM archive WHERE name='${archivename}'"
+ local archiveroot="$(psql -tAc "${query}")"
+ if [[ -z ${archiveroot} ]]; then
+ echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2
+ return 1
+ fi
+ echo "${archiveroot}"
+}
+
+# Prepare the trees for buildds, then push wanna-build
+function do_buildd() {
+ if lockfile -r3 ${LOCK_DAILY}; then
+ TMPFILES="${TMPFILES} ${LOCK_DAILY}"
+ make_buildd_dir
+ wbtrigger
+ fi
+}
+
+# Cleanup policy queues
+function cleanpolicy() {
+ dak clean-suites -a backports-policy,policy
+}
+
+# Scan new packages for contents
+function scancontents() {
+ dak contents -l 10000 scan-binary
+ dak contents -l 1000 scan-source
+}
+
+function ddaccess() {
+ # Tell our dd accessible mirror to sync itself up.
+ log "Trigger dd accessible parts sync"
+ ${scriptsdir}/sync-dd dd-sync dd-sync1 dd-sync2 sync
+}
+
+
+
+########################################################################
+########################################################################
+########################################################################
+########################################################################
+
+# Function to save which stage we are in, so we can restart an interrupted
+# dinstall. Or even run actions in parallel, if we dare to, by simply
+# backgrounding the call to this function. But that should only really be
+# done for things we don't care much about.
+#
+# This should be called with the first argument being an array, with the
+# members
+# - FUNC - the function name to call
+# - ARGS - Possible arguments to hand to the function. Can be the empty string
+# - TIME - The timestamp name. Can be the empty string
+# - ERR - if this is the string false, then the call will be surrounded by
+# set +e ... set -e calls, so errors in the function do not exit
+# dinstall. Can be the empty string, meaning true.
+#
+# MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
+# ADDED FOR DINSTALL FEATURES!
+function stage() {
+ ARGS='GO[@]'
+ local "${!ARGS}"
+
+ local error=${ERR:-"true"}
+
+ ARGS=${ARGS:-""}
+
+ log "########## ${PROGRAM} BEGIN: ${FUNC} ${ARGS} ##########"
+ local STAGEFILE="${stagedir}/${FUNC}${ARGS:+_}${ARGS}"
+ STAGEFILE=${STAGEFILE// /_}
+ if [[ -f ${STAGEFILE} ]]; then
+ local stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
+ local unixtime=$(date +%s)
+ local difference=$(( unixtime - stamptime ))
+ if [[ ${difference} -ge 14400 ]]; then
+ log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
+ else
+ log "Did already run ${FUNC}, not calling again..."
+ fi
+ return
+ fi
+
+ debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
+
+ # Make sure we are always at the same place. If a function wants
+ # to be elsewhere, it has to cd first!
+ cd ${configdir}
+
+ # Now redirect the output into $STAGEFILE.log. In case it errors
+ # out somewhere our errorhandler trap can then mail the contents
+ # of $STAGEFILE.log only, instead of a whole ${PROGRAM} logfile.
+ # Short error mails ftw!
+ exec >> "${STAGEFILE}.log" 2>&1
+
+ if [[ -f ${LOCK_STOP} ]]; then
+ log "${LOCK_STOP} exists, exiting immediately"
+ exit 42
+ fi
+
+ # Do we care about trouble in the function we call?
+ if [[ ${error} == false ]]; then
+ set +e
+ fi
+ ${FUNC} ${ARGS}
+
+ # No matter what happened in the function, we make sure we have
+ # set -e default state back
+ set -e
+
+ # Make sure we are always at the same place.
+ cd ${configdir}
+
+ # We always use the same umask. If a function wants to do
+ # different, fine, but we reset.
+ umask 022
+
+ touch "${STAGEFILE}"
+
+ if [[ -n ${TIME} ]]; then
+ ts "${TIME}"
+ fi
+
+ # And the output goes back to the normal logfile
+ exec >> "${LOGFILE}" 2>&1
+
+ # Now we should make sure that we have a usable ${PROGRAM}.log, so
+ # append the $STAGEFILE.log to it.
+ if [[ ${TIMESTAMP} == true ]]; then
+ /usr/bin/ts "%b %d %H:%M:%S ${HOSTNAME} ${PROGRAM}[$$]: ${FUNC} " < "${STAGEFILE}.log"
+ else
+ cat "${STAGEFILE}.log"
+ fi
+ rm -f "${STAGEFILE}.log"
+
+ log "########## ${PROGRAM} END: ${FUNC} ##########"
+
+ if [[ -f ${LOCK_STOP} ]]; then
+ log "${LOCK_STOP} exists, exiting immediately"
+ exit 42
+ fi
+}