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