# SliTaz package receipt.

PACKAGE="privoxy"
VERSION="3.0.19-stable"
CATEGORY="network"
SHORT_DESC="Non-caching web privacy proxy."
MAINTAINER="paul@slitaz.org"
DEPENDS="zlib pcre"
BUILD_DEPENDS="zlib-dev autoconf perl m4 coreutils"
TARBALL="$PACKAGE-$VERSION-src.tar.gz"
WEB_SITE="http://www.privoxy.org/"
WGET_URL="http://downloads.sourceforge.net/ijbswa/$TARBALL"

# Rules to configure and make the package.
compile_rules()
{
	# Have to create privoxy user/group to be able to compile
	adduser -s /bin/false -H -D -u 42 privoxy
	addgroup -g 42 privoxy
	
	cd $src

	# Needs autoconf
	autoheader
	autoconf

	./configure \
		--prefix=/usr \
		--sysconfdir=/etc/privoxy \
		--infodir=/usr/share/info \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		$CONFIGURE_ARGS &&
	make && make DESTDIR=$PWD/_pkg install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/etc/init.d $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr
	cp -a $_pkg/var $fs
	cp -a $_pkg/etc $fs

	# Copy daemon from stuff
	cp $stuff/daemon-privoxy $fs/etc/init.d/privoxy
}

post_install()
{
	# adduser privoxy if needed
	if ! grep -q privoxy $1/etc/passwd; then
		echo -n "Adding user privoxy..."
		chroot $1/ adduser -s /bin/false -H -D -u 42 privoxy
		status
	fi

	if ! grep -q privoxy $1/etc/group; then
		echo -n "Adding group privoxy..."
		chroot $1/ addgroup -g 42 privoxy
		status
	fi

	# and change file permissions
	echo -n "Changing file permissions..."
	chown -R privoxy.privoxy $1/etc/privoxy
	chown -R root.root $1/etc/privoxy/templates
	chown root.root $1/etc/privoxy
	chown privoxy.privoxy $1/var/log/privoxy/logfile
	status
}

# Del user privoxy when pkg is removed.
post_remove()
{
	deluser privoxy
	delgroup privoxy
}