# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=miniupnpd
pkgver=2.3.3
pkgrel=0
pkgdesc="Lightweight UPnP IGD daemon"
url="http://miniupnp.free.fr"
arch="all"
license="BSD-3-Clause"
install="$pkgname.post-install"
depends="uuidgen"
makedepends="bsd-compat-headers iptables-dev libnfnetlink-dev openssl-dev>3"
checkdepends="util-linux-dev"
subpackages="$pkgname-doc $pkgname-openrc
	$pkgname-iptables:_fwscripts:noarch
	$pkgname-ip6tables:_fwscripts:noarch
	"
source="http://miniupnp.free.fr/files/miniupnpd-$pkgver.tar.gz
	$pkgname.initd
"

# secfixes:
#   2.2.2-r0:
#     - CVE-2019-12107
#     - CVE-2019-12108
#     - CVE-2019-12109
#     - CVE-2019-12110
#     - CVE-2019-12111

build() {
	./configure \
		--vendorcfg \
		--leasefile \
		--ipv6 \
		--igd2
	make ISGITREPO=""
}

check() {
	make check ISGITREPO=""
}

package() {
	make PREFIX="$pkgdir/" ISGITREPO="" install
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

_fwscripts() {
	depends=
	local _tables=${subpkgname#$pkgname-}
	pkgdesc="$_tables scripts for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel $_tables"
	amove	/etc/miniupnpd/${_tables}_init.sh \
		/etc/miniupnpd/${_tables}_removeall.sh
}

sha512sums="
98915e3c1410d6753a58133596bad012fea205f36ae4991c2cf4b358d1e905e029287cfcf1aa97283c2e3c1cb8c20655bff35d49a37ae8756739e33c4ae3e7ef  miniupnpd-2.3.3.tar.gz
3619d66b5d27369e9ae368f189fc4f4e25a803b460a954f47fd749195755bda8e828fbaa4e04ffc980aa72078f790d41a313c2ab7d0de7d4c284251a577b7a90  miniupnpd.initd
"
