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