#! /bin/sh
#
# Executed daily via cron, out of deb-dak's crontab.

set -e
export SCRIPTVARS=/var/lib/dak/katie/vars
. $SCRIPTVARS

################################################################################

echo Archive maintenance started at $(date +%X)

NOTICE="$ftpdir/Archive_Maintenance_In_Progress"

cleanup() {
  rm -f "$NOTICE"
}
trap cleanup 0

rm -f "$NOTICE"
cat > "$NOTICE" <<EOF
Packages are currently being installed and indices rebuilt.
Maintenance is automatic, starting at 13:52 US Central time, and
ending at about 15:30.  This file is then removed.

You should not mirror the archive during this period.
EOF

################################################################################

echo "Creating pre-daily-cron-job backup of projectb database..."
pg_dump projectb > /var/lib/dak/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)

################################################################################

## Disabled currently. Scripts are /usr/share/doc/dak/scripts
##update-bugdoctxt
##update-mirrorlists
##update-mailingliststxt

################################################################################

cd $accepted
rm -f REPORT
kelly -pa *.changes | tee REPORT | \
     mail -s "Install for $(date +%D)" LEHOBEY@FREE.FR
chgrp debadmin REPORT
chmod 664 REPORT

cd $masterdir
symlinks -d -r $ftpdir

cd $masterdir
jenna

# Generate override files
cd $overridedir
denise

# Generate Packages and Sources files
cd $masterdir
apt-ftparchive generate apt.conf
# Generate Release files
ziyi

# Clean out old packages
rhona
shania

## Disabled currently.
##mkmaintainers
copyoverrides
mklslar
## See first dsync-flist.
##mkchecksums

rm -f $NOTICE
echo Archive maintenance finished at $(date +%X)

################################################################################

echo "Creating post-daily-cron-job backup of projectb database..."
POSTDUMP=/var/lib/dak/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)
pg_dump projectb > $POSTDUMP
(cd /var/lib/dak/backup; ln -sf $POSTDUMP current)

################################################################################

# Vacuum the database
echo "VACUUM; VACUUM ANALYZE;" | psql projectb 2>&1 | grep -v "^NOTICE:  Skipping.*only table owner can VACUUM it$"

################################################################################

# Send a report on NEW/BYHAND packages
helena | mail -e -s "NEW and BYHAND on $(date +%D)" LEHOBEY@FREE.FR
# and one on crufty packages
rene | mail -e -s "rene run for $(date +%D)" LEHOBEY@FREE.FR

################################################################################

# Run billie

time billie

################################################################################

ulimit -m 90000 -d 90000 -s 10000 -v 90000

## Disabled currently.
##run-parts --report /org/ftp.debian.org/scripts/distmnt

echo Daily cron scripts successful.