# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=lldpd
pkgver=1.0.19
pkgrel=0
pkgdesc="Implementation of IEEE 802.1ab"
url="https://lldpd.github.io/"
arch="all"
license="ISC"
makedepends="autoconf automake libtool linux-headers bsd-compat-headers
	libevent-dev libxml2-dev net-snmp-dev libbsd-dev jansson-dev
	doxygen perl-dev readline-dev"
install="$pkgname.post-install"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
pkgusers="lldpd"
pkggroups="lldpd"
source="$pkgname-$pkgver.tar.gz::https://github.com/vincentbernat/lldpd/archive/$pkgver.tar.gz
	$pkgname.confd
	$pkgname.initd"

# secfixes:
#   1.0.13-r0:
#     - CVE-2021-43612
#   1.0.8-r0:
#     - CVE-2020-27827

prepare() {
	# this should be shipped with the release tarball
	echo $pkgver > .dist-version
	./autogen.sh
	default_prepare
}

build() {
	./configure \
		--prefix=/usr \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--enable-static=no \
		--enable-pie \
		--enable-hardening \
		--without-embedded-libevent \
		--with-snmp \
		--with-xml \
		--with-privsep-user=$pkgusers \
		--with-privsep-group=$pkggroups \
		--with-privsep-chroot=/run/$pkgname \
		--with-lldpd-ctl-socket=/run/$pkgname/$pkgname.socket \
		--with-lldpd-pid-file=/run/$pkgname/$pkgname.pid
	make
}

check() {
	make check
}

package() {
	install -Dm644 /dev/null "$pkgdir/etc/lldpd.conf"
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir/etc/conf.d/$pkgname"
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir/etc/init.d/$pkgname"
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
	make DESTDIR="$pkgdir" install
}

sha512sums="
093389b785220d83dfd12a0d91800789dc47b006b409809ae5255baf77d01c0006ba16750aa660ac7f7e27c8afd18519758df525e8b9a9f0ade3e967a1717df3  lldpd-1.0.19.tar.gz
a2a4c85068a6b8b80c92fe56af7799a8b8cb2516e5a65b3ae4cb28f278e5acc72402da2a35f0c48a6048fd4a8536061142cafaa49a4bae8e52ca0a5d9ed38b4c  lldpd.confd
ffe1b3ca2dcd1c2c1d7ac24f2b90bd5324596bb4252be64a8be36d562df402b38341952fb00ab909706ae2fe854e205e2f48746a4b718b39d7e72ddee4af445c  lldpd.initd
"
