# Maintainer: David P. <megver83@parabola.nu>
# Contributor (Artix): Kaiting Chen <kaiting.chen@kiwilight.com>
# Maintainer (Arch): Gaetan Bisson <bisson@archlinux.org>

pkgname='cronie'
pkgver=1.6.1
pkgrel=1
pkgrel+=.nonsystemd1
pkgdesc='Daemon that runs specified programs at scheduled times and related tools'
url='https://github.com/cronie-crond/cronie/'
license=('custom:BSD')
arch=('x86_64')
arch+=('armv7h' 'i686')
depends=('pam' 'bash' 'run-parts')
optdepends=('smtp-server: send job output via email'
            'smtp-forwarder: forward job output to email server')
conflicts=('cron')
provides=('cron')
options=('debug')
source=("https://github.com/cronie-crond/cronie/releases/download/${pkgname}-${pkgver}/${pkgname}-${pkgver}.tar.gz"
        'pam.d'
        'deny')
sha256sums=('2cd0f0dd1680e6b9c39bf1e3a5e7ad6df76aa940de1ee90a453633aa59984e62'
            '00864268b491bab8c66400a4a4b4bf85f168a6e44e85676105e084940924090c'
            'ae6e533ecdfc1bd2dd80a9e25acb0260cbe9f00c4e4abee93d552b3660f263fc')
backup=('etc/cron.deny'
        'etc/pam.d/crond'
        'etc/cron.d/0hourly'
        'etc/anacrontab')

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

	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--enable-anacron \
		--with-inotify \
		--with-pam
	make
}

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

	make DESTDIR="${pkgdir}" install

	chmod u+s "${pkgdir}"/usr/bin/crontab
	install -d "${pkgdir}"/var/spool/{ana,}cron
	install -d "${pkgdir}"/etc/cron.{d,hourly,daily,weekly,monthly}

	install -Dm0644 ../deny "${pkgdir}"/etc/cron.deny
	install -Dm0644 ../pam.d "${pkgdir}"/etc/pam.d/crond

	install -Dm0644 contrib/anacrontab "${pkgdir}"/etc/anacrontab
	install -Dm0644 contrib/0hourly "${pkgdir}"/etc/cron.d/0hourly
	install -Dm0755 contrib/0anacron "${pkgdir}"/etc/cron.hourly/0anacron

	install -Dm0644 COPYING "${pkgdir}"/usr/share/licenses/cronie/COPYING
}
