# Contributor: xrs <xrs@mail36.net>
# Maintainer: xrs <xrs@mail36.net>
pkgname=gnunet
pkgver=0.12.0
pkgrel=0
pkgdesc="A framework for secure and privacy enhancing peer-to-peer networking"
url="https://gnunet.org"
arch="all !ppc64le"
license="AGPL-3.0-only"
depends="gnutls-utils bash which iptables coreutils"
depends_dev="libgpg-error-dev libgcrypt-dev nettle-dev unbound-dev gnutls-dev
	gnurl-dev libmicrohttpd-dev openssl-dev libunistring-dev libidn2-dev
	nss-dev sqlite-dev zlib-dev miniupnpc-dev gmp-dev gettext openjpeg-dev
	jansson-dev"
makedepends="$depends_dev autoconf automake libtool gettext-dev python3
	texlive texinfo"
install="$pkgname.pre-install $pkgname.post-install"
pkgusers="gnunet"
pkggroups="gnunet gnunetdns"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang"
options="!check suid" # No check because The GNUnet project lacks a good CI at the moment.
source="https://mirrors.ocf.berkeley.edu/gnu/gnunet/gnunet-$pkgver.tar.gz
	gnunet-system.conf
	gnunet-user.conf
	gnunet-system-services.initd
	gnunet-user-services.initd
	gnunet-gns-proxy.initd
	"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-logging=verbose
	make
}

check() {
	make DESTDIR="$pkgdir" check
}

package() {
	make DESTDIR="$pkgdir" -j1 install # Using more CPUs generates CI-errors.

	libexecdir=$pkgdir/usr/lib/gnunet/libexec/
	# Limit access to critical gnunet-helper-dns to group "gnunetdns"
	chgrp gnunetdns $libexecdir/gnunet-helper-dns
	chgrp gnunetdns $libexecdir/gnunet-service-dns
	# Limit access to certain SUID binaries by group "gnunet"
	chgrp gnunet    $libexecdir/gnunet-helper-exit
	chgrp gnunet    $libexecdir/gnunet-helper-vpn
	chgrp gnunet    $libexecdir/gnunet-helper-nat-client
	chgrp gnunet    $libexecdir/gnunet-helper-nat-server
	chmod u+s       $libexecdir/gnunet-helper-exit
	chmod u+s       $libexecdir/gnunet-helper-vpn
	chmod 2750      $libexecdir/gnunet-helper-dns
	chmod 2700      $libexecdir/gnunet-service-dns
	chmod u+s       $libexecdir/gnunet-helper-nat-client
	chmod u+s       $libexecdir/gnunet-helper-nat-server

	install -m644 -D $srcdir/$pkgname-user.conf \
		$pkgdir/etc/skel/.config/$pkgname.conf
	install -m644 -D $srcdir/$pkgname-system.conf \
		$pkgdir/etc/$pkgname.conf
	install -m755 -D $srcdir/$pkgname-system-services.initd \
		$pkgdir/etc/init.d/$pkgname-system-services
	install -m755 -D $srcdir/$pkgname-user-services.initd \
		$pkgdir/etc/init.d/$pkgname-user-services
	install -m755 -D $srcdir/$pkgname-gns-proxy.initd \
		$pkgdir/etc/init.d/$pkgname-gns-proxy
}

dev() {
	default_dev

	# dev() will move gnunet-config from $pkg to $pkg-dev, but it's an
	# intended part of $pkg.
	install -m755 -D $builddir/src/util/.libs/gnunet-config \
		$pkgdir/usr/bin/gnunet-config
}

sha512sums="42d778eb1a7847d84255581657c1d71d12bda54f4d33e60b7a389c498d9c830b0501fe4a83725f3aa452f88875a96d5856171a686c8738f5d4ee3de06860a079  gnunet-0.12.0.tar.gz
a0f55413ed2c6edd6746a751d92ddac95ba70f20eefb07330817870d749456448f44bba95d245911a00f6078e0c2ac626004e3b764be5e5e049c00626c4c5ac0  gnunet-system.conf
b21112ff16aee771332aa9c33f55b0c7f46fe0266053543241e3efbe25dba56482c0e11112a192eefe59f1c74d2af5d7071b6a4e1e875cfc7e9d55b5fe8a0a33  gnunet-user.conf
96ab78bb48d5fb10f0b34336ad05e73b543c4362c73436ef20b3bb83dff214e997acf38a2ea493b1901bdc37c8877d83cdaebd73a0e50831e2f23413c8edda76  gnunet-system-services.initd
3dc88aaedc3886c0795bdb4c8e259125232ba10f2bc762216c341bb3240ef0855cba968799ba121304463a65e73ed0f62dec03759a2be478ec4ac086361b49ba  gnunet-user-services.initd
19c9bb3fde1fe36dd53a6181ec0f08a00ed2871bca026832983cbbe6550e258c9f3166923f2b6715fc9edb5eb0dae38d2f497f54c8ba74fdb7c483608450fa4b  gnunet-gns-proxy.initd"
