#!/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=unbound
pkgver=1.17.0
pkgrel=01
pkgdesc="Validating, recursive, and caching DNS resolver w/o systemd"
arch=(x86_64)
url="https://unbound.net/"
depends=(dnssec-anchors fstrm hiredis ldns libevent libnghttp2 libsodium openssl)
makedepends=(expat protobuf-c python swig )
optdepends=(
  'expat: for unbound-anchor'
  'sh: for unbound-control-setup'
  'python: for python-bindings'
)
provides=(libunbound.so)
backup=(etc/$pkgname/$pkgname.conf)
source=(
  https://unbound.net/downloads/$pkgname-$pkgver.tar.gz{,.asc}
  $pkgname-1.14.0-trust_anchor_file.patch
  $pkgname-sysusers.conf
  $pkgname-tmpfiles.conf
  $pkgname-trusted-key.hook
)

prepare() {
  # enable trusted-anchor-file and set it to an unbound specific location
  patch -p1 -d $pkgname-$pkgver -i ../$pkgname-1.14.0-trust_anchor_file.patch
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  cd $pkgname-$pkgver
  ./configure \
              --prefix=/usr \
              --sysconfdir=/etc \
              --localstatedir=/var \
              --sbindir=/usr/bin \
              --disable-rpath \
              --enable-dnscrypt \
              --enable-dnstap \
              --enable-pie \
              --enable-relro-now \
              --enable-subnet \
              --disable-systemd \
              --disable-ipv6 \
              --enable-tfo-client \
              --enable-tfo-server \
              --enable-cachedb \
              --with-libhiredis \
              --with-conf-file=/etc/unbound/unbound.conf \
              --with-pidfile=/run/unbound.pid \
              --with-rootkey-file=/etc/trusted-key.key \
              --with-libevent \
              --with-libnghttp2 \
              --with-pyunbound
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd ${pkgname}-${pkgver}
  make -k check
}

package() {
  depends+=(libprotobuf-c.so)

  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install
#  install -vDm 644 contrib/${pkgname}.service -t "${pkgdir}"/usr/lib/systemd/system/
  install -vDm 644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/
  install -vDm 644 ../${pkgname}-sysusers.conf "${pkgdir}"/usr/lib/sysusers.d/${pkgname}.conf
  install -vDm 644 ../${pkgname}-tmpfiles.conf "${pkgdir}"/usr/lib/tmpfiles.d/${pkgname}.conf
  # libalpm hook to copy the dnssec-anchors provided key to /etc/unbound
  install -vDm 644 ../unbound-trusted-key.hook -t "${pkgdir}"/usr/share/libalpm/hooks/
}

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

license=(BSD)

validpgpkeys=(EDFAA3F2CA4E6EB05681AF8E9F6F1C2D7E045F8D) # W.C.A. Wijngaards <wouter@nlnetlabs.nl>

sha256sums=(dcbc95d7891d9f910c66e4edc9f1f2fde4dea2eec18e3af9f75aed44a02f1341 # unbound-1.17.0.tar.gz
	4b0bf5e596e24c7675a3a28e78adfb33c7716750e0d41b4172337e1d03eb859f # unbound-1.17.0.tar.gz.asc
	8e6e831e87484f8969a79bcd216b08b147935597c303101dad7ea1eb4cf3d326 # unbound-1.14.0-trust_anchor_file.patch
	85b8f00881fb93bcce83bdfe3246463a396eb5b352c0d7f5fca32fcb839d22fa # unbound-sysusers.conf
	31a573f43287dd7e3678be1680388bfc7d8dee8280eb2443f521a4b349aaa6b6 # unbound-tmpfiles.conf
	afb7a0a5e2da327c27c8f666b1ffaf34689121684c301928624221ac1d0c066a) # unbound-trusted-key.hook
 
