# SliTaz package receipt.

PACKAGE="ntop"
VERSION="4.1.0"
CATEGORY="network"
SHORT_DESC="Network traffic probe."
MAINTAINER="pascal.bellard@slitaz.org"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://www.ntop.org/"
WGET_URL="$SF_MIRROR/$PACKAGE/$TARBALL"
CONFIG_FILES="/etc/ntop"
TAGS="network"

DEPENDS="zlib openssl libpng libpcap glibc gdbm rrdtool perl pcre geoip libwrap"
BUILD_DEPENDS="zlib-dev openssl-dev libpng-dev libpcap-dev libtool glibc-dev gdbm-dev rrdtool \
 autoconf automake rrdtool-dev wget geoip-dev libwrap"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	./autogen.sh --prefix=/usr	\
		--sysconfdir=/etc \
		--localstatedir=/var/lib $CONFIGURE_ARGS &&
	make &&
make DESTDIR=$PWD/_pkg install 
#~ && make install-data-as
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/lib/plugins \
		$fs/usr/share \
		$fs/var/log/ntop

	cp -a $_pkg/usr/lib/*.so* $fs/usr/lib
	cp -a $_pkg/usr/lib/ntop $fs/usr/lib
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/share/ntop $fs/usr/share
	chown -R www.www $fs/usr/share/ntop
	cp -a $_pkg/usr/bin $fs
	cp -a $_pkg/etc $fs
	cp -a $_pkg/var $fs
	
	# Copy startup script and fix perms
	cp -a stuff/etc $fs
	chown root.root $fs/etc/init.d/ntop
}

post_install()
{
	user=ntop
	group=ntop
	
	if ! grep -q $user: $1/etc/passwd; then
		echo -n "Adding user/group $user..."
		chroot $1/ addgroup -S $user
		chroot $1/ adduser -S -D -H -G $group $user
		status
	fi
	
	# Fix perms for files and directories
	chroot $1/ chown -R ${user}.${group} /var/lib/ntop /var/log/ntop
		
	# Start package daemon if we are  on running system
	[ -z $1 ] && /etc/init.d/$PACKAGE start
	
	# post_install messges
	echo -e "\nTo starts $PACKAGE server you can run :\n"
	echo "/etc/init.d/$PACKAGE start"
	echo -e "Or add $PACKAGE to RUN_DAEMONS in /etc/rcS.conf\n"
}

pre_remove()
{
	[ -z $1 ] && /etc/init.d/$PACKAGE stop
}

post_remove()
{
        user=ntop
        group=ntop

	if ! grep -q $user: $1/etc/passwd; then
        	echo -n "Removing user/group $user..."
                chroot $1/ delgroup $user
                chroot $1/ deluser  $user
                status
       	fi
}