# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=ospd-openvas
pkgver=22.8.1
pkgrel=0
pkgdesc="ospd-openvas is an OSP server implementation to allow GVM to remotely control an OpenVAS Scanner"
url="https://github.com/greenbone/ospd-openvas"
arch="noarch"
license="AGPL-3.0-or-later"
pkgusers="gvm"
pkggroups="gvm"
depends="
	py3-defusedxml
	py3-deprecated
	py3-gnupg
	py3-lxml
	py3-packaging
	py3-paho-mqtt
	py3-psutil
	py3-redis
	mosquitto
	"
makedepends="py3-gpep517 py3-installer py3-poetry-core"
checkdepends="py3-pytest py3-gnupg"
subpackages="$pkgname-openrc $pkgname-pyc"
install="$pkgname.post-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/ospd-openvas/archive/v$pkgver.tar.gz
	$pkgname.initd
	ospd.conf
	fix-test-unlink.patch
	"
# !fhs: /run/ospd referenced in /etc/openvas/ospd.conf
options="!fhs"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	if [ $arch = "x86" ]; then
		pytest --deselect tests/messaging/test_mqtt.py::MQTTDaemonTestCase
	else
		python3 -m venv --clear --without-pip --system-site-packages .testenv
		.testenv/bin/python3 -m installer .dist/*.whl
		.testenv/bin/python3 -m pytest
	fi
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
	install -d -o $pkgusers -g $pkggroups "$pkgdir"/run/ospd
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/ospd.conf "$pkgdir"/etc/openvas/ospd.conf
}

sha512sums="
60c9a4d0ff4600a763baddf0fd96036663947b5f313946c1547fc8c59a273dba8b5573ed89736b3433688d8bf39bd9d7b089935289855e4edc8673477bb90221  ospd-openvas-22.8.1.tar.gz
264aa78a9909011de6800cf2839d2729bde4c2a8689d7a550c573d2d489c39dc224d7dc52d59210518aa1e2a9ae6a94beac978126f573bd87f378b6fa57511cf  ospd-openvas.initd
2f571f41b34599cc0fb772203f69c781f9c6b043d1451fbd0f930d8040a6888dd832578ac8afdba3015db926b51c7ada56dd435e72f9fa4fffb99d2e769d74aa  ospd.conf
d266ad2cfdcf869cdbe8cfd06a0fa354e583cc2dfa4c3aaf2b478b5af3524a2a39d53ae08ac4816881bbca264262258ed08d077dc0e5a344a9ad091cbc1a656e  fix-test-unlink.patch
"
