#!/bin/sh
# $Id: dwww.cron.daily,v 1.12 2004/04/18 16:10:38 robert Exp $
#
# 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.

# 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
dwww-build-menu      > /dev/null

dpkg --search '*' | dwww-quickfind --build "$DWWW_QUICKFIND_DB.new"
mv -f "$DWWW_QUICKFIND_DB.new" "$DWWW_QUICKFIND_DB"

if [ ! -d /var/cache/dwww ] ; then
	mkdir /var/cache/dwww
	chmod 755 /var/cache/dwww
	chown "$DWWW_CGIUSER" /var/cache/dwww
fi

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
