# Contributor: xrs <xrs@mail36.net>
# Maintainer: xrs <xrs@mail36.net>
pkgname=gnunet
pkgver=0.11.6
pkgrel=0
pkgdesc="A framework for secure and privacy enhancing peer-to-peer networking"
url="https://gnunet.org"
arch="all"
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"
makedepends="$depends_dev autoconf automake libtool gettext-dev python3
	texlive texinfo"
install="$pkgname.pre-install $pkgname.post-install $pkgname.pre-deinstall"
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.xsession
	"

prepare() {
	default_prepare
	autoreconf -if # FIXME: See https://bugs.gnunet.org/view.php?id=5902
}

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

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

package() {
	make DESTDIR="$pkgdir" install

	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.xsession \
		$pkgdir/etc/X11/xinit/xinitrc.d/80-$pkgname-user-services
}

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="1c6ea2ac7280d2edb30df627b79e017d199e93cd3970ce49f3f049abfb1dddfed541118e55766c422edf4a80e140c4eb2cfc681e0d4a1384e39811d024df9278  gnunet-0.11.6.tar.gz
a0f55413ed2c6edd6746a751d92ddac95ba70f20eefb07330817870d749456448f44bba95d245911a00f6078e0c2ac626004e3b764be5e5e049c00626c4c5ac0  gnunet-system.conf
b21112ff16aee771332aa9c33f55b0c7f46fe0266053543241e3efbe25dba56482c0e11112a192eefe59f1c74d2af5d7071b6a4e1e875cfc7e9d55b5fe8a0a33  gnunet-user.conf
96ab78bb48d5fb10f0b34336ad05e73b543c4362c73436ef20b3bb83dff214e997acf38a2ea493b1901bdc37c8877d83cdaebd73a0e50831e2f23413c8edda76  gnunet-system-services.initd
3dc88aaedc3886c0795bdb4c8e259125232ba10f2bc762216c341bb3240ef0855cba968799ba121304463a65e73ed0f62dec03759a2be478ec4ac086361b49ba  gnunet-user-services.initd
4fe1ed80cbaa4c140805bde2629fdb32b97f3273281ae7277c8988b4e490605652cdb9975fc1178169426f2279597c55f6e6b75b52315a426d78a1fedbb08401  gnunet.xsession"
