X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=config%2Fdebian%2Fcommon;h=62ec9a1ed8f47d08dd3959b9f56a50b0fb482359;hb=c10e027383c48f1be6e431de2f316d70c2ca2292;hp=c9363bc8d1f294669533cbabf312e53a17fb3059;hpb=32063f01897651692754f8a2a0f189fa7c1f3c64;p=dak.git diff --git a/config/debian/common b/config/debian/common old mode 100644 new mode 100755 index c9363bc8..62ec9a1e --- a/config/debian/common +++ b/config/debian/common @@ -4,34 +4,47 @@ # Set $PROGRAM to a string to have it added to the output. function log () { local prefix=${PROGRAM:-} - echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@" + echo "$(date +"%b %d %H:%M:%S") ${HOSTNAME} ${prefix}[$$]: $*" } # log the message using log() but then also send a mail # to the address configured in MAILTO (if non-empty) function log_error () { log "$@" - if [ -z "${MAILTO}" ]; then - echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" -a "From: Debian FTP Masters " ${MAILTO} + if [[ -z ${MAILTO} ]]; then + echo "$*" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@${HOSTNAME}] ERROR [$$]" -a "From: Debian FTP Masters " ${MAILTO} fi } # debug log, only output when DEBUG=1 function debug () { - if [ $DEBUG -eq 1 ]; then + if [[ $DEBUG -eq 1 ]]; then log "$*" fi } +# Get a tempfile, add it to the right variable to get rid of it, +# and return it +function gettempfile() { + local MAKEDIR=${1:-false} + local TMPARGS="" + if [[ ${MAKEDIR} == true ]]; then + TMPARGS="--directory" + fi + local TMPFILE=$( mktemp -p ${TMPDIR} ${TMPARGS} ) + TMPFILES="${TEMPFILES} ${TMPFILE}" + echo "${TMPFILE}" +} + # Function that only cleans tempfiles, but does not exit or otherwise # care about any exit status function cleantempfiles() { resolvetmpfiles for TEMPFILE in $TMPFILES; do - if [ -n "${TEMPFILE}" ] && [ -f "${TEMPFILE}" ]; then + if [[ -n ${TEMPFILE} ]] && [[ -f ${TEMPFILE} ]]; then rm -f "${TEMPFILE}" - elif [ -n "${TEMPFILE}" ] && [ -d "${TEMPFILE}" ]; then - if [ "${TEMPFILE}" != "/" ] && [ "${TEMPFILE}" != "/*" ]; then + elif [[ -n ${TEMPFILE} ]] && [[ -d ${TEMPFILE} ]]; then + if [[ ${TEMPFILE} != / ]] && [[ ${TEMPFILE} != /* ]]; then rm -rf "${TEMPFILE}" fi fi @@ -83,15 +96,17 @@ function wbtrigger() { # used by cron.dinstall *and* cron.unchecked. function make_buildd_dir () { # We generate straight into the static mirror location for incoming + log "Preparing buildd area" dak manage-build-queues -a dak generate-packages-sources2 -a build-queues dak generate-releases -a build-queues >/dev/null # Stick a last modified date in the page footer - echo "

Last updated: `date -u`

" > ${incoming}/web/README.html + echo "

Last updated: $(date -u)

" > ${incoming}/web/README.html # Tell the mirrors that we've updated - chronic /usr/local/bin/static-update-component incoming.debian.org + log "Pushing static for incoming.d.o" + chronic /usr/local/bin/static-update-component incoming.debian.org < /dev/null } # Process (oldstable)-proposed-updates "NEW" queue @@ -144,18 +159,23 @@ function backports_policy() { function do_unchecked () { cd $unchecked - changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs) - report=$queuedir/REPORT + changes=$(find . -maxdepth 1 -mindepth 1 -type f \( -name \*.changes -o -name \*.dak-commands \) | sed -e "s,./,," | xargs) + report=${queuedir}/REPORT timestamp=$(date "+%Y-%m-%d %H:%M") - UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""} - echo "$timestamp": ${changes:-"Nothing to do"} >> $report - dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report - dak process-commands -d "$unchecked" >> $report + if [[ ! -z ${changes} ]]; then + log "Processing files ${changes}" + { + echo "${timestamp}: ${changes}" + dak process-upload -a -d "$unchecked" + dak process-commands -d "$unchecked" + } >> ${report} - if [ ! -z "$changes" ]; then sync_debbugs do_buildd + else + log "Nothing to do" + echo "Nothing to do" >> ${report} fi } @@ -164,13 +184,16 @@ function do_new () { log "Doing NEW processing" (dak process-policy new; dak process-policy byhand) | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND processing" -a "From: Debian FTP Masters " ftpmaster@ftp-master.debian.org + log "Processing Backports NEW" dak process-policy backports-new | mail -a "X-Debian: DAK" -e -s "NEW processing for backports-new" -a "From: Debian FTP Masters " backports-team@debian.org + log "Cleanup NEW/Backports NEW" dak clean-suites -a new,backports-new } function sync_debbugs () { # sync with debbugs + log "Sync debbugs version tracking information" echo "--" >> $report timestamp=$(date "+%Y-%m-%d-%H:%M") mkdir -p $queuedir/bts_version_track_archive/${timestamp} @@ -180,12 +203,13 @@ function sync_debbugs () { NOW=$(date +%s) TSTAMP=$(stat -c %Y $lockdir/synced_bts_version) DIFF=$(( NOW - TSTAMP )) - if [ $DIFF -ge 259200 ]; then - log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)" + if [[ $DIFF -ge 259200 ]]; then + log_error "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)" fi } function clean_debbugs () { + log "Cleanup debbugs" # Delete files older than 60 days find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete # Delete empty directories @@ -199,9 +223,11 @@ function reports() { dak queue-report -d backports-new,backports-policy | mail -a "X-Debian: DAK" -e -s "NEW and POLICY on $(date +%D)" -a "From: Debian FTP Masters " backports-team@debian.org # and one on crufty packages log "Sending information about crufty packages" - dak cruft-report -R > $webdir/cruft-report-daily.txt - dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt - cat $webdir/cruft-report-daily.txt | mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" -a "From: Debian FTP Masters " ftpmaster@ftp-master.debian.org + dak cruft-report -R > $webdir/cruft-report-daily.txt.new + dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt.new + echo "Page generated on $(date -u)" >> $webdir/cruft-report-daily.txt.new + mv $webdir/cruft-report-daily.txt.new $webdir/cruft-report-daily.txt + mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" -a "From: Debian FTP Masters " ftpmaster@ftp-master.debian.org < $webdir/cruft-report-daily.txt } function pg_timestamp() { @@ -214,7 +240,7 @@ function get_archiveroot() { local archivename="$1" local query="SELECT path FROM archive WHERE name='${archivename}'" local archiveroot="$(psql -tAc "${query}")" - if [ -z "${archiveroot}" ]; then + if [[ -z ${archiveroot} ]]; then echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2 return 1 fi @@ -242,8 +268,8 @@ function scancontents() { } function ddaccess() { - # Tell our dd accessible mirror to sync itself up. Including ftp dir. - log "Trigger dd accessible parts sync including ftp dir" + # 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 } @@ -279,13 +305,13 @@ function stage() { ARGS=${ARGS:-""} log "########## ${PROGRAM} BEGIN: ${FUNC} ${ARGS} ##########" - local STAGEFILE="${stagedir}/${FUNC}_${ARGS}" + local STAGEFILE="${stagedir}/${FUNC}${ARGS:+_}${ARGS}" STAGEFILE=${STAGEFILE// /_} - if [ -f "${STAGEFILE}" ]; then + 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 + 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..." @@ -305,13 +331,13 @@ function stage() { # Short error mails ftw! exec >> "${STAGEFILE}.log" 2>&1 - if [ -f "${LOCK_STOP}" ]; then + 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 + if [[ ${error} == false ]]; then set +e fi ${FUNC} ${ARGS} @@ -329,7 +355,7 @@ function stage() { touch "${STAGEFILE}" - if [ -n "${TIME}" ]; then + if [[ -n ${TIME} ]]; then ts "${TIME}" fi @@ -338,12 +364,16 @@ function stage() { # Now we should make sure that we have a usable ${PROGRAM}.log, so # append the $STAGEFILE.log to it. - cat "${STAGEFILE}.log" >> "${LOGFILE}" + 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 + if [[ -f ${LOCK_STOP} ]]; then log "${LOCK_STOP} exists, exiting immediately" exit 42 fi