-#!/bin/sh
+#!/bin/bash
#
-# Run once a week via cron, out of katie's crontab.
set -e
-export SCRIPTVARS=/srv/backports-master.debian.org/config/backports/vars
+set -o pipefail
+set -u
+# ERR traps should be inherited from functions too. (And command
+# substitutions and subshells and whatnot, but for us the functions is
+# the important part here)
+set -E
+export SCRIPTVARS=/srv/backports-master.debian.org/dak/config/backports/vars
. $SCRIPTVARS
+# Start logging
+NOW=`date "+%Y.%m.%d-%H:%M:%S"`
+LOGFILE="$logdir/weekly_${NOW}.log"
+exec > "$LOGFILE" 2>&1
+
+cleanup() {
+ echo "Cleanup"
+ rm -f "$LOGFILE"
+}
+trap cleanup 0
+
################################################################################
# Purge empty directories
-
+echo "Purging empty directories in $ftpdir/pool/"
if [ ! -z "$(find $ftpdir/pool/ -type d -empty)" ]; then
find $ftpdir/pool/ -type d -empty | xargs rmdir;
fi
# Clean up apt-ftparchive's databases
-
cd $configdir
-apt-ftparchive -q clean apt.conf
+#echo "Cleanup apt-ftparchive's database"
+#apt-ftparchive -q clean apt.conf
+
+echo "Fixing symlinks in $ftpdir"
+symlinks -d -r $ftpdir
+
+echo "Finally, all is done, compressing logfile"
+exec > /dev/null 2>&1
+
+bzip2 -9 "$LOGFILE"
+
################################################################################