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

pkgname=gnupg
pkgver=2.4.3
pkgrel=02
pkgdesc='Complete and free implementation of the OpenPGP standard w/o systemd'
url='https://www.gnupg.org/'
depends=(bzip2 libbz2.so glibc gnutls libgcrypt
  libgpg-error libksba libassuan libassuan.so npth
  libldap libusb libnpth.so pinentry readline 
  libreadline.so sh sqlite  tpm2-tss zlib)
checkdepends=('openssh')
makedepends=('pcsclite' 'automake' 'autoconf' 'gettext')
optdepends=('pcsclite: for using scdaemon not with the gnupg internal card driver')

# options=('debug')  ###  uncomment this line to have the debug pkg produced
source=("https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2"{,.sig}
	$pkgname-2.4-avoid_beta_warning.patch  # do not emit beta warnings (due to misbehaving build system)
	$pkgname-2.4-drop_import_clean.patch  # do not potentially remove components on certificates during import
	$pkgname-2.4-revert_default_rfc4880bis.patch)  # v5 is incompatible with other implementations and v6

# install=$pkgname.install  ###  this was for linking systemd sockets and such crap !!

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    msg2 "Applying patch $src..."
    patch -Np1 < "../$src"
  done

  # improve reproducibility
  rm doc/gnupg.info*

  ./autogen.sh
}

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--sbindir=/usr/bin \
		--libexecdir=/usr/lib/gnupg \
		--enable-maintainer-mode \
		--disable-systemd

	make
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make check
}

package() {
  local units=({dirmngr,gpg-agent{,-{browser,extra,ssh}}}.socket)

	local unit
	cd "${srcdir}/${pkgname}-${pkgver}"
	make DESTDIR="${pkgdir}" install
	ln -s gpg "${pkgdir}"/usr/bin/gpg2
	ln -s gpgv "${pkgdir}"/usr/bin/gpgv2
	install -Dm 644 COPYING.{CC0,other} -t "${pkgdir}/usr/share/licenses/$pkgname/"
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=(BSD-2-Clause BSD-3-Clause CC0-1.0 GPL-2.0-or-later GPL-3.0-or-later LGPL-2.1-or-later 'LGPL-3.0-or-later OR GPL-2.0-or-later' MIT Unicode-TOU)

validpgpkeys=(5B80C5754298F0CB55D8ED6ABCEF7E294B092E28 # Andre Heinecke (Release Signing Key)
	6DAA6E64A76D2840571B4902528897B826403ADA # Werner Koch (dist signing 2020)
	AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD # Niibe Yutaka (GnuPG Release Key)
	02F38DFF731FF97CB039A1DA549E695E905BA208) # GnuPG.com (Release Signing Key 2021)

sha256sums=(a271ae6d732f6f4d80c258ad9ee88dd9c94c8fdc33c3e45328c4d7c126bd219d  # gnupg-2.4.3.tar.bz2
	b31501d6f81bd75c2bf874cb12f74fd6dd21665e91ed2348d05f5c08f8ac6a40  # gnupg-2.4.3.tar.bz2.sig
	243c3a79295519b3931f9d846cf2af5caa064a78de812ee336dc786c1567b4d0  # gnupg-2.4-avoid_beta_warning.patch
	6ade15b536c50a88efc2d9dc958433b0ccfaf2908025b7672753e6bfce51c3c6  # gnupg-2.4-drop_import_clean.patch
	ef2267eecd9eb59bbbbdb97d55cbfe10236b4979a125c6683a840830bc202905) # gnupg-2.4-revert_default_rfc4880bis.patch

##  160195f1668cc7dc2cff69c8f6db25f9fcf816cf1d195fa7f5e1ea49d10295ec  gnupg-2.4.3-02-x86_64.pkg.tar.lz

