#!/bin/sh
#
#       update-squidguard  -  db update script for SquidGuard
#
#       Copyright 2003 Ivan E. Moore II <rkrusty at debian.org>
#       Copyright 2010-2011 Joachim Wiedorn <ad_debian at joonet.de>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License version 2 as 
#       published by the Free Software Foundation.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

echo "Double checking directory and file permissions..."
chown -R proxy.proxy /var/lib/squidguard/db   1>/dev/null
chmod 2770 /var/lib/squidguard/db          1>/dev/null

LOGDIR=/var/log/squid
LOGFILE=squidGuard.log
if test ! -f ${LOGDIR}/${LOGFILE}; then
	echo "Create logfile for squidguard..."
	test -d ${LOGDIR} || mkdir -p ${LOGDIR}
	touch ${LOGDIR}/${LOGFILE}
fi
chown -R proxy.proxy /var/log/squid     1>/dev/null
chgrp proxy /etc/squid/squidGuard.conf  1>/dev/null

echo "Re-building SquidGuard database (this can take a while)..."
su - proxy -c "squidGuard -C all"
echo "Update finished!"

if [ -e /etc/init.d/squid3 ]; then
	/etc/init.d/squid3 reload
elif [ -e /etc/init.d/squid ]; then
	/etc/init.d/squid reload
else
	echo "No init script found for reloading Squid!"
fi

