# Maintainer: Luke Shumaker <lukeshu@parabola.nu>
# Maintainer (AUR:postsrsd-git): Radek Podgorny <radek@podgorny.cz>
# Maintainer (AUR:postsrsd-git): Thomas Haider <t.haider@deprecate.de>
# Maintainer (AUR:postsrsd): fordprefect <fordprefect@dukun.de>

pkgname=postsrsd
pkgver=1.4
pkgrel=3
pkgdesc="Sender Rewriting Scheme (SRS) daemon for Postfix"
arch=('i686' 'x86_64' 'armv7h')
makedepends=('cmake' 'help2man')
backup=('etc/default/postsrsd')
url="https://github.com/roehling/postsrsd"
license=('GPL2') # postsrsd.c is GPLv2+, but the vendored libsrs2 is
                 # GPLv2|BSD3; the intersection of these is GPLv2
source=("$pkgname-$pkgver.tar.gz::https://github.com/roehling/postsrsd/archive/${pkgver}.tar.gz"
        0001-systemd-populate-SRS_DOMAIN-default-using-postconf.patch
        postsrsd-genkey.service
        postsrsd.service-genkey.conf)
md5sums=('cb6e13a06d6bbd7d383efb9bbf0867ce'
         '55c38abef2084405eee3d4b7619d71dd'
         '621d1ac7a15aec5d0cf91ec9b3ae7266'
         '3441061474bd5da0d5f8148f53b05917')

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

  local patch
  for patch in ../*.patch; do
    patch -Np1 -i "$patch"
  done
}

build() {
  cd "$srcdir/${pkgname}-${pkgver}"
  mkdir -p build
  cd build
  cmake .. \
        -DCMAKE_BUILD_TYPE=Release \
        -DGENERATE_SRS_SECRET=OFF \
        -DUSE_APPARMOR=ON \
        -DINIT_FLAVOR=systemd \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DSYSD_UNIT_DIR='/usr/lib/systemd/system'
  make all
}

package() {
  cd "$srcdir/${pkgname}-${pkgver}/build"
  make DESTDIR="$pkgdir/" install

  mv "$pkgdir"/usr/{sbin,bin}

  # This is to defer running the keygen until runtime; because of
  # GENERATE_SRS_SECRET=OFF.
  install -Dm644 "$srcdir/postsrsd-genkey.service"      "$pkgdir/usr/lib/systemd/system/postsrsd-genkey.service"
  install -Dm644 "$srcdir/postsrsd.service-genkey.conf" "$pkgdir/usr/lib/systemd/system/postsrsd.service.d/genkey.conf"
}
