# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

IUSE="berkdb debug mysql postgres" # apache1 apache2"
DESCRIPTION="NeTAMS - Network Traffic Accounting and Monitoring Software"
HOMEPAGE="http://www.netams.com"
LICENSE="BSD"
SRC_URI="http://www.netams.com/files/${P}.tar.gz"
SLOT="0"
KEYWORDS="~x86 ~amd64"

DEPEND="berkdb? (sys-libs/db)
	mysql? ( >=dev-db/mysql-4)
	postgres? ( >=dev-db/postgresql-7.4 )
	net-firewall/iptables
	>=net-libs/libpcap-0.7
	"
#	apache1? ( =net-www/apache-1* )
#	apache2? ( >=net-www/apache-2 )
#	"
	# FIXME list is not complete
	# version of postgresql?
	# really libpcap not needed, this is optional

src_unpack() {
	unpack ${A} ; cd ${S}
	# disable debug mode
	if use !debug
	then
		sed -ie "s:if \[ ! \"x\$1\" = \"x-nodebug:if \[ \"x\$1\" = \"x-nodebug:g" configure.sh
	fi
	# adding $CFLAGS support
	cd ${S}/addon
	`sed -ie "s:FLAGS  += -pipe -O2:FLAGS  += $CFLAGS:g" Makefile.common`
}
src_compile() {
# FIXME work around configuring
	emake -j1 || die "emake failed" # no accept $MAKEOPTS
}

src_install() {
	dosbin src/netams src/netamsctl src/flowprobe src/ipfw2netflow src/ulog2netflow
	insinto /etc/init.d
	newins addon/netams-gentoo.sh netams
	insinto /etc
	insopts -m0644
	newins addon/netams.cfg netams.cfg.sample
	doman doc/*.8
	dodoc doc/README doc/TODO.txt
	dodir /usr/share/${PN}
	insinto /usr/share/${PN}
	doins -r \
		addon/ru-networks.txt \
		addon/ua-networks-get.sh \
		addon/mysql_rotate.pl \
		addon/postgresql_schema.sql \
		cgi-bin \
		# where place it?
		# for apache - /var/www/localhost
		addon/oracle
}

pkg_postinst()
{
	ewarn ""
	ewarn "CGI scripts are installed into /usr/share/${PN}/cgi-bin"
	ewarn "You should copy them to appropriate place."
	ewarn "Example of config file placed into /etc/${PN}.cfg.sample"
	ewarn "For autostart type"
	ewarn "    rc-update add netams default"
	ewarn ""
	ewarn "And PLEASE READ THE DOCUMENTATION FIRST!"
	ewarn "${HOMEPAGE}/doc/index.html"
	ewarn ""
}