]> git.decadent.org.uk Git - dak.git/blob - config/debian/common
Run policy from unchecked as well as dinstall
[dak.git] / config / debian / common
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
10 # log the message using log() but then also send a mail
11 # to the address configured in MAILTO (if non-empty)
12 function log_error () {
13         log "$@"
14         if [ -z "${MAILTO}" ]; then
15                 echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}  -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
16         fi
17 }
18
19 # debug log, only output when DEBUG=1
20 function debug () {
21     if [ $DEBUG -eq 1 ]; then
22         log "$*"
23     fi
24 }
25
26 function wbtrigger() {
27     SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
28     if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
29         ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
30     fi
31     rm -f "${LOCK_BUILDD}"
32 }
33
34 # used by cron.dinstall *and* cron.unchecked.
35 function make_buildd_dir () {
36     dak manage-build-queues -a
37
38     for dist in $(ls -1 ${incoming}/dists/); do
39         # Skip project trace directory
40         if [ "${dist}x" = "projectx" ]; then continue; fi
41         cd ${incoming}/dists/${dist}
42         mkdir -p tree/${STAMP}
43         cp -al ${incoming}/dists/${dist}/buildd/. tree/${STAMP}/
44         ln -sfT tree/${STAMP} ${incoming}/dists/${dist}/current
45         find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
46     done
47
48 }
49
50 # Process (oldstable)-proposed-updates "NEW" queue
51 function punew_do() {
52     date -u -R >> REPORT
53     dak process-policy $1 | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in $1" debian-release@lists.debian.org -- -F "Debian FTP Masters" -f 
54     echo >> REPORT
55 }
56
57 # These versions used in dinstall
58 function punew() {
59     log "Doing automated p-u-new processing"
60     cd "${queuedir}/p-u-new"
61     punew_do "$1"
62 }
63
64 function opunew() {
65     log "Doing automated o-p-u-new processing"
66     cd "${queuedir}/o-p-u-new"
67     punew_do "$1"
68 }
69
70 # Do the unchecked processing, in case we have files.
71 function do_unchecked () {
72     cd $unchecked
73
74     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
75     report=$queuedir/REPORT
76     timestamp=$(date "+%Y-%m-%d %H:%M")
77     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
78
79     echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
80     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
81 }
82
83 # Do the newstage processing, in case we have files.
84 function do_newstage () {
85     cd $newstage
86
87     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
88     report=$queuedir/REPORT
89     timestamp=$(date "+%Y-%m-%d %H:%M")
90     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
91
92     echo "$timestamp": ${changes:-"Nothing to do in newstage"}  >> $report
93     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$newstage" >> $report
94 }
95
96 function sync_debbugs () {
97     # sync with debbugs
98     echo "--" >> $report
99     timestamp=$(date "+%Y-%m-%d-%H:%M")
100     mkdir -p $queuedir/bts_version_track_archive/${timestamp}
101     rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
102     rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
103     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
104     NOW=$(date +%s)
105     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
106     DIFF=$(( NOW - TSTAMP ))
107     if [ $DIFF -ge 259200 ]; then
108         log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
109     fi
110 }
111
112 function clean_debbugs () {
113     # Delete files older than 60 days
114     find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
115     # Delete empty directories
116     find $queuedir/bts_version_track_archive/ -empty -type d -delete
117 }
118
119 function reports() {
120     # Send a report on NEW/BYHAND packages
121     log "Nagging ftpteam about NEW/BYHAND packages"
122     dak queue-report | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND on $(date +%D)" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
123     # and one on crufty packages
124     log "Sending information about crufty packages"
125     dak cruft-report > $webdir/cruft-report-daily.txt
126     dak cruft-report -s experimental >> $webdir/cruft-report-daily.txt
127     cat $webdir/cruft-report-daily.txt | mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
128 }
129
130 function pg_timestamp() {
131     tsname=${1:-"unknown"}
132     log "Saving postgres transaction id for ${tsname}"
133     psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
134 }