]> git.decadent.org.uk Git - dak.git/blob - config/debian/dinstall.functions
Name it newstage
[dak.git] / config / debian / dinstall.functions
1 # Timestamp. Used for dinstall stat graphs
2 function ts() {
3         echo "Archive maintenance timestamp ($1): $(date +%H:%M:%S)"
4 }
5
6 # Cleanup actions
7 function cleanup() {
8         rm -f ${LOCK_DAILY}
9         rm -f ${LOCK_ACCEPTED}
10 }
11
12 # If we error out this one is called, *FOLLOWED* by cleanup above
13 function onerror() {
14     ERRDATE=$(date "+%Y.%m.%d-%H:%M:%S")
15
16     subject="ATTENTION ATTENTION!"
17     if [ "${error}" = "false" ]; then
18         subject="${subject} (continued)"
19     else
20         subject="${subject} (interrupted)"
21     fi
22     subject="${subject} dinstall error at ${ERRDATE} in ${STAGEFILE} - (Be quiet, Brain, or I'll stab you with a Q-tip)"
23
24     cat "${STAGEFILE}.log" | mail -s "${subject}" -a "X-Debian: DAK" cron@ftp-master.debian.org
25 }
26
27 ########################################################################
28 # the actual dinstall functions follow                                 #
29 ########################################################################
30
31 # pushing merkels QA user, part one
32 function merkel1() {
33     log "Telling merkels QA user that we start dinstall"
34     ssh -2 -i ~dak/.ssh/push_merkel_qa  -o BatchMode=yes -o SetupTimeOut=90 -o ConnectTimeout=90 qa@merkel.debian.org sleep 1
35 }
36
37 # Create the postgres dump files
38 function pgdump_pre() {
39     log "Creating pre-daily-cron-job backup of projectb database..."
40     pg_dump projectb > $base/backup/dump_pre_$(date +%Y.%m.%d-%H:%M:%S)
41 }
42
43 function pgdump_post() {
44     log "Creating post-daily-cron-job backup of projectb database..."
45     cd $base/backup
46     POSTDUMP=$(date +%Y.%m.%d-%H:%M:%S)
47     pg_dump projectb > $base/backup/dump_$POSTDUMP
48     pg_dumpall --globals-only > $base/backup/dumpall_$POSTDUMP
49     ln -sf $base/backup/dump_$POSTDUMP current
50     ln -sf $base/backup/dumpall_$POSTDUMP currentall
51 }
52
53 # Load the dak-dev projectb
54 function pgdakdev() {
55     cd $base/backup
56     echo "drop database projectb" | psql -p 5433 template1
57         cat currentall | psql -p 5433 template1
58     createdb -p 5433 -T template0 projectb
59     fgrep -v '\connect' current | psql -p 5433 projectb
60 }
61
62 # Updating various files
63 function updates() {
64     log "Updating Bugs docu, Mirror list and mailing-lists.txt"
65     cd $configdir
66     $scriptsdir/update-bugdoctxt
67     $scriptsdir/update-mirrorlists
68     $scriptsdir/update-mailingliststxt
69     $scriptsdir/update-pseudopackages.sh
70 }
71
72 # Process (oldstable)-proposed-updates "NEW" queue
73 function punew_do() {
74     date -u -R >> REPORT
75     dak process-policy $1 | tee >> REPORT | mail -e -s "NEW changes in $1" debian-release@lists.debian.org
76     echo >> REPORT
77 }
78 function punew() {
79     log "Doing automated p-u-new processing"
80     cd "${queuedir}/p-u-new"
81     punew_do "$1"
82 }
83 function opunew() {
84     log "Doing automated o-p-u-new processing"
85     cd "${queuedir}/o-p-u-new"
86     punew_do "$1"
87 }
88
89 # The first i18n one, syncing new descriptions
90 function i18n1() {
91     log "Synchronizing i18n package descriptions"
92     # First sync their newest data
93     cd ${scriptdir}/i18nsync
94     rsync -aq --delete --delete-after ddtp-sync:/does/not/matter . || true
95
96     # Now check if we still know about the packages for which they created the files
97     # is the timestamp signed by us?
98     if $(gpgv --keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/pubring.gpg timestamp.gpg timestamp); then
99         # now read it. As its signed by us we are sure the content is what we expect, no need
100         # to do more here. And we only test -d a directory on it anyway.
101         TSTAMP=$(cat timestamp)
102         # do we have the dir still?
103         if [ -d ${scriptdir}/i18n/${TSTAMP} ]; then
104             # Lets check!
105             if ${scriptsdir}/ddtp-i18n-check.sh . ${scriptdir}/i18n/${TSTAMP}; then
106                 # Yay, worked, lets copy around
107                 for dir in squeeze sid; do
108                     if [ -d dists/${dir}/ ]; then
109                         cd dists/${dir}/main/i18n
110                         rsync -aq --delete --delete-after  . ${ftpdir}/dists/${dir}/main/i18n/.
111                     fi
112                     cd ${scriptdir}/i18nsync
113                 done
114             else
115                 echo "ARRRR, bad guys, wrong files, ARRR"
116                 echo "Arf, Arf, Arf, bad guys, wrong files, arf, arf, arf" | mail -s "Don't you kids take anything. I'm watching you. I've got eye implants in the back of my head." debian-l10n-devel@lists.alioth.debian.org
117             fi
118         else
119             echo "ARRRR, missing the timestamp ${TSTAMP} directory, not updating i18n, ARRR"
120             echo "Arf, Arf, Arf, missing the timestamp ${TSTAMP} directory, not updating i18n, arf, arf, arf" | mail -s "Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way." debian-l10n-devel@lists.alioth.debian.org
121         fi
122     else
123         echo "ARRRRRRR, could not verify our timestamp signature, ARRR. Don't mess with our files, i18n guys, ARRRRR."
124         echo "Arf, Arf, Arf, could not verify our timestamp signature, arf. Don't mess with our files, i18n guys, arf, arf, arf" | mail -s "You can't keep blaming yourself. Just blame yourself once, and move on." debian-l10n-devel@lists.alioth.debian.org
125     fi
126 }
127
128 function cruft() {
129     log "Checking for cruft in overrides"
130     dak check-overrides
131 }
132
133 function dominate() {
134     log "Removing obsolete source and binary associations"
135     dak dominate
136 }
137
138 function filelist() {
139     log "Generating file lists for apt-ftparchive"
140     dak generate-filelist
141 }
142
143 function fingerprints() {
144     log "Not updating fingerprints - scripts needs checking"
145
146     log "Updating fingerprints"
147     dak import-keyring -L /srv/keyring.debian.org/keyrings/debian-keyring.gpg
148
149     OUTFILE=$(mktemp)
150     dak import-keyring --generate-users "%s" /srv/keyring.debian.org/keyrings/debian-maintainers.gpg >"${OUTFILE}"
151
152     if [ -s "${OUTFILE}" ]; then
153         /usr/sbin/sendmail -odq -oi -t -f envelope@ftp-master.debian.org <<EOF
154 From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>
155 To: <debian-project@lists.debian.org>
156 Subject: Debian Maintainers Keyring changes
157 Content-Type: text/plain; charset=utf-8
158 MIME-Version: 1.0
159
160 The following changes to the debian-maintainers keyring have just been activated:
161
162 $(cat $OUTFILE)
163
164 Debian distribution maintenance software,
165 on behalf of the Keyring maintainers
166
167 EOF
168     fi
169     rm -f "$OUTFILE"
170 }
171
172 function overrides() {
173     log "Writing overrides into text files"
174     cd $overridedir
175     dak make-overrides
176
177     # FIXME
178     rm -f override.sid.all3
179     for i in main contrib non-free main.debian-installer; do cat override.sid.$i >> override.sid.all3; done
180 }
181
182 function mpfm() {
183     log "Generating package / file mapping"
184     dak make-pkg-file-mapping | bzip2 -9 > $base/ftp/indices/package-file.map.bz2
185 }
186
187 function packages() {
188     log "Generating Packages and Sources files"
189     cd $configdir
190     GZIP='--rsyncable' ; export GZIP
191     apt-ftparchive generate apt.conf
192 }
193
194 function pdiff() {
195     log "Generating pdiff files"
196     dak generate-index-diffs
197 }
198
199 function release() {
200     log "Generating Release files"
201     dak generate-releases
202 }
203
204 function dakcleanup() {
205     log "Cleanup old packages/files"
206     dak clean-suites -m 10000
207     dak clean-queues
208 }
209
210 function buildd_dir() {
211     # Rebuilt the buildd dir to avoid long times of 403
212     log "Regenerating the buildd incoming dir"
213     STAMP=$(date "+%Y%m%d%H%M")
214     make_buildd_dir
215 }
216
217 function mklslar() {
218     cd $ftpdir
219
220     FILENAME=ls-lR
221
222     log "Removing any core files ..."
223     find -type f -name core -print0 | xargs -0r rm -v
224
225     log "Checking permissions on files in the FTP tree ..."
226     find -type f \( \! -perm -444 -o -perm +002 \) -ls
227     find -type d \( \! -perm -555 -o -perm +002 \) -ls
228
229     log "Checking symlinks ..."
230     symlinks -rd .
231
232     log "Creating recursive directory listing ... "
233     rm -f .${FILENAME}.new
234     TZ=UTC ls -lR > .${FILENAME}.new
235
236     if [ -r ${FILENAME}.gz ] ; then
237         mv -f ${FILENAME}.gz ${FILENAME}.old.gz
238         mv -f .${FILENAME}.new ${FILENAME}
239         rm -f ${FILENAME}.patch.gz
240         zcat ${FILENAME}.old.gz | diff -u - ${FILENAME} | gzip --rsyncable -9cfn - >${FILENAME}.patch.gz
241         rm -f ${FILENAME}.old.gz
242     else
243         mv -f .${FILENAME}.new ${FILENAME}
244     fi
245
246     gzip --rsyncable -9cfN ${FILENAME} >${FILENAME}.gz
247     rm -f ${FILENAME}
248 }
249
250 function mkmaintainers() {
251     log 'Creating Maintainers index ... '
252
253     cd $indices
254     dak make-maintainers ${scriptdir}/masterfiles/pseudo-packages.maintainers | \
255         sed -e "s/~[^  ]*\([   ]\)/\1/"  | \
256         awk '{printf "%-20s ", $1; for (i=2; i<=NF; i++) printf "%s ", $i; printf "\n";}' > .new-maintainers
257
258     if ! cmp -s .new-maintainers Maintainers || [ ! -f Maintainers ]; then
259             log "installing Maintainers ... "
260             mv -f .new-maintainers Maintainers
261             gzip --rsyncable -9v <Maintainers >.new-maintainers.gz
262             mv -f .new-maintainers.gz Maintainers.gz
263     else
264         rm -f .new-maintainers
265     fi
266 }
267
268 function copyoverrides() {
269     log 'Copying override files into public view ...'
270
271     for ofile in $copyoverrides ; do
272             cd $overridedir
273             chmod g+w override.$ofile
274
275             cd $indices
276
277             newofile=override.$ofile.gz
278             rm -f .newover-$ofile.gz
279             pc="`gzip 2>&1 -9nv <$overridedir/override.$ofile >.newover-$ofile.gz`"
280         if ! cmp -s .newover-$ofile.gz $newofile || [ ! -f $newofile ]; then
281                     log "   installing new $newofile $pc"
282                     mv -f .newover-$ofile.gz $newofile
283                     chmod g+w $newofile
284         else
285                     rm -f .newover-$ofile.gz
286             fi
287     done
288 }
289
290 function mkfilesindices() {
291     umask 002
292     cd $base/ftp/indices/files/components
293
294     ARCHLIST=$(tempfile)
295
296     log "Querying projectb..."
297     echo 'SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)' | psql projectb -At | sed 's/|//;s,^/srv/ftp.debian.org/ftp,.,' | sort >$ARCHLIST
298
299     includedirs () {
300         perl -ne 'print; while (m,/[^/]+$,) { $_=$`; print $_ . "\n" unless $d{$_}++; }'
301     }
302     poolfirst () {
303         perl -e '@nonpool=(); while (<>) { if (m,^\./pool/,) { print; } else { push @nonpool, $_; } } print for (@nonpool);'
304     }
305
306     log "Generating sources list"
307     (
308         sed -n 's/|$//p' $ARCHLIST
309         cd $base/ftp
310         find ./dists -maxdepth 1 \! -type d
311         find ./dists \! -type d | grep "/source/"
312     ) | sort -u | gzip --rsyncable -9 > source.list.gz
313
314     log "Generating arch lists"
315
316     ARCHES=$( (<$ARCHLIST sed -n 's/^.*|//p'; echo amd64) | grep . | grep -v all | sort -u)
317     for a in $ARCHES; do
318         (sed -n "s/|$a$//p" $ARCHLIST
319             sed -n 's/|all$//p' $ARCHLIST
320
321             cd $base/ftp
322             find ./dists -maxdepth 1 \! -type d
323             find ./dists \! -type d | grep -E "(proposed-updates.*_$a.changes$|/main/disks-$a/|/main/installer-$a/|/Contents-$a|/binary-$a/)"
324         ) | sort -u | gzip --rsyncable -9 > arch-$a.list.gz
325     done
326
327     log "Generating suite lists"
328
329     suite_list () {
330         printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)\n' $1 $1 | psql -F' ' -A -t projectb
331
332         printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d\n' $1 | psql -F' ' -A -t projectb
333     }
334
335     printf 'SELECT id, suite_name FROM suite\n' | psql -F' ' -At projectb |
336     while read id suite; do
337         [ -e $base/ftp/dists/$suite ] || continue
338         (
339             (cd $base/ftp
340                 distname=$(cd dists; readlink $suite || echo $suite)
341                 find ./dists/$distname \! -type d
342                 for distdir in ./dists/*; do
343                     [ "$(readlink $distdir)" != "$distname" ] || echo $distdir
344                 done
345             )
346             suite_list $id | tr -d ' ' | sed 's,^/srv/ftp.debian.org/ftp,.,'
347         ) | sort -u | gzip --rsyncable -9 > suite-${suite}.list.gz
348     done
349
350     log "Finding everything on the ftp site to generate sundries"
351     (cd $base/ftp; find . \! -type d \! -name 'Archive_Maintenance_In_Progress' | sort) >$ARCHLIST
352
353     rm -f sundries.list
354     zcat *.list.gz | cat - *.list | sort -u |
355     diff - $ARCHLIST | sed -n 's/^> //p' > sundries.list
356
357     log "Generating files list"
358
359     for a in $ARCHES; do
360         (echo ./project/trace; zcat arch-$a.list.gz source.list.gz) |
361         cat - sundries.list dists.list project.list docs.list indices.list |
362         sort -u | poolfirst > ../arch-$a.files
363     done
364
365     (cd $base/ftp/
366             for dist in sid squeeze; do
367                     find ./dists/$dist/main/i18n/ \! -type d | sort -u | gzip --rsyncable -9 > $base/ftp/indices/files/components/translation-$dist.list.gz
368             done
369     )
370
371     (cat ../arch-i386.files ../arch-amd64.files; zcat suite-oldstable.list.gz suite-proposed-updates.list.gz ; zcat translation-sid.list.gz ; zcat translation-squeeze.list.gz) |
372     sort -u | poolfirst > ../typical.files
373
374     rm -f $ARCHLIST
375     log "Done!"
376 }
377
378 function mkchecksums() {
379     dsynclist=$dbdir/dsync.list
380     md5list=$indices/md5sums
381
382     log -n "Creating md5 / dsync index file ... "
383
384     cd "$ftpdir"
385     ${bindir}/dsync-flist -q generate $dsynclist --exclude $dsynclist --md5
386     ${bindir}/dsync-flist -q md5sums $dsynclist | gzip -9n --rsyncable > ${md5list}.gz
387     ${bindir}/dsync-flist -q link-dups $dsynclist || true
388 }
389
390 function mirror() {
391     log "Regenerating \"public\" mirror/ hardlink fun"
392     cd ${mirrordir}
393     rsync -aH --link-dest ${ftpdir} --delete --delete-after --ignore-errors ${ftpdir}/. .
394 }
395
396 function expire() {
397     log "Expiring old database dumps..."
398     cd $base/backup
399     $scriptsdir/expire_dumps -d . -p -f "dump_*"
400 }
401
402 function transitionsclean() {
403     log "Removing out of date transitions..."
404     cd $base
405     dak transitions -c -a
406 }
407
408 function reports() {
409     # Send a report on NEW/BYHAND packages
410     log "Nagging ftpteam about NEW/BYHAND packages"
411     dak queue-report | mail -e -s "NEW and BYHAND on $(date +%D)" ftpmaster@ftp-master.debian.org
412     # and one on crufty packages
413     log "Sending information about crufty packages"
414     dak cruft-report > $webdir/cruft-report-daily.txt
415     dak cruft-report -s experimental >> $webdir/cruft-report-daily.txt
416     cat $webdir/cruft-report-daily.txt | mail -e -s "Debian archive cruft report for $(date +%D)" ftpmaster@ftp-master.debian.org
417 }
418
419 function dm() {
420     log "Updating DM html page"
421     $scriptsdir/dm-monitor >$webdir/dm-uploaders.html
422 }
423
424 function bts() {
425     log "Categorizing uncategorized bugs filed against ftp.debian.org"
426     dak bts-categorize
427 }
428
429 function merkel2() {
430     # Push dak@merkel so it syncs the projectb there. Returns immediately, the sync runs detached
431     log "Trigger merkel/flotows projectb sync"
432     ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_projectb dak@merkel.debian.org sleep 1
433     # Also trigger flotow, the ftpmaster test box
434     ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_flotow_projectb dak@flotow.debconf.org sleep 1
435 }
436
437 function merkel3() {
438     # Push dak@merkel to tell it to sync the dd accessible parts. Returns immediately, the sync runs detached
439     log "Trigger merkels dd accessible parts sync"
440     ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_ddaccess dak@merkel.debian.org sleep 1
441 }
442
443 function mirrorpush() {
444     log "Starting the mirrorpush"
445     date -u > /srv/ftp.debian.org/web/mirrorstart
446     echo "Using dak v1" >> /srv/ftp.debian.org/web/mirrorstart
447     echo "Running on host $(hostname -f)" >> /srv/ftp.debian.org/web/mirrorstart
448     sudo -H -u archvsync /home/archvsync/runmirrors > ~dak/runmirrors.log 2>&1 &
449 }
450
451 function i18n2() {
452     log "Exporting package data foo for i18n project"
453     STAMP=$(date "+%Y%m%d%H%M")
454     mkdir -p ${scriptdir}/i18n/${STAMP}
455     cd ${scriptdir}/i18n/${STAMP}
456     dak control-suite -l stable > lenny
457     dak control-suite -l testing > squeeze
458     dak control-suite -l unstable > sid
459     echo "${STAMP}" > timestamp
460     gpg --secret-keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/secring.gpg --keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/pubring.gpg --no-options --batch --no-tty --armour --default-key 55BE302B --detach-sign -o timestamp.gpg timestamp
461     rm -f md5sum
462     md5sum * > md5sum
463     cd ${webdir}/
464     ln -sfT ${scriptdir}/i18n/${STAMP} i18n
465
466     cd ${scriptdir}
467     find ./i18n -mindepth 1 -maxdepth 1 -mtime +2 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
468 }
469
470 function stats() {
471     log "Updating stats data"
472     cd $configdir
473     $scriptsdir/update-ftpstats $base/log/* > $base/misc/ftpstats.data
474     R --slave --vanilla < $base/misc/ftpstats.R
475     dak stats arch-space > $webdir/arch-space
476     dak stats pkg-nums > $webdir/pkg-nums
477 }
478
479 function aptftpcleanup() {
480     log "Clean up apt-ftparchive's databases"
481     cd $configdir
482     apt-ftparchive -q clean apt.conf
483 }
484
485 function compress() {
486     log "Compress old psql backups"
487     cd $base/backup/
488     find -maxdepth 1 -mindepth 1 -type f -name 'dump_pre_*' -mtime +2 -print0 | xargs -0 --no-run-if-empty rm
489
490     find -maxdepth 1 -mindepth 1 -type f -name 'dump_*' \! -name '*.bz2' \! -name '*.gz' -mmin +720 |
491     while read dumpname; do
492         echo "Compressing $dumpname"
493         bzip2 -9fv "$dumpname"
494     done
495     find -maxdepth 1 -mindepth 1 -type f -name "dumpall_*" \! -name '*.bz2' \! -name '*.gz' -mmin +720 |
496     while read dumpname; do
497         echo "Compressing $dumpname"
498         bzip2 -9fv "$dumpname"
499     done
500     finddup -l -d $base/backup
501 }
502
503 function logstats() {
504     $masterdir/tools/logs.py "$1"
505 }
506
507 # save timestamp when we start
508 function savetimestamp() {
509         NOW=`date "+%Y.%m.%d-%H:%M:%S"`
510         echo ${NOW} > "${dbdir}/dinstallstart"
511 }
512
513 function maillogfile() {
514     cat "$LOGFILE" | mail -s "Log for dinstall run of ${NOW}" cron@ftp-master.debian.org
515 }
516
517 function renamelogfile() {
518     if [ -f "${dbdir}/dinstallstart" ]; then
519         NOW=$(cat "${dbdir}/dinstallstart")
520 #        maillogfile
521         mv "$LOGFILE" "$logdir/dinstall_${NOW}.log"
522         logstats "$logdir/dinstall_${NOW}.log"
523         bzip2 -9 "$logdir/dinstall_${NOW}.log"
524     else
525         error "Problem, I don't know when dinstall started, unable to do log statistics."
526         NOW=`date "+%Y.%m.%d-%H:%M:%S"`
527 #        maillogfile
528         mv "$LOGFILE" "$logdir/dinstall_${NOW}.log"
529         bzip2 -9 "$logdir/dinstall_${NOW}.log"
530     fi
531 }
532
533 function testingsourcelist() {
534     dak ls -s testing -f heidi -r .| egrep 'source$' > ${webdir}/testing.list
535 }
536
537 # do a last run of process-unchecked before dinstall is on.
538 function process_unchecked() {
539     log "Processing the unchecked queue"
540     UNCHECKED_WITHOUT_LOCK="-p"
541     do_unchecked
542     sync_debbugs
543 }
544
545 # do a run of newstage only before dinstall is on.
546 function newstage() {
547     log "Processing the newstage queue"
548     UNCHECKED_WITHOUT_LOCK="-p"
549     do_newstage
550 }
551
552 # Function to update a "statefile" telling people what we are doing
553 # (more or less).
554 #
555 # This should be called with the argument(s)
556 #  - Status name we want to show.
557 #
558 function state() {
559     RIGHTNOW="$(date -u +"%a %b %d %T %Z %Y (%s)")"
560     cat >"${DINSTALLSTATE}" <<EOF
561 Dinstall start: ${DINSTALLBEGIN}
562 Current action: ${1}
563 Action start: ${RIGHTNOW}
564 EOF
565 }