#!/bin/sh
# WARNING - DO NOT RUN THIS SCRIPT WITH SAUCE RUNNING!
# This script fixes the mess left by the site-annoy huge expiry time
# bug, by deleting all entries that have implausible timeouts.

set -e

cd /var/lib/sauce

time_t=$(date '+%s')
if test $time_t -ge 1300000000
then
	cat >&2 <<'END'
clean-site-annoy is being run _FAR_ too late.  Please consult sauce-maint.
Alternatively, simply deleting your site-annoy database is reasonably safe.
END
	exit 1
fi

for f in main log; do
	w=db.site-annoy.$f
	test -f $w || continue
	egrep -v ' 1[^0-4]| 2' $w >$w.new || test $? = 1
	rm -f $w.csa~
	ln $w $w.csa~
	mv -f $w.new $w
done
