]> git.decadent.org.uk Git - dak.git/blobdiff - config/debian/common
Add a timestamp to the cruft-report
[dak.git] / config / debian / common
old mode 100644 (file)
new mode 100755 (executable)
index a568d82..62ec9a1
@@ -4,21 +4,21 @@
 # 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} ${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}] ERROR [$$]" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ${MAILTO}
+    if [[ -z ${MAILTO} ]]; then
+        echo "$*" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@${HOSTNAME}] ERROR [$$]" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ${MAILTO}
     fi
 }
 
 # debug log, only output when DEBUG=1
 function debug () {
-    if [ $DEBUG -eq 1 ]; then
+    if [[ $DEBUG -eq 1 ]]; then
         log "$*"
     fi
 }
@@ -41,10 +41,10 @@ function gettempfile() {
 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
@@ -102,11 +102,11 @@ function make_buildd_dir () {
     dak generate-releases -a build-queues >/dev/null
 
     # Stick a last modified date in the page footer
-    echo "<p>Last updated: `date -u`</p>" > ${incoming}/web/README.html
+    echo "<p>Last updated: $(date -u)</p>" > ${incoming}/web/README.html
 
     # Tell the mirrors that we've updated
     log "Pushing static for incoming.d.o"
-    chronic /usr/local/bin/static-update-component incoming.debian.org
+    chronic /usr/local/bin/static-update-component incoming.debian.org < /dev/null
 }
 
 # Process (oldstable)-proposed-updates "NEW" queue
@@ -160,14 +160,16 @@ function do_unchecked () {
     cd $unchecked
 
     changes=$(find . -maxdepth 1 -mindepth 1 -type f \( -name \*.changes -o -name \*.dak-commands \) | sed -e "s,./,," | xargs)
-    report=$queuedir/REPORT
+    report=${queuedir}/REPORT
     timestamp=$(date "+%Y-%m-%d %H:%M")
 
-    if [ ! -z "$changes" ]; then
+    if [[ ! -z ${changes} ]]; then
         log "Processing files ${changes}"
-        echo "${timestamp}: ${changes}"  >> $report
-        dak process-upload -a -d "$unchecked" >> $report
-        dak process-commands -d "$unchecked" >> $report
+        {
+            echo "${timestamp}: ${changes}"
+            dak process-upload -a -d "$unchecked"
+            dak process-commands -d "$unchecked"
+        } >> ${report}
 
         sync_debbugs
         do_buildd
@@ -201,7 +203,7 @@ function sync_debbugs () {
     NOW=$(date +%s)
     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
     DIFF=$(( NOW - TSTAMP ))
-    if [ $DIFF -ge 259200 ]; then
+    if [[ $DIFF -ge 259200 ]]; then
         log_error "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
     fi
 }
@@ -221,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 <ftpmaster@ftp-master.debian.org>" 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>" 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>" ftpmaster@ftp-master.debian.org < $webdir/cruft-report-daily.txt
 }
 
 function pg_timestamp() {
@@ -236,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
@@ -303,11 +307,11 @@ function stage() {
     log "########## ${PROGRAM} BEGIN: ${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..."
@@ -327,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}
@@ -351,7 +355,7 @@ function stage() {
 
     touch "${STAGEFILE}"
 
-    if [ -n "${TIME}" ]; then
+    if [[ -n ${TIME} ]]; then
         ts "${TIME}"
     fi
 
@@ -369,7 +373,7 @@ function stage() {
 
     log "########## ${PROGRAM} END: ${FUNC} ##########"
 
-    if [ -f "${LOCK_STOP}" ]; then
+    if [[ -f ${LOCK_STOP} ]]; then
         log "${LOCK_STOP} exists, exiting immediately"
         exit 42
     fi