##
##  dcron.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_major 3
%define       V_minor 2

#   package information
Name:         dcron
Summary:      Dillon's Cron Daemon
URL:          http://apollo.backplane.com/FreeSrc/
Vendor:       Matthew Dillon
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Process
License:      GPL
Version:      %{V_major}.%{V_minor}
Release:      20150308

#   list of sources
Source0:      http://apollo.backplane.com/FreeSrc/dcron%{V_major}%{V_minor}.tgz
Source1:      rc.dcron
Patch0:       dcron.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101, MTA, vim

%description
    Dillon Cron (dcron) is a portable multi-user crond(8) replacement.

%track
    prog dcron = {
        version   = %{V_major}%{V_minor}
        url       = http://apollo.backplane.com/FreeSrc/
        regex     = dcron(__VER__)\.tgz
    }

%prep
    %setup -q -n dcron
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;/var/spool/cron/crontabs;%{l_prefix}/var/dcron/crontabs;' \
        -e 's;/etc/cron.d;%{l_prefix}/etc/dcron/crontabs;' \
        -e 's;/usr/lib/sendmail;%{l_prefix}/sbin/sendmail;' \
        -e 's;/usr/bin/vi;%{l_prefix}/bin/vim;' \
        -e 's;/var/run/dcron.pid;%{l_prefix}/var/dcron/dcron.pid;' \
        defs.h
    %{l_make} %{l_mflags} \
        CC="%{l_cc}" \
        CFLAGS="%{l_cflags} -I."

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/dcron/crontabs \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/var/dcron/crontabs
    %{l_shtool} install -c -s -m 755 crontab $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -s -m 755 crond $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 644 crontab.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    %{l_shtool} install -c -m 644 crond.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.dcron} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(4755,%{l_susr},%{l_mgrp}) %{l_prefix}/bin/crontab' \
        '%attr(-,%{l_susr},%{l_mgrp}) %{l_prefix}/etc/dcron/crontabs'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} dcron status 2>/dev/null`
    [ ".$dcron_active" = .yes ] && %{l_rc} dcron restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} dcron stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/dcron/dcron.log* >/dev/null 2>&1 || true
    exit 0

