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