]> git.decadent.org.uk Git - dak.git/blob - config/debian/common
Export buildd queues to public location
[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     dak generate-packages-sources2 -a build-queues
38     dak generate-releases -a build-queues >/dev/null
39     ${scriptdir}/update-buildd-archive ${base}/build-queues ${incoming}/debian-buildd
40
41     for suite in unstable experimental; do
42         rm -rf "$incoming/dists/$suite/buildd"
43         dak export-suite -s "buildd-$suite" -d "$incoming/dists/$suite/buildd"
44     done
45     rm -f ${incoming}/public/*
46     dak export-suite -s "accepted" -d "$incoming/public"
47
48     # export to old build queue directories
49     # XXX: Remove once the buildds use the version generated above.
50     for suite in $(ls -1 $incoming/dists/); do
51         # Skip project trace directory
52         if [ "${suite}x" = "projectx" ]; then continue; fi
53         cd ${incoming}/dists/${suite}/buildd
54
55         apt-ftparchive packages . $overridedir/override.sid.all3 >Packages
56         gzip -9c --rsyncable <Packages >Packages.gz
57         apt-ftparchive sources . $overridedir/override.sid.all3 >Sources
58         gzip -9c --rsyncable <Sources >Sources.gz
59
60         rm -f buildd/Release
61         cd ..
62         apt-ftparchive -qq -o APT::FTPArchive::Release::Origin="Debian" -o APT::FTPArchive::Release::Label="Debian" -o APT::FTPArchive::Release::Description="buildd $suite incoming" -o APT::FTPArchive::Release::Architectures="$archs" release buildd >Release
63         if [ "$suite" = "experimental" ]; then
64             echo "NotAutomatic: yes" >>Release
65         fi
66
67         gpg --secret-keyring /srv/ftp-master.debian.org/s3kr1t/dot-gnupg/secring.gpg --keyring /srv/ftp-master.debian.org/s3kr1t/dot-gnupg/pubring.gpg --no-options --batch --no-tty --armour --default-key 473041FA --detach-sign -o Release.gpg Release
68
69         mv Release Release.gpg buildd/
70     done
71
72     STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
73
74     for dist in $(ls -1 ${incoming}/dists/); do
75         # Skip project trace directory
76         if [ "${dist}x" = "projectx" ]; then continue; fi
77         cd ${incoming}/dists/${dist}
78         mkdir -p tree/${STAMP}
79         cp -al ${incoming}/dists/${dist}/buildd/. tree/${STAMP}/
80         ln -sfT tree/${STAMP} ${incoming}/dists/${dist}/current
81         find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
82     done
83 }
84
85 # Process (oldstable)-proposed-updates "NEW" queue
86 function punew_do() {
87     local queue="$1"
88     local qdir="$2"
89     date -u -R >> REPORT
90     dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" debian-release@lists.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
91     echo >> REPORT
92
93     dak generate-packages-sources2 -s "${queue}"
94
95     STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
96
97     local exportdir="${queuedir}${qdir}/tree/${STAMP}"
98     local targetdir="${queuedir}${qdir}/export"
99     dak export -q "${queue}" -d "${exportdir}" --all
100     ln -sfT ${exportdir} ${targetdir}
101     find ${queuedir}${qdir}/tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
102 }
103
104 # These versions used in dinstall
105 function punew() {
106     if [ "${PROGRAM}" = "dinstall" ]; then
107         log "Doing automated p-u-new processing"
108     fi
109     cd "${queuedir}/p-u-new"
110     punew_do "$1" "p-u-new"
111 }
112
113 function opunew() {
114     if [ "${PROGRAM}" = "dinstall" ]; then
115         log "Doing automated o-p-u-new processing"
116     fi
117     cd "${queuedir}/o-p-u-new"
118     punew_do "$1" "o-p-u-new"
119 }
120
121 # Do the unchecked processing, in case we have files.
122 function do_unchecked () {
123     cd $unchecked
124
125     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
126     report=$queuedir/REPORT
127     timestamp=$(date "+%Y-%m-%d %H:%M")
128     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
129
130     echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
131     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
132     dak process-commands -d "$unchecked" >> $report
133 }
134
135 # process NEW policy queue
136 function do_new () {
137     if [ "${PROGRAM}" = "dinstall" ]; then
138         log "Doing NEW processing"
139     fi
140     (dak process-policy new; dak process-policy byhand) | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND processing" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
141     dak clean-suites -a new
142 }
143
144 function sync_debbugs () {
145     # sync with debbugs
146     echo "--" >> $report
147     timestamp=$(date "+%Y-%m-%d-%H:%M")
148     mkdir -p $queuedir/bts_version_track_archive/${timestamp}
149     rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
150     rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
151     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
152     NOW=$(date +%s)
153     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
154     DIFF=$(( NOW - TSTAMP ))
155     if [ $DIFF -ge 259200 ]; then
156         log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
157     fi
158 }
159
160 function clean_debbugs () {
161     # Delete files older than 60 days
162     find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
163     # Delete empty directories
164     find $queuedir/bts_version_track_archive/ -empty -type d -delete
165 }
166
167 function reports() {
168     # Send a report on NEW/BYHAND packages
169     log "Nagging ftpteam about NEW/BYHAND packages"
170     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
171     # and one on crufty packages
172     log "Sending information about crufty packages"
173     dak cruft-report -R > $webdir/cruft-report-daily.txt
174     dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
175     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
176 }
177
178 function pg_timestamp() {
179     tsname=${1:-"unknown"}
180     log "Saving postgres transaction id for ${tsname}"
181     psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
182 }