#!/bin/sh 

set -e

umask 022

doit() 
{
	if [ -f /usr/share/bugzilla3/lib/collectstats.pl \
        	-a -f /usr/share/bugzilla3/lib/whineatnews.pl ] ; then
	            su www-data -c /usr/share/bugzilla3/lib/collectstats.pl
	            su www-data -c /usr/share/bugzilla3/lib/whineatnews.pl
	fi
}

# process the main configuration: /etc/bugzilla3
doit

# then the extra sites: /etc/bugzilla3/sites/*
if [ -d /etc/bugzilla3/sites ]; then
    for site in `cd /etc/bugzilla3/sites && ls`; do
        X_BUGZILLA_SITE="$site" doit
    done
fi

# Remove old GraphViz pictures
find /var/lib/bugzilla3/data/webdot -type f -mtime +1 -exec rm {} \; || true

exit 0
