
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

config etc/httpd/extra/awstats.conf.new
if ! grep '### awstats - begin ###' etc/httpd/httpd.conf > /dev/null; then
    echo Updating httpd.conf
    (
	echo "### awstats - begin ###"
	echo "#Include /etc/httpd/extra/awstats.conf"
	echo "### awstats - end ###"
	echo
	) >> etc/httpd/httpd.conf
else
    echo Note: httpd.conf already contains awstats section.
fi

config etc/cron.hourly/awstats.new

HOSTNAME=`hostname`
FQDN=$HOSTNAME.`dnsdomainname`

config etc/awstats/awstats.model.conf.new
if [ ! -r etc/awstats/awstats.conf ]; then
  sed -e 's/^DirData=.*/DirData="\/var\/lib\/awstats"/' \
      -e 's/^DirCgi=.*/DirCgi="\/awstats"/' \
      -e 's/^DirIcons=.*/DirIcons="\/awstatsicons"/' \
      -e 's/^SiteDomain=.*/SiteDomain="'$FQDN\"/ \
      -e 's/^LogFile=.*/LogFile="\/var\/log\/httpd\/access_log"/' \
      etc/awstats/awstats.model.conf > etc/awstats/awstats.conf
fi

echo
echo 'To enable awstats:'
echo '- hourly stats update via cron:'
echo '	"chmod +x /etc/cron.hourly/awstats"'
echo '- update /etc/httpd/httpd.conf.'
echo '	ensure you have "CustomLog ... combined"'
echo '	uncomment the following line:'
echo '		#Include /etc/httpd/extra/awstats.conf'
echo
echo Please review installation instructions in /usr/doc/awstats-6.8/awstats_setup.html
echo
( cd usr/doc/awstats-6.8 ; rm -rf docs )
( cd usr/doc/awstats-6.8 ; ln -sf ../../share/awstats/docs docs )
