# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pingu
pkgver=1.5
pkgrel=1
pkgdesc="Small daemon that pings hosts and executes a script when status change"
url="https://git.alpinelinux.org/cgit/pingu"
arch="all"
license="GPL"
makedepends="libev-dev lua-dev asciidoc linux-headers"
depends=
subpackages="$pkgname-doc lua-pingu:_lua mtu"
source="pingu-$pkgver.tar.gz::https://github.com/ncopa/pingu/archive/v$pkgver.tar.gz
	pingu.initd
	"

_builddir="$srcdir"/$pkgname-$pkgver

prepare() {
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	./configure \
		--prefix=/usr \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--with-luapc=lua \
		|| return 1
	make || return 1
}

prepare() {
        local i
        cd "$_builddir"
        for i in $source; do
                case $i in
                *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
                esac
	done
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install
	install -m644 -D pingu.conf "$pkgdir"/etc/pingu/pingu.conf
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

mtu() {
	pkgdesc="Utility to detect MTU"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

_lua() {
	pkgdesc="lua module for pingu client"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib "$pkgdir"/usr/share "$subpkgdir"/usr/
}

md5sums="3454ef7723e446d917c389c0615c62b4  pingu-1.5.tar.gz
dd46546d05395893a1624e467b04b1d4  pingu.initd"
sha256sums="1caaef8765e7bd6950be8109a58187ad529237eec89742d923c1888f4c2a9f6d  pingu-1.5.tar.gz
1d4388e96a257c0bc01a585df36c0e6bc6c1ba53c9bb0b67290eaff7e8a6d1b3  pingu.initd"
sha512sums="71e5fbe93f831f24d168957cdeaff2817a22f407575316d6515755bec760d10724821070549eaab562924237b96976a1a776ca903d5fe0cd9f9b69a38eadd8c9  pingu-1.5.tar.gz
93859ab4e84d07c776915045b3fe533de551c55465dab4aa283f5606c0e8a439875f91e0e1db419bc97b01f7e4c4b0f5d434885edcf9ad77e6f65f6f27715de8  pingu.initd"
