]> git.donarmstrong.com Git - dak.git/blob - config/debian/common
merge from ftp-master
[dak.git] / config / debian / common
1 # log something (basically echo it together with a timestamp)
2 #
3 # Set $PROGRAM to a string to have it added to the output.
4 function log () {
5         if [ -z "${PROGRAM}" ]; then
6                 echo "$(date +"%b %d %H:%M:%S") $(hostname -s) [$$] $@"
7         else
8                 echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${PROGRAM}[$$]: $@"
9         fi
10 }
11
12 # log the message using log() but then also send a mail
13 # to the address configured in MAILTO (if non-empty)
14 function log_error () {
15         log "$@"
16         if [ -z "${MAILTO}" ]; then
17                 echo "$@" | mail -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}
18         fi
19 }
20
21 # debug log, only output when DEBUG=1
22 function debug () {
23     if [ $DEBUG -eq 1 ]; then
24         log "$*"
25     fi
26 }
27
28 function wbtrigger() {
29     MODE=${1:-"often"}
30     SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
31     if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
32         if [ "x${MODE}x" = "xdailyx" ]; then
33             ssh ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.daily || echo "W-B trigger.daily failed" | mail -s "W-B Daily trigger failed" ftpmaster@ftp-master.debian.org
34         elif [ "x${MODE}x" = "xoftenx" ]; then
35             ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
36         else
37             log_error "Unknown wb trigger mode called"
38         fi
39     fi
40     rm -f "${LOCK_BUILDD}"
41 }
42
43 # used by cron.dinstall *and* cron.unchecked.
44 function make_buildd_dir () {
45     dak manage-build-queues -a
46
47     cd ${incoming}
48     mkdir -p tree/${STAMP}
49     cp -al ${incoming}/buildd/. tree/${STAMP}/
50     ln -sfT tree/${STAMP} ${incoming}/builddweb
51     find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
52
53     for dist in experimental
54     do
55         cd ${incoming}/dists/${dist}
56         mkdir -p tree/${STAMP}
57         cp -al ${incoming}/dists/${dist}/buildd/. tree/${STAMP}/
58         ln -sfT tree/${STAMP} ${incoming}/dists/${dist}/current
59         find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
60     done
61 }
62
63 # Do the unchecked processing, in case we have files.
64 function do_unchecked () {
65     cd $unchecked
66
67     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
68     report=$queuedir/REPORT
69     timestamp=$(date "+%Y-%m-%d %H:%M")
70     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
71
72     echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
73     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
74 }
75
76 # Do the newstage processing, in case we have files.
77 function do_newstage () {
78     cd $newstage
79
80     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
81     report=$queuedir/REPORT
82     timestamp=$(date "+%Y-%m-%d %H:%M")
83     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
84
85     echo "$timestamp": ${changes:-"Nothing to do in newstage"}  >> $report
86     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$newstage" >> $report
87 }
88
89 function sync_debbugs () {
90     # sync with debbugs
91     echo "--" >> $report
92     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
93     NOW=$(date +%s)
94     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
95     DIFF=$(( NOW - TSTAMP ))
96     if [ $DIFF -ge 259200 ]; then
97         log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
98     fi
99 }