#!/bin/sh
#
# This housekeeping shell script is installed as /etc/cron.daily/dwww.
# Cron automatically runs it once a day.
#
# This script re-builds the dwww web pages, and removes old documents
# from the cache that have not been accessed for some number of days.
# The number of days should be configured by setting the DWWW_KEEPDAYS
# variable in /etc/dwww/dwww.conf.  The value set in this script is a
# default; don't modify it, or an upgrade will wipe out your modification.

# check if dwww is still installed
test -x /usr/sbin/dwww-build || exit 0

set -e

. /usr/share/dwww/functions.sh && dwww_initialize  || exit 1

dwww-build --default >/dev/null
dpkg --search '*' | dwww-quickfind --build $DWWW_QUICKFIND_DB.new
mv -f $DWWW_QUICKFIND_DB.new $DWWW_QUICKFIND_DB
find /var/cache/dwww -atime +$DWWW_KEEPDAYS -name '[^.]*' \
	-maxdepth 2 -type f -print0 | xargs -0 rm -f
cd /var/cache/dwww
su -s /bin/sh $DWWW_CGIUSER -c '/usr/sbin/dwww-cache --clean'
exit 0
