]> git.decadent.org.uk Git - dak.git/blob - config/debian/dinstall.functions
Various
[dak.git] / config / debian / dinstall.functions
1 # -*- mode:sh -*-
2
3 # Remove daily lock
4 # FIXME: Dead code when switched to cronscript
5 function remove_daily_lock() {
6     rm -f $LOCK_DAILY
7 }
8
9 # Remove changelog lock
10 function remove_changelog_lock() {
11     rm -f $LOCK_CHANGELOG
12 }
13
14 # Remove all locks
15 function remove_all_locks() {
16     rm -f $LOCK_DAILY $LOCK_ACCEPTED
17 }
18
19 function remove_locks {
20     remove_all_locks
21     trap - EXIT TERM HUP INT QUIT
22     ts "locked part finished"
23 }
24
25 function lockaccepted {
26     lockfile "$LOCK_ACCEPTED"
27     trap remove_all_locks EXIT TERM HUP INT QUIT
28 }
29
30 # If we error out this one is called, *FOLLOWED* by cleanup above
31 function onerror() {
32     ERRDATE=$(date "+%Y.%m.%d-%H:%M:%S")
33
34     subject="ATTENTION ATTENTION!"
35     if [ "${error}" = "false" ]; then
36         subject="${subject} (continued)"
37     else
38         subject="${subject} (interrupted)"
39     fi
40     subject="${subject} dinstall error at ${ERRDATE} in ${STAGEFILE} - (Be quiet, Brain, or I'll stab you with a Q-tip)"
41
42     if [ -r "${STAGEFILE}.log" ]; then
43         cat "${STAGEFILE}.log"
44     else
45         echo "file ${STAGEFILE}.log does not exist, sorry"
46     fi | mail -s "${subject}" -a "X-Debian: DAK" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" cron@ftp-master.debian.org
47 }
48
49 ########################################################################
50 # the actual functions follow                                          #
51 ########################################################################
52
53 # pushing merkels QA user, part one
54 function qa1() {
55     log "Telling QA user that we start dinstall"
56     ssh -n -2 -i ~dak/.ssh/push_merkel_qa  -o BatchMode=yes -o SetupTimeOut=90 -o ConnectTimeout=90 qa@qa.debian.org sleep 1
57 }
58
59 # Updating various files
60 function updates() {
61     log "Updating Bugs docu, Mirror list and mailing-lists.txt"
62     cd $configdir
63     $scriptsdir/update-bugdoctxt
64     $scriptsdir/update-mirrorlists
65     $scriptsdir/update-mailingliststxt
66     $scriptsdir/update-pseudopackages.sh
67 }
68
69 # The first i18n one, syncing new descriptions
70 function i18n1() {
71     log "Synchronizing i18n package descriptions"
72     # First sync their newest data
73     cd ${scriptdir}/i18nsync
74     rsync -aq --delete --delete-after ddtp-sync:/does/not/matter . || true
75
76     # Now check if we still know about the packages for which they created the files
77     # is the timestamp signed by us?
78     if $(gpgv --keyring /srv/ftp-master.debian.org/s3kr1t/dot-gnupg/pubring.gpg timestamp.gpg timestamp); then
79         # now read it. As its signed by us we are sure the content is what we expect, no need
80         # to do more here. And we only test -d a directory on it anyway.
81         TSTAMP=$(cat timestamp)
82         # do we have the dir still?
83         if [ -d ${scriptdir}/i18n/${TSTAMP} ]; then
84             # Lets check!
85             if ${scriptsdir}/ddtp-i18n-check.sh . ${scriptdir}/i18n/${TSTAMP}; then
86                 # Yay, worked, lets copy around
87                 for dir in ${extimportdists}; do
88                     if [ -d dists/${dir}/ ]; then
89                         cd dists/${dir}/main/i18n
90                         rsync -aq --delete --delete-after --exclude Translation-en.bz2 --exclude Translation-*.diff/ . ${ftpdir}/dists/${dir}/main/i18n/.
91                     fi
92                     cd ${scriptdir}/i18nsync
93                 done
94             else
95                 echo "ARRRR, bad guys, wrong files, ARRR"
96                 echo "Arf, Arf, Arf, bad guys, wrong files, arf, arf, arf" | mail -a "X-Debian: DAK" -s "Don't you kids take anything. I'm watching you. I've got eye implants in the back of my head." -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" debian-l10n-devel@lists.alioth.debian.org
97             fi
98         else
99             echo "ARRRR, missing the timestamp ${TSTAMP} directory, not updating i18n, ARRR"
100             echo "Arf, Arf, Arf, missing the timestamp ${TSTAMP} directory, not updating i18n, arf, arf, arf" | mail -a "X-Debian: DAK" -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." -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" debian-l10n-devel@lists.alioth.debian.org
101         fi
102     else
103         echo "ARRRRRRR, could not verify our timestamp signature, ARRR. Don't mess with our files, i18n guys, ARRRRR."
104         echo "Arf, Arf, Arf, could not verify our timestamp signature, arf. Don't mess with our files, i18n guys, arf, arf, arf" | mail -a "X-Debian: DAK" -s "You can't keep blaming yourself. Just blame yourself once, and move on." -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" debian-l10n-devel@lists.alioth.debian.org
105     fi
106 }
107
108 # Syncing AppStream/DEP-11 data
109 function dep11() {
110     log "Synchronizing AppStream metadata"
111     # First sync their newest data
112     local dep11dir="${scriptdir}/dep11"
113     mkdir -p ${dep11dir}
114     cd ${dep11dir}
115     rsync -aq --delete --delete-after dep11-sync:/does/not/matter . || true
116
117     # Lets check!
118     if ${scriptsdir}/dep11-basic-validate.py . ${dep11dir}/; then
119         # Yay, worked, lets copy around
120         for dir in ${extimportdists}; do
121             if [ -d ${dir}/ ]; then
122                 for comp in main contrib non-free; do
123                     mkdir -p ${ftpdir}/dists/${dir}/${comp}/dep11
124                     cd ${dir}/${comp}
125                     rsync -aq --delete --delete-after --exclude *.tmp . ${ftpdir}/dists/${dir}/${comp}/dep11/.
126                     cd ${dep11dir}
127                 done
128             fi
129         done
130     else
131         echo "ARRRR, bad guys, wrong files, ARRR"
132         echo "Arf, Arf, Arf, bad guys, wrong files, arf, arf, arf" | mail -a "X-Debian: DAK" -s "Don't you kids take anything. I'm watching you. I've got eye implants in the back of my head." -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" mak@debian.org
133     fi
134 }
135
136 function cruft() {
137     log "Checking for cruft in overrides"
138     dak check-overrides
139 }
140
141 function dominate() {
142     log "Removing obsolete source and binary associations"
143     dak dominate
144     dak manage-debug-suites unstable-debug experimental-debug
145 }
146
147 function autocruft() {
148     log "Check for obsolete binary packages"
149     dak auto-decruft -s unstable
150     dak auto-decruft -s experimental --if-newer-version-in unstable --if-newer-version-in-rm-msg "NVIU"
151 }
152
153 function fingerprints() {
154     log "Updating fingerprints"
155     dak import-keyring -L /srv/keyring.debian.org/keyrings/debian-keyring.gpg
156
157     OUTFILE=$(mktemp)
158     dak import-keyring --generate-users "%s" /srv/keyring.debian.org/keyrings/debian-maintainers.gpg >"${OUTFILE}"
159
160     if [ -s "${OUTFILE}" ]; then
161         /usr/sbin/sendmail -odq -oi -t -f envelope@ftp-master.debian.org <<EOF
162 From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>
163 To: <debian-project@lists.debian.org>
164 Subject: Debian Maintainers Keyring changes
165 Content-Type: text/plain; charset=utf-8
166 X-Debian: DAK
167 MIME-Version: 1.0
168
169 The following changes to the debian-maintainers keyring have just been activated:
170
171 $(cat $OUTFILE)
172
173 Debian distribution maintenance software,
174 on behalf of the Keyring maintainers
175
176 EOF
177     fi
178     rm -f "$OUTFILE"
179 }
180
181 function overrides() {
182     log "Writing overrides into text files"
183     cd $overridedir
184     dak make-overrides
185 }
186
187 function mpfm() {
188     local archiveroot
189
190     log "Generating package / file mapping"
191     for archive in "${public_archives[@]}"; do
192         log "  archive: ${archive}"
193         archiveroot="$(get_archiveroot "${archive}")"
194         dak make-pkg-file-mapping "${archive}" | bzip2 -9 > "${archiveroot}/indices/package-file.map.bz2"
195     done
196 }
197
198 function packages() {
199     for archive in "${public_archives[@]}"; do
200         log "  Generating Packages/Sources for ${archive}"
201         dak generate-packages-sources2 -a "${archive}"
202         log "  Generating Contents for ${archive}"
203         dak contents generate -a "${archive}"
204     done
205 }
206
207 function pdiff() {
208     log "Generating pdiff files"
209     dak generate-index-diffs
210 }
211
212 function release() {
213     log "Generating Release files"
214     for archive in "${public_archives[@]}"; do
215         log "  archive: ${archive}"
216         dak generate-releases -a "${archive}"
217     done
218 }
219
220 function dakcleanup() {
221     log "Cleanup old packages/files"
222     dak clean-suites -m 10000
223     dak clean-queues -i "$unchecked"
224 }
225
226 function mklslar() {
227     local archiveroot
228     local FILENAME=ls-lR
229
230     for archive in "${public_archives[@]}"; do
231         archiveroot="$(get_archiveroot "${archive}")"
232         cd "${archiveroot}"
233
234         log "Removing any core files ..."
235         find -type f -name core -print -delete
236
237         log "Checking symlinks ..."
238         symlinks -rd .
239
240         log "Creating recursive directory listing ... "
241         rm -f ${FILENAME}.gz
242         TZ=UTC ls -lR | gzip -9c --rsyncable > ${FILENAME}.gz
243     done
244 }
245
246 function mkmaintainers() {
247     local archiveroot
248     local indices
249
250     log 'Creating Maintainers index ... '
251
252     for archive in "${public_archives[@]}"; do
253         archiveroot="$(get_archiveroot "${archive}")"
254         indices="${archiveroot}/indices"
255         if ! [ -d "${indices}" ]; then
256             mkdir "${indices}"
257         fi
258         cd "${indices}"
259
260         dak make-maintainers -a "${archive}" ${scriptdir}/masterfiles/pseudo-packages.maintainers
261         gzip -9v --rsyncable <Maintainers >Maintainers.gz
262         gzip -9v --rsyncable <Uploaders >Uploaders.gz
263     done
264 }
265
266 function copyoverrides() {
267     log 'Copying override files into public view ...'
268
269     (
270         shopt -s nullglob
271         for ofile in ${overridedir}/override.{squeeze,wheezy,jessie,stretch,sid}.{,extra.}{main,contrib,non-free}*; do
272             bname=${ofile##*/}
273             gzip -9cv --rsyncable ${ofile} > ${indices}/${bname}.gz
274             chmod g+w ${indices}/${bname}.gz
275         done
276     )
277 }
278
279 function mkfilesindices() {
280     set +o pipefail
281     umask 002
282     cd $base/ftp/indices/files/components
283
284     ARCHLIST=$(tempfile)
285
286     log "Querying postgres"
287     local query="
288       SELECT './pool/' || c.name || '/' || f.filename AS path, a.arch_string AS arch_string
289       FROM files f
290       JOIN files_archive_map af ON f.id = af.file_id
291       JOIN component c ON af.component_id = c.id
292       JOIN archive ON af.archive_id = archive.id
293       LEFT OUTER JOIN
294         (binaries b
295          JOIN architecture a ON b.architecture = a.id)
296         ON f.id = b.file
297       WHERE archive.name = 'ftp-master'
298       ORDER BY path, arch_string
299     "
300     psql -At -c "$query" >$ARCHLIST
301
302     includedirs () {
303         perl -ne 'print; while (m,/[^/]+$,) { $_=$`; print $_ . "\n" unless $d{$_}++; }'
304     }
305     poolfirst () {
306         perl -e '@nonpool=(); while (<>) { if (m,^\./pool/,) { print; } else { push @nonpool, $_; } } print for (@nonpool);'
307     }
308
309     log "Generating sources list"
310     (
311         sed -n 's/|$//p' $ARCHLIST
312         cd $base/ftp
313         find ./dists -maxdepth 1 \! -type d
314         find ./dists \! -type d | grep "/source/"
315     ) | sort -u | gzip -9 > source.list.gz
316
317     log "Generating arch lists"
318
319     ARCHES=$( (<$ARCHLIST sed -n 's/^.*|//p'; echo amd64) | grep . | grep -v all | sort -u)
320     for a in $ARCHES; do
321         (sed -n "s/|$a$//p" $ARCHLIST
322          sed -n 's/|all$//p' $ARCHLIST
323
324          cd $base/ftp
325          find ./dists -maxdepth 1 \! -type d
326          find ./dists \! -type d | grep -E "(proposed-updates.*_$a.changes$|/main/disks-$a/|/main/installer-$a/|/Contents-$a|/binary-$a/)"
327         ) | sort -u | gzip -9 > arch-$a.list.gz
328     done
329
330     log "Generating suite lists"
331
332     suite_list () {
333         local suite_id="$(printf %d $1)"
334         local query
335         query="
336           SELECT DISTINCT './pool/' || c.name || '/' || f.filename
337           FROM
338             (SELECT sa.source AS source
339                FROM src_associations sa
340               WHERE sa.suite = $suite_id
341              UNION
342              SELECT esr.src_id
343                FROM extra_src_references esr
344                JOIN bin_associations ba ON esr.bin_id = ba.bin
345                WHERE ba.suite = $suite_id
346              UNION
347              SELECT b.source AS source
348                FROM bin_associations ba
349                JOIN binaries b ON ba.bin = b.id WHERE ba.suite = $suite_id) s
350             JOIN dsc_files df ON s.source = df.source
351             JOIN files f ON df.file = f.id
352             JOIN files_archive_map af ON f.id = af.file_id
353             JOIN component c ON af.component_id = c.id
354             JOIN archive ON af.archive_id = archive.id
355             WHERE archive.name = 'ftp-master'
356         "
357         psql -F' ' -A -t -c "$query"
358
359         query="
360           SELECT './pool/' || c.name || '/' || f.filename
361           FROM bin_associations ba
362           JOIN binaries b ON ba.bin = b.id
363           JOIN files f ON b.file = f.id
364           JOIN files_archive_map af ON f.id = af.file_id
365           JOIN component c ON af.component_id = c.id
366           JOIN archive ON af.archive_id = archive.id
367           WHERE ba.suite = $suite_id AND archive.name = 'ftp-master'
368         "
369         psql -F' ' -A -t -c "$query"
370     }
371
372     psql -F' ' -At -c "SELECT id, suite_name FROM suite" |
373         while read id suite; do
374             [ -e $base/ftp/dists/$suite ] || continue
375             (
376                 (cd $base/ftp
377                  distname=$(cd dists; readlink $suite || echo $suite)
378                  find ./dists/$distname \! -type d
379                  for distdir in ./dists/*; do
380                      [ "$(readlink $distdir)" != "$distname" ] || echo $distdir
381                  done
382                 )
383                 suite_list $id
384             ) | sort -u | gzip -9 > suite-${suite}.list.gz
385         done
386
387     log "Finding everything on the ftp site to generate sundries"
388     (cd $base/ftp; find . \! -type d \! -name 'Archive_Maintenance_In_Progress' | sort) >$ARCHLIST
389
390     rm -f sundries.list
391     zcat *.list.gz | cat - *.list | sort -u |
392         diff - $ARCHLIST | sed -n 's/^> //p' > sundries.list
393
394     log "Generating files list"
395
396     for a in $ARCHES; do
397         (echo ./project/trace; zcat arch-$a.list.gz source.list.gz) |
398             cat - sundries.list dists.list project.list docs.list indices.list |
399             sort -u | poolfirst > ../arch-$a.files
400     done
401
402     (cd $base/ftp/
403      for dist in sid jessie stretch; do
404          find ./dists/$dist/main/i18n/ \! -type d | sort -u | gzip -9 > $base/ftp/indices/files/components/translation-$dist.list.gz
405      done
406     )
407
408     (cat ../arch-i386.files ../arch-amd64.files; zcat suite-proposed-updates.list.gz ; zcat translation-sid.list.gz ; zcat translation-jessie.list.gz ; zcat translation-stretch.list.gz) |
409         sort -u | poolfirst > ../typical.files
410
411     rm -f $ARCHLIST
412     log "Done!"
413     set -o pipefail
414 }
415
416 function mkchecksums() {
417     local archiveroot dsynclist md5list
418
419     for archive in "${public_archives[@]}"; do
420         archiveroot="$(get_archiveroot "${archive}")"
421         dsynclist=$dbdir/dsync.${archive}.list
422         md5list=${archiveroot}/indices/md5sums
423
424         log -n "Creating md5 / dsync index file for ${archive}... "
425
426         cd "$archiveroot"
427         ${bindir}/dsync-flist -q generate $dsynclist --exclude $dsynclist --md5
428         ${bindir}/dsync-flist -q md5sums $dsynclist | gzip -9n > ${md5list}.gz
429         ${bindir}/dsync-flist -q link-dups $dsynclist || true
430     done
431 }
432
433 function mirror() {
434     local archiveroot targetpath TRACEFILE
435
436     for archive in "${public_archives[@]}"; do
437         archiveroot="$(get_archiveroot "${archive}")"
438         targetpath="${mirrordir}/${archive}"
439         TRACEFILE="${archiveroot}/project/trace/ftp-master.debian.org"
440         mkdir -p "${archiveroot}/project/trace/"
441
442         log "Regenerating \"public\" mirror/${archive} hardlink fun"
443         DATE_SERIAL=$(date +"%Y%m%d01")
444         FILESOAPLUS1=$(awk '/serial/ { print $3+1 }' ${TRACEFILE} || echo ${DATE_SERIAL} )
445         if [ "$DATE_SERIAL" -gt "$FILESOAPLUS1" ]; then
446             SERIAL="$DATE_SERIAL"
447         else
448             SERIAL="$FILESOAPLUS1"
449         fi
450         date -u > ${TRACEFILE}
451         echo "Using dak v1" >> ${TRACEFILE}
452         echo "Running on host: $(hostname -f)" >> ${TRACEFILE}
453         echo "Archive serial: ${SERIAL}" >> ${TRACEFILE}
454
455         mkdir -p ${targetpath}
456         cd ${targetpath}
457         rsync -aH --link-dest ${archiveroot} --delete --delete-after --delete-excluded --exclude Packages.*.new --exclude Sources.*.new  --ignore-errors ${archiveroot}/. .
458     done
459 }
460
461 function expire() {
462     log "Expiring old database dumps..."
463     cd $base/backup
464     $scriptsdir/expire_dumps -d . -p -f "dump_*"
465 }
466
467 function transitionsclean() {
468     log "Removing out of date transitions..."
469     cd $base
470     dak transitions -c -a
471 }
472
473 function dm() {
474     log "Updating DM permissions page"
475     dak acl export-per-source dm >$exportdir/dm.txt
476 }
477
478 function bts() {
479     log "Categorizing uncategorized bugs filed against ftp.debian.org"
480     sudo -u dak-unpriv dak bts-categorize
481 }
482
483 function mirrorpush() {
484     log "Checking the public archive copies..."
485
486     local archiveroot targetpath
487
488     for archive in "${public_archives[@]}"; do
489         log "... archive: ${archive}"
490         archiveroot="$(get_archiveroot "${archive}")"
491         targetpath="${mirrordir}/${archive}"
492         cd ${archiveroot}/dists
493
494         broken=0
495         for release in $(find . -name "InRelease"); do
496             echo "Processing: ${release}"
497             subdir=${release%/InRelease}
498             while read SHASUM SIZE NAME; do
499                 if ! [ -f "${subdir}/${NAME}" ]; then
500                     bname=$(basename ${NAME})
501                     if [[ "${bname}" =~ ^(Packages|Sources|Contents-[a-zA-Z0-9-]+|Translation-[a-zA-Z_]+|Components-(amd64|i386)\.yml|icons-(128x128|64x64)\.tar)$ ]]; then
502
503                         # We don't keep unpacked files, don't check for their existance.
504                         # We might want to go and check their unpacked shasum, but right now
505                         # I don't care. I believe it should be enough if all the packed shasums
506                         # match.
507                         continue
508                     fi
509                     broken=$(( broken + 1 ))
510                     echo "File ${subdir}/${NAME} is missing"
511                     continue
512                 fi
513
514                 # We do have symlinks in the tree (see the contents files currently).
515                 # So we use "readlink -f" to check the size of the target, as thats basically
516                 # what gen-releases does
517                 fsize=$(stat -c %s $(readlink -f "${subdir}/${NAME}"))
518                 if [ ${fsize} -ne ${SIZE} ]; then
519                     broken=$(( broken + 1 ))
520                     echo "File ${subdir}/${NAME} has size ${fsize}, expected is ${SIZE}"
521                     continue
522                 fi
523
524                 fshasum=$(sha1sum $(readlink -f "${subdir}/${NAME}"))
525                 fshasum=${fshasum%% *}
526                 if [ "${fshasum}" != "${SHASUM}" ]; then
527                     broken=$(( broken + 1 ))
528                     echo "File ${subdir}/${NAME} has checksum ${fshasum}, expected is ${SHASUM}"
529                     continue
530                 fi
531             done < <(sed '1,/SHA1:/d' "${release}" | sed '/SHA256:/,$d')
532         done
533
534         if [ $broken -gt 0 ]; then
535             log_error "Trouble with the public mirror for ${archive}, found ${broken} errors"
536             continue
537         else
538             log "Starting the mirrorpush for ${archive}"
539             case ${archive} in
540                 ftp-master)
541                     fname="mirrorstart"
542                     pusharg=""
543                     ;;
544                 debian-debug)
545                     pusharg="-a debug"
546                     ;;&
547                 backports)
548                     pusharg="-a backports"
549                     ;;&
550                 *)
551                     fname="mirrorstart.${archive}"
552                     ;;
553             esac
554             date -u > /srv/ftp.debian.org/web/${fname}
555             echo "Using dak v1" >> /srv/ftp.debian.org/web/${fname}
556             echo "Running on host $(hostname -f)" >> /srv/ftp.debian.org/web/${fname}
557             sudo -H -u archvsync /home/archvsync/runmirrors ${pusharg} > ~dak/runmirrors-${archive}.log 2>&1 &
558         fi
559     done
560 }
561
562 function mirrorpush-backports() {
563     log "Syncing backports mirror"
564     sudo -u backports /home/backports/bin/update-archive
565 }
566
567 function i18n2() {
568     log "Exporting package data foo for i18n project"
569     STAMP=$(date "+%Y%m%d%H%M")
570     mkdir -p ${scriptdir}/i18n/${STAMP}
571     cd ${scriptdir}/i18n/${STAMP}
572     for suite in stable testing unstable; do
573         codename=$(dak admin s show ${suite}|grep '^Codename')
574         codename=${codename##* }
575         echo "Codename is ${codename}"
576         dak control-suite -l ${suite} >${codename}
577     done
578     echo "${STAMP}" > timestamp
579     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 timestamp.gpg timestamp
580     rm -f md5sum
581     md5sum * > md5sum
582     cd ${webdir}/
583     ln -sfT ${scriptdir}/i18n/${STAMP} i18n
584
585     cd ${scriptdir}
586     find ./i18n -mindepth 1 -maxdepth 1 -mtime +2 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
587 }
588
589 function stats() {
590     log "Updating stats data"
591     cd $configdir
592     $scriptsdir/update-ftpstats $base/log/* > $base/misc/ftpstats.data
593     R --slave --vanilla < $base/misc/ftpstats.R
594     dak stats arch-space > $webdir/arch-space
595     dak stats pkg-nums > $webdir/pkg-nums
596 }
597
598 function cleantransactions() {
599     log "Cleanup transaction ids older than 3 months"
600     cd $base/backup/
601     find -maxdepth 1 -mindepth 1 -type f -name 'txid_*' -mtime +90 -delete
602 }
603
604 function logstats() {
605     $masterdir/tools/logs.py "$1"
606 }
607
608 # save timestamp when we start
609 function savetimestamp() {
610     echo ${NOW} > "${dbdir}/dinstallstart"
611 }
612
613 function maillogfile() {
614     cat "$LOGFILE" | mail -a "X-Debian: DAK" -s "Log for dinstall run of ${NOW}" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" cron@ftp-master.debian.org
615 }
616
617 function testingsourcelist() {
618     dak ls -s testing -f heidi -r .| egrep 'source$' > ${webdir}/testing.list
619 }
620
621 # Function to update a "statefile" telling people what we are doing
622 # (more or less).
623 #
624 # This should be called with the argument(s)
625 #  - Status name we want to show.
626 #
627 function state() {
628     RIGHTNOW="$(date -u +"%a %b %d %T %Z %Y (%s)")"
629     cat >"${DINSTALLSTATE}" <<EOF
630 Dinstall start: ${DINSTALLBEGIN}
631 Current action: ${1}
632 Action start: ${RIGHTNOW}
633 EOF
634 }
635
636 # extract changelogs and stuff
637 function changelogs() {
638     if lockfile -r3 $LOCK_CHANGELOG; then
639         log "Extracting changelogs"
640         dak make-changelog -e -a ftp-master
641         [ -f ${exportdir}/changelogs/filelist.yaml ] && xz -f ${exportdir}/changelogs/filelist.yaml
642         mkdir -p ${exportpublic}/changelogs
643         cd ${exportpublic}/changelogs
644         rsync -aHW --delete --delete-after --ignore-errors ${exportdir}/changelogs/. .
645         sudo -H -u staticsync /usr/local/bin/static-update-component metadata.ftp-master.debian.org >/dev/null 2>&1 &
646
647         dak make-changelog -e -a backports
648         [ -f /srv/backports-master.debian.org/export/changelogs/filelist.yaml ] && xz -f /srv/backports-master.debian.org/export/changelogs/filelist.yaml
649         mkdir -p /srv/backports-master.debian.org/rsync/export/changelogs
650         cd /srv/backports-master.debian.org/rsync/export/changelogs
651         rsync -aHW --delete --delete-after --ignore-errors /srv/backports-master.debian.org/export/changelogs/. .
652         remove_changelog_lock
653         trap remove_changelog_lock EXIT TERM HUP INT QUIT
654     fi
655 }
656
657 # Generate a list of extra mirror files, sha256sum em and sign that
658 function signotherfiles() {
659     log "Signing extra mirror files"
660
661     local archiveroot
662
663     for archive in "${public_archives[@]}"; do
664         log "... archive: ${archive}"
665         archiveroot="$(get_archiveroot "${archive}")"
666         local TMPLO=$( mktemp -p ${TMPDIR} )
667         trap "rm -f ${TMPLO}" ERR EXIT TERM HUP INT QUIT
668
669         cd ${archiveroot}
670         rm -f extrafiles
671         sha256sum $(find * -type f | egrep -v '(pool|i18n|dep11|source)/|Contents-.*\.(gz|diff)|installer|binary-|(In)?Release(.gpg)?|\.changes' | sort) > ${TMPLO}
672         gpg --no-options --batch --no-tty --armour --personal-digest-preferences=SHA256 --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 --clearsign --output ${archiveroot}/extrafiles ${TMPLO}
673         rm -f ${TMPLO}
674     done
675 }
676
677 function startup() {
678     touch "${DINSTALLSTART}"
679     ts "startup"
680     lockfile -l 3600 "${LOCK_DAILY}"
681     trap onerror ERR
682     touch "${LOCK_BRITNEY}"
683     TMPFILES="${TMPFILES} ${LOCK_DAILY} ${LOCK_BRITNEY}"
684 }