# Contributor: Giorgio Lando <lando at imap dot cc>
# Contributor: Sergej Pupykin
# Contributor: Thomas Bächler
# Contributor: Sébastien Luttringer
# Maintainer: Thorsten Töpper <atsutane-tu@freethoughts.de>

pkgname=fcron
pkgver=3.4.0
pkgrel=1
pkgdesc='Feature-rich cron implementation'
arch=(x86_64)
url='http://fcron.free.fr'
license=('GPL')
depends=('pam' 'run-parts')
makedepends=('smtp-forwarder' 'vim' 'fcron' 'systemd')
# use fcron as recursive deps to have user fcron installed during installation
# else add the following in build chroot
# groupadd -g 23 fcron
# useradd -r -d /var/spool/fcron -u 23 -g 23 fcron
optdepends=('smtp-forwarder: to send mails from cron jobs'
            'vim: default editor for fcrontab')
provides=('cron')
conflicts=('dcron')
backup=('etc/fcron/fcron.conf'
        'etc/fcron/fcron.allow'
        'etc/fcron/fcron.deny'
        'var/spool/fcron/systab.orig')
options=('emptydirs' '!makeflags')
install=$pkgname.install
source=("http://fcron.free.fr/archives/$pkgname-$pkgver.src.tar.gz"
        "http://fcron.free.fr/archives/$pkgname-$pkgver.src.tar.gz.sign"
        "fcron.sysusers"
        'systab.orig')
sha512sums=('1ce4cf2f72ac66bfc97ec28d8d3b8c53f44cff4307b80cda86419db6a1d9c3ed288d5ce92f4af8e497f775c975ee9e1b7d6cbb4ae07e84df4fe64fbdeb3a3558'
            'SKIP'
            '91a373073015b44839c85e180a5721eaf49717e5dcfca862ab6d857fa70f05a7bacfa7709553db94c8ab5e30fb7e9431a97103bfe927ef326c3bcdbfa6f3ee28'
            '5ed83bcba95f28bceb716ccbc735284d7317f18d99506959abb24fa0f4a846435e23b4ab88ed64f71b89c89b1b02b182f708c3418a6095135ed75b9bb0ef446e')
validpgpkeys=('7733B98B987784DF27707D41F8E544EC485EE7BC')

build() {
  cd $pkgname-$pkgver
  # Don't use --username=root and --groupname=root, this completly break
  # fcron security and allow local root escalation.
  # Thanks to Anh K. Huynh <kyanh@theslinux.org> for reporting it.
  ./configure --prefix=/usr \
              --sbindir=/usr/bin \
              --sysconfdir=/etc/fcron \
              --with-answer-all=no \
              --with-boot-install=no \
              --datarootdir=/usr/share \
              --datadir=/usr/share \
              --with-docdir=/usr/share/doc \
              --localstatedir=/var \
              --with-systemdsystemunitdir=/usr/lib/systemd/system \
              --with-piddir=/run \
              --with-editor=/usr/bin/vim \
              --with-sendmail=/usr/bin/sendmail
  make
}

package() {
  cd $pkgname-$pkgver
  sed -e '/systemctl daemon-reload/d' -i Makefile
  make DESTDIR="$pkgdir/" install
  install -Dm644 files/fcron.pam "$pkgdir/etc/pam.d/fcron"
  install -Dm644 files/fcrontab.pam "$pkgdir/etc/pam.d/fcrontab"
  install -Dm644 "$srcdir/fcron.sysusers" "$pkgdir/usr/lib/sysusers.d/fcron.conf"

  # Install a default fcrontab so that fcron can completely replace dcron
  # We don't use binary format which is incompatible between arch and may cause crash
  # We regenerate the binary format at each update
  install -Dm640 "$srcdir/systab.orig" "$pkgdir/var/spool/fcron/systab.orig"

  # Add cron.* directories
  install -d -m755 "$pkgdir/etc/cron.daily"
  install -d -m755 "$pkgdir/etc/cron.hourly"
  install -d -m755 "$pkgdir/etc/cron.monthly"
  install -d -m755 "$pkgdir/etc/cron.weekly"

  # remove docs
  rm -r "$pkgdir/usr/share/doc"

  # avoid conflict with filesystem>=2012.06
  rmdir "$pkgdir"/{var/,}run

  # avoid conflict with libbsd - #31259
  rm "$pkgdir/usr/share/man/man3/bitstring.3" \
    "$pkgdir/usr/share/man/fr/man3/bitstring.3"
  rmdir --ignore-fail-on-non-empty "$pkgdir/usr/share/man/man3" \
    "$pkgdir/usr/share/man/fr/man3"
}

# vim:set ts=2 sw=2 et:
