# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer:
pkgname=netdata
pkgver=1.9.0
pkgrel=0
pkgdesc="Real-time performance monitoring"
url="https://github.com/firehol/netdata"
license="GPL-3.0-or-later"
arch="all"
depends="bash"
makedepends="zlib-dev e2fsprogs-dev"
pkgusers="netdata"
pkggroups="netdata"
subpackages="$pkgname-nodejs::noarch $pkgname-python::noarch"
install="$pkgname.pre-install"
source="https://github.com/firehol/netdata/releases/download/v$pkgver/netdata-$pkgver.tar.xz
	$pkgname.initd"
builddir="$srcdir"/$pkgname-$pkgver

build() {
	cd "$builddir"
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--with-zlib \
		--with-math \
		--with-webdir=/usr/share/webapss/netdata \
		--with-user=netdata
	make
}

check() {
	cd "$builddir"
	make check
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	chgrp -R $pkggroups "$pkgdir"/usr/share/webapss/netdata
	chown -R $pkgusers:$pkggroups $pkgdir/var/lib/netdata \
		$pkgdir/var/cache/netdata
	install -Dm755 $srcdir/$pkgname.initd \
		$pkgdir/etc/init.d/$pkgname
	install -Dm644 ./system/netdata.conf $pkgdir/etc/netdata/netdata.conf
}

nodejs() {
	pkgdesc="$pkgdesc (nodejs support)"
	depends="$pkgname nodejs"
	mkdir -p "$subpkgdir"/usr/libexec/netdata
	mv $pkgdir/usr/libexec/netdata/node.d \
		$subpkgdir/usr/libexec/netdata
}

python() {
	pkgdesc="$pkgdesc (python support)"
	depends="$pkgname python2"
	mkdir -p "$subpkgdir"/usr/libexec/netdata
	mv $pkgdir/usr/libexec/netdata/python.d \
		"$subpkgdir"/usr/libexec/netdata
}

sha512sums="3766c8b86229545dee8fed3a43a5dd73ba36db9114b2418a6ceaaba15488edf792308be922dafed34026fd52166257fc27823ce0f6664696f79b33b93345f2b5  netdata-1.9.0.tar.xz
2aaaee7010c24b3f52be8b01295f73ac6c38ac4d1b627e8b9227d03fe3b248b7157b1d5217edebd88ba461adc1ce89503520acd877b300e4503e75125f40da96  netdata.initd"
