#!/bin/sh
#
# shalla_update.sh, v 0.3 20070418
# done by kapivie at sil.at under FreeBSD
# without any warranty
#
#--------------------------------------------------
# little script (for crond)
# to fetch and modify new list from shalla.de
#--------------------------------------------------
#
# *check* paths and squidGuard-owner on your system
# try i.e. "which squid" to find out the path for squid
# try "ps aux | grep squid" to find out the owner for squidGuard
#     *needs wget*
#

squidGuardpath="/usr/bin/squidGuard"
squidpath="/usr/sbin/squid"
httpget="/usr/bin/wget"
tarpath="/bin/tar"
chownpath="/bin/chown"

dbhome="/var/squidGuard/blacklists"     # like in squidGuard.conf
squidGuardowner="squid:squid"

##########################################

workdir="/tmp"
shallalist="http://www.shallalist.de/Downloads/shallalist.tar.gz"


# download actual shalla's blacklist
# thanks for the " || exit 1 " hint to Rich Wales
echo "getting new tarball..."
$httpget $shallalist -O $workdir/shallalist.tar.gz || exit 1
echo "unpacking the tarball..."
$tarpath xzf $workdir/shallalist.tar.gz -C $workdir || exit 1

# create new local database
echo "removing old database..."
rm -r $dbhome
echo "creating new database..."
mv $workdir/BL $dbhome
echo "bringing on-line the new database..."
$squidGuardpath -C all

echo "changing database ownership to squid..."
$chownpath -R $squidGuardowner $dbhome

echo "reconfiguring squid..."
$squidpath -k reconfigure

echo "all done"


