#!/bin/sh
# $Id: dwww.cron.daily,v 1.11 2003/02/25 22:01:45 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"

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
