#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname='gnunet'
pkgver=0.16.3.r0.g4e5747f9a
pkgrel=1
pkgdesc='A framework for secure peer-to-peer networking'
arch=('x86_64')
url="http://${pkgname}.org"
conflicts=("${pkgname}-git" "${pkgname}-bin")
provides=("${pkgname}" GNUnet)
depends=('brotli' 'gettext' 'gnurl' 'gnutls' 'iptables' 'jansson'
         'libextractor' 'libgcrypt' 'libidn2' 'libmicrohttpd' 'libsodium'
         'libtool' 'libunistring' 'nss' 'openssl' 'sqlite' 'which' 'zlib'
	'net-tools')
makedepends=('bluez-libs' 'gettext' 'git' 'libtool' 'opus'
             'pkgconfig' 'postgresql' 'python' 'recutils')
optdepends=('bluez: for bluetooth transport'
            'gnunet-gtk: for handling the gnunet:// URI scheme'
            'libgabe: for Attribute-Based Encryption'
	    'libogg: for conversation service'
            'libpabc: for re:claimID zero-knowledge privacy credentials'
	    'libpulse: for conversation service'
            'miniupnpc: for NAT uPnP support'
            'mysql: for an alternative to sqlite in the database plugin'
	    'opus: for conversation service'
            'pbc: for Attribute-Based Encryption'
            'postgresql: for an alternative to sqlite in the database plugin'
            'python: for test suite'
            'texi2mdoc: for automatic mdoc generation'
            'texinfo: for building the documentation'
            'texlive-core: for generating GNS business cards via gnunet-bcd'
            'zbar: for reading/writing QR codes using gnunet-qr')
backup=("etc/${pkgname}.conf")
source=("git+https://git.${pkgname}.org/${pkgname}.git"
        "${pkgname}.sysusers"
        "${pkgname}.tmpfiles"
        "${pkgname}-uri.desktop"
        "${pkgname}-user.conf")
install="${pkgname}.install"

pkgver() {

	cd "${pkgname}" > /dev/null 2>&1
	git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'

}

prepare() {

	cd "${srcdir}/${pkgname}"
	export GNUNET_PREFIX='/usr/lib'

	./bootstrap

}

build() {

	cd "${srcdir}/${pkgname}"

	./configure --prefix='/usr' \
		--bindir=/usr/bin \
		--sbindir=/usr/bin \
		--libdir=/usr/lib \
		--with-pulse=no \
		--enable-experimental

	make
	make -C contrib

}

package() {

	cd "${srcdir}/${pkgname}"

	make DESTDIR="${pkgdir}" install
	make DESTDIR="${pkgdir}" -C contrib install

	install -dm755 "${pkgdir}/usr/lib/sysusers.d"
	install -Dm644 "${srcdir}/${pkgname}.sysusers" \
		"${pkgdir}/usr/lib/sysusers.d/${pkgname}.conf"

	install -dm755 "${pkgdir}/usr/lib/tmpfiles.d"
	install -Dm644 "${srcdir}/${pkgname}.tmpfiles" \
		"${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"

	install -dm755 "${pkgdir}/usr/share/applications"
	install -Dm644 "${srcdir}/${pkgname}-uri.desktop" \
		"${pkgdir}/usr/share/applications/${pkgname}-uri.desktop"

	install -dm700 "${pkgdir}/etc/skel/.config"
	install -Dm600 "${srcdir}/${pkgname}-user.conf" \
		"${pkgdir}/etc/skel/.config/${pkgname}.conf"

	# Automatically generate a configuration file using the content of
	# `/usr/share/gnunet/config.d/` as model; in this way we can ensure
	# that this configuration file is the one backed up with each update,
	# while `/usr/share/gnunet/config.d/` is kept as immutable default
	# configuration.

	install -dm755 "${pkgdir}/etc"

	{
		echo "# /etc/${pkgname}.conf"
		(cd "${pkgdir}" > /dev/null 2>&1 && find "usr/share/${pkgname}/config.d" -type f -name '*.conf' \
			-printf '\n\n# For the default values of the the following lines please refer to\n# /%p\n\n' \
			-exec cat '{}' ';')
	} > "${pkgdir}/etc/${pkgname}.conf"

}

#---- license gpg-key sha256sums ----

license=('AGPL')

sha256sums=('SKIP'
	66299dbbdd0219d2f5f0520e69fc094f38f789724d973c2f63a421257ea4f755 # gnunet.sysusers
	5c34e1ecc6208900426f8e399e8c3edbef12cce19eba605fd7364ddb3547d9f0 # gnunet.tmpfiles
	98e4e1d6d4fd7c7fd05d9e16402c95f1e7afeb4b97c8c68ac63e8abd11ff4ee7 # gnunet-uri.desktop
	3f17b9ed2c1f8cc0f919fe477df99678c17778a31f1eeb56517e285e3cef30f2) # gnunet-user.conf
