common 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # -*- mode:sh -*-
  2. # log something (basically echo it together with a timestamp)
  3. #
  4. # Set $PROGRAM to a string to have it added to the output.
  5. function log () {
  6. local prefix=${PROGRAM:-}
  7. echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@"
  8. }
  9. # log the message using log() but then also send a mail
  10. # to the address configured in MAILTO (if non-empty)
  11. function log_error () {
  12. log "$@"
  13. if [ -z "${MAILTO}" ]; then
  14. echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ${MAILTO}
  15. fi
  16. }
  17. # debug log, only output when DEBUG=1
  18. function debug () {
  19. if [ $DEBUG -eq 1 ]; then
  20. log "$*"
  21. fi
  22. }
  23. function wbtrigger() {
  24. SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
  25. if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
  26. ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
  27. fi
  28. rm -f "${LOCK_BUILDD}"
  29. }
  30. # used by cron.dinstall *and* cron.unchecked.
  31. function make_buildd_dir () {
  32. # We generate straight into the static mirror location for incoming
  33. dak manage-build-queues -a
  34. dak generate-packages-sources2 -a build-queues
  35. dak generate-releases -a build-queues >/dev/null
  36. # Stick a last modified date in the page footer
  37. echo "<p>Last updated: `date -u`</p>" > ${incoming}/web/README.html
  38. # Tell the mirrors that we've updated
  39. chronic /usr/local/bin/static-update-component incoming.debian.org
  40. }
  41. # Process (oldstable)-proposed-updates "NEW" queue
  42. function punew_do() {
  43. local queue="$1"
  44. local qdir="$2"
  45. local to="${3}"
  46. date -u -R >> REPORT
  47. dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" "${to}"
  48. echo >> REPORT
  49. dak generate-packages-sources2 -s "${queue}"
  50. STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
  51. local exportdir="${qdir}/tree/${STAMP}"
  52. local targetdir="${qdir}/export"
  53. mkdir -p -- ${exportdir}
  54. dak export -q "${queue}" -d "${exportdir}" --all
  55. ln -sfT ${exportdir} ${targetdir}
  56. find "${qdir}/tree" -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
  57. }
  58. # These versions used in dinstall
  59. function punew() {
  60. if [ "${PROGRAM}" = "dinstall" ]; then
  61. log "Doing automated p-u-new processing"
  62. fi
  63. cd "${queuedir}/p-u-new"
  64. punew_do "$1" "${queuedir}/p-u-new" "debian-release@lists.debian.org"
  65. }
  66. function opunew() {
  67. if [ "${PROGRAM}" = "dinstall" ]; then
  68. log "Doing automated o-p-u-new processing"
  69. fi
  70. cd "${queuedir}/o-p-u-new"
  71. punew_do "$1" "${queuedir}/o-p-u-new" "debian-release@lists.debian.org"
  72. }
  73. function backports_policy() {
  74. local queue="backports-policy"
  75. local qdir="/srv/backports-master.debian.org/queue/policy"
  76. local to="backports-team@debian.org"
  77. if [ "${PROGRAM}" = "dinstall" ]; then
  78. log "Doing automated ${queue} processing"
  79. fi
  80. cd "${qdir}"
  81. punew_do "${queue}" "${qdir}" "${to}"
  82. }
  83. # Do the unchecked processing, in case we have files.
  84. function do_unchecked () {
  85. cd $unchecked
  86. changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
  87. report=$queuedir/REPORT
  88. timestamp=$(date "+%Y-%m-%d %H:%M")
  89. UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
  90. echo "$timestamp": ${changes:-"Nothing to do"} >> $report
  91. dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
  92. dak process-commands -d "$unchecked" >> $report
  93. }
  94. # process NEW policy queue
  95. function do_new () {
  96. if [ "${PROGRAM}" = "dinstall" ]; then
  97. log "Doing NEW processing"
  98. fi
  99. (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>" ftpmaster@ftp-master.debian.org
  100. dak process-policy backports-new | mail -a "X-Debian: DAK" -e -s "NEW processing for backports-new" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" backports-team@debian.org
  101. dak clean-suites -a new,backports-new
  102. }
  103. function sync_debbugs () {
  104. # sync with debbugs
  105. echo "--" >> $report
  106. timestamp=$(date "+%Y-%m-%d-%H:%M")
  107. mkdir -p $queuedir/bts_version_track_archive/${timestamp}
  108. rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
  109. rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
  110. rsync -aq -e "ssh -o Batchmode=yes -o ConnectTimeout=30 -o SetupTimeout=30" --remove-source-files $queuedir/bts_version_track/ bugs-sync:/org/bugs.debian.org/versions/queue/ftp-master/ 2>/dev/null && touch $lockdir/synced_bts_version || true
  111. NOW=$(date +%s)
  112. TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
  113. DIFF=$(( NOW - TSTAMP ))
  114. if [ $DIFF -ge 259200 ]; then
  115. log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
  116. fi
  117. }
  118. function clean_debbugs () {
  119. # Delete files older than 60 days
  120. find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
  121. # Delete empty directories
  122. find $queuedir/bts_version_track_archive/ -empty -type d -delete
  123. }
  124. function reports() {
  125. # Send a report on NEW/BYHAND packages
  126. log "Nagging ftpteam about NEW/BYHAND packages"
  127. dak queue-report | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND on $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
  128. 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
  129. # and one on crufty packages
  130. log "Sending information about crufty packages"
  131. dak cruft-report -R > $webdir/cruft-report-daily.txt
  132. dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
  133. 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
  134. }
  135. function pg_timestamp() {
  136. tsname=${1:-"unknown"}
  137. log "Saving postgres transaction id for ${tsname}"
  138. psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
  139. }
  140. function get_archiveroot() {
  141. local archivename="$1"
  142. local query="SELECT path FROM archive WHERE name='${archivename}'"
  143. local archiveroot="$(psql -tAc "${query}")"
  144. if [ -z "${archiveroot}" ]; then
  145. echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2
  146. return 1
  147. fi
  148. echo "${archiveroot}"
  149. }