#!/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 |---------------------------------------
# This package spans multiple repositories.
# Always build from cyrus-sasl/trunk and merge changes to libsasl/trunk.

# NOTE: upgrade cyrus-sasl in tandem with core/libsasl
# As one PKGBUILD can (currently) not provide packages for several
# repositories, libsasl and the rest of cyrus-sasl are provided separately
# (else this would require mariadb and postgresql in [core])
pkgbase=cyrus-sasl
pkgname=(cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-ldap cyrus-sasl-sql)
pkgver=2.1.28
pkgrel=03  ## rebuilt due to Obarun's update of postgresql
pkgdesc="Cyrus Simple Authentication Service Layer (SASL) library"
arch=('x86_64')
url="https://www.cyrusimap.org/sasl/"
options=('!makeflags')
makedepends=('postgresql-libs' 'mariadb-libs' 'libldap' 'krb5' 'openssl' 'sqlite')
source=(https://github.com/cyrusimap/$pkgbase/releases/download/$pkgbase-$pkgver/$pkgbase-$pkgver.tar.gz{,.sig}
        saslauthd.conf.d
        tmpfiles.conf)

prepare() {
  cd $pkgbase-$pkgver
  autoreconf -fiv
}

build() {
  cd $pkgbase-$pkgver
  ./configure --prefix=/usr \
      --disable-krb4 \
      --disable-macos-framework \
      --disable-otp \
      --disable-passdss \
      --disable-srp \
      --disable-srp-setpass \
      --disable-static \
      --enable-alwaystrue \
      --enable-anon \
      --enable-auth-sasldb \
      --enable-checkapop \
      --enable-cram \
      --enable-digest \
      --enable-gssapi \
      --enable-ldapdb \
      --enable-login \
      --enable-ntlm \
      --enable-plain \
      --enable-shared \
      --enable-sql \
      --infodir=/usr/share/info \
      --mandir=/usr/share/man \
      --sbin=/usr/bin \
      --sysconfdir=/etc \
      --with-dblib=gdbm \
      --with-devrandom=/dev/urandom \
      --with-configdir=/etc/sasl2:/etc/sasl:/usr/lib/sasl2 \
      --with-ldap \
      --with-mysql=/usr \
      --with-pam \
      --with-pgsql=/usr/lib \
      --with-saslauthd=/var/run/saslauthd \
      --with-sqlite3=/usr/lib
  # prevent excessive overlinking by libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  make -k check -C $pkgbase-$pkgver
}

package_cyrus-sasl() {
  depends=(gdbm libgdbm.so glibc krb5 libkrb5.so libldap libsasl=$pkgver openssl pam libpam.so)
  pkgdesc="Cyrus saslauthd SASL authentication daemon"
  backup=(etc/conf.d/saslauthd)

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver/saslauthd
  make DESTDIR="$pkgdir" install-data-local -C $pkgbase-$pkgver/saslauthd
  install -vDm 644 $pkgbase-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"

  install -vDm 644 saslauthd.conf.d "$pkgdir/etc/conf.d/saslauthd"
#  install -vDm 644 saslauthd.service -t "$pkgdir/usr/lib/systemd/system/"
  install -vDm 644 tmpfiles.conf "$pkgdir/usr/lib/tmpfiles.d/saslauthd.conf"
}

package_cyrus-sasl-gssapi() {
  pkgdesc="GSSAPI authentication mechanism for Cyrus SASL"
  depends=(glibc krb5 libgssapi_krb5.so libsasl=$pkgver)
  replaces=('cyrus-sasl-plugins')

  install -vdm 755 "$pkgdir/usr/lib/sasl2"
  cp -av $pkgbase-$pkgver/plugins/.libs/libgs{,sapiv}2.so* "$pkgdir/usr/lib/sasl2/"
  install -vDm 644 $pkgbase-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_cyrus-sasl-ldap() {
  pkgdesc="ldapdb auxprop module for Cyrus SASL"
  depends=(glibc libldap libsasl=$pkgver)
  replaces=('cyrus-sasl-plugins')

  install -vdm 755 "$pkgdir/usr/lib/sasl2"
  cp -av $pkgbase-$pkgver/plugins/.libs/libldapdb.so* "$pkgdir/usr/lib/sasl2/"
  install -vDm 644 $pkgbase-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_cyrus-sasl-sql() {
  pkgdesc="SQL auxprop module for Cyrus SASL"
  depends=(libsasl=$pkgver mariadb-libs libmariadb.so postgresql-libs libpq.so sqlite)
  replaces=('cyrus-sasl-plugins')

  install -vdm 755 "$pkgdir/usr/lib/sasl2"
  cp -av $pkgbase-$pkgver/plugins/.libs/libsql.so* "$pkgdir/usr/lib/sasl2/"
  install -vDm 644 $pkgbase-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
}

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

license=('custom')

validpgpkeys=(829F339F8C296FE80F409D93E3D7C118C7B9F46A  # Partha Susarla <mail@spartha.org>
	DEA1999F0CDB1AAEBA001E0DBEE3E3B4D2F06546) # Quanah Gibson-Mount <quanah@fast-mail.org>

sha256sums=(7ccfc6abd01ed67c1a0924b353e526f1b766b21f42d4562ee635a8ebfc5bb38c # cyrus-sasl-2.1.28.tar.gz
	e6169548f42234eb2b1af9719415016a57116835b8ea494596f52743b49971fd # cyrus-sasl-2.1.28.tar.gz.sig
	fa57b4f374ae633633091b1c8b44e1e0be814e4fddbfa75f16eb3dd1f16b8640 # saslauthd.conf.d
	16ca1a4185847b0c6c70ef6c7c314cb466f698d3ed02185a5f50e8179822f024) # tmpfiles.conf
 
