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