# SliTaz package receipt.

PACKAGE="squidclamav"
VERSION="6.5"
CATEGORY="security"
SHORT_DESC="Antivirus redirector for Squid proxy."
MAINTAINER="pascal.bellard@slitaz.org"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://squidclamav.darold.net/"
WGET_URL="$SF_MIRROR/$PACKAGE/$TARBALL"
CONFIG_FILES="/etc/squidclamav.conf"

DEPENDS="squid libcurl clamav c_icap squidguard"
BUILD_DEPENDS="curl-dev c_icap-dev"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	mkdir -p $DESTDIR/etc
	./configure \
		--prefix=/usr \
		--libdir=/usr/lib \
		--libexecdir=/var/www/cgi-bin \
		--sysconfdir=/etc \
		$CONFIGURE_ARGS &&
	make && make install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr \
		$fs/etc/squid/conf.d
	
	cp -a $install/etc $fs
	cp -a $install/usr/lib $fs/usr
	cp -a $install/var $fs/
	cp -a $stuff/icap-clamav.conf $fs/etc/squid/conf.d
	
	# Customise config file
	sed -i -e "s|^redirect.*|redirect http://localhost/cgi-bin/squidclamav/clwarn.cgi|" \
		-e "s|^#squidguard.*|squidguard /usr/bin/squidGuard|" \
		$fs/etc/squidclamav.conf
		
	rm -f $fs/usr/lib/c_icap/*.la		


}

#Post install command
post_install()
{
	echo 'Service squidclamav squidclamav.so' >> $1/etc/c-icap/c-icap.conf
	if ( ps | grep -q squid ); then
		/etc/init.d/squid restart
	fi
}

#Post remove command
post_remove()
{
	sed -i -e "s/.*squidclamav.*//" $1/etc/c-icap/c-icap.conf
	if ( ps | grep -q squid ); then
		/etc/init.d/squid restart
	fi
	if ( ps | grep -q c-icap ); then
		/etc/init.d/c-icapd restart
	fi
}