# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=pmacct
pkgver=1.7.0
pkgrel=0
pkgdesc="Measure, account, classify, aggregate and export IPv4 and IPv6 traffic"
url="http://www.pmacct.net/"
arch="all"
license="GPL"
makedepends="bsd-compat-headers libpcap-dev mariadb-connector-c-dev postgresql-dev
	zlib-dev jansson-dev sqlite-dev"
subpackages="$pkgname-doc"
source="http://www.pmacct.net/$pkgname-$pkgver.tar.gz
	mariadb.patch
	pmacct.initd
	pmacct.confd
	pmacctd.conf
	sfacctd.conf
	nfacctd.conf
	uacctd.conf"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	update_config_sub
}

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-pgsql \
		--enable-64bit \
		--enable-threads \
		--enable-mysql \
		--enable-sqlite3 \
		--enable-ipv6 \
		--enable-v4-mapped \
		--enable-jansson \
		|| return 1
	make || return 1
}

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/pmacctd
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/pmacctd
	install -m644 -D "$srcdir"/pmacctd.conf "$pkgdir"/etc/pmacctd.conf
	install -m644 -D "$srcdir"/nfacctd.conf "$pkgdir"/etc/nfacctd.conf
	install -m644 -D "$srcdir"/sfacctd.conf "$pkgdir"/etc/sfacctd.conf
	install -m644 -D "$srcdir"/uacctd.conf "$pkgdir"/etc/uacctd.conf
	ln -s /etc/init.d/pmacctd "$pkgdir"/etc/init.d/nfacctd &>/dev/null
	ln -s /etc/init.d/pmacctd "$pkgdir"/etc/init.d/sfacctd &>/dev/null
	ln -s /etc/init.d/pmacctd "$pkgdir"/etc/init.d/uacctd &>/dev/null
	mkdir -p $pkgdir/usr/share/doc/pmacct/examples
	mkdir -p $pkgdir/usr/share/doc/pmacct/sql
	cp -r examples/* $pkgdir/usr/share/doc/pmacct/examples
	cp sql/README.* $pkgdir/usr/share/doc/pmacct
	cp sql/* $pkgdir/usr/share/doc/pmacct/sql
}

sha512sums="14f1cecc562f008d9b79259f885fc3a1d0a74efa4840d6150277c9bb3c67a233ca9a6b921d9d83fd488d1eb6f535075d7fbf53de0036c48611ffcbf5eb7559b5  pmacct-1.7.0.tar.gz
dab77f60a6ef1914eaa817d1faeee7bdae0ffbde9f7473d43495b1ee3087ac826735f5a0f30f7cadacfa82a03731a506fc40f5c08aa1fdcfb34bcee370460039  mariadb.patch
b109f2d64c83d6749a8c81784204e54a68ec7bbc146242f02e1fa7061647acc887921cdbf90a5ecc81186a87a5b4a5175a3b5e25f92e51b5dd1426fb390ef754  pmacct.initd
6078607dde8619f8fa5698f217c40a7e46ed85843923abecc87652d2e9df6db677898ee1965367247e6ac838d907533a8b1c7ab0515f3f2dc6f3fd4eb14bd5be  pmacct.confd
fa1ead3ee4374ad84cccc0e7043fc86e95da555e2bde3815f03953587f03a609ec3aea227ebf85c9636e071921c5b094359d71d15055f866c05e113cda3b347b  pmacctd.conf
b0547fa413108087aacff490fa9f9aa5c9114acb82f40903a8150a47ffdb72765c52ce708c2feaa6fd225469ee8b7a4f1bfa3e48e512f6e8ffecb83d483cdec4  sfacctd.conf
acb3c869f3e553ba10ab76e302e37f47391b4ddf1b2531ca00017b843750d7224a67a85516acc94c1016759ecf0fb874103d913e599672a5c279345067f40d45  nfacctd.conf
b0547fa413108087aacff490fa9f9aa5c9114acb82f40903a8150a47ffdb72765c52ce708c2feaa6fd225469ee8b7a4f1bfa3e48e512f6e8ffecb83d483cdec4  uacctd.conf"
