##
##  diogene87.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_diogene87  1.0.0rc5
%define       V_narcisse81 0.0.4

#   package information
Name:         diogene87
Summary:      Job Scheduling System
URL:          http://diogene87.org/
Vendor:       D. Parisot & S.G. Ytsma
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        System
License:      GPL
Version:      %{V_diogene87}
Release:      20120623

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://download.sourceforge.net/diogene87/diogene87-%{V_diogene87}.tar.gz
Source1:      http://download.sourceforge.net/narcisse81/narcisse81-%{V_narcisse81}.tar.gz
Source2:      rc.diogene87
Source3:      fsl.diogene87
Patch0:       diogene87.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  gettext
PreReq:       gettext
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif

%description
    Diogene87 is a powerful scheduler system providing centralized
    management, jobs dependencies, start condition, planning, log of job
    activity, job monitoring, statistic for job duration and resource
    control.

%track
    prog diogene87 = {
        disabled
        comment   = "Diogene87 project is dead"
        version   = %{V_diogene87}
        url       = http://sourceforge.net/projects/diogene87/files/
        regex     = diogene87-(__VER__)\.tar\.gz
    }
    prog diogene87:narcisse81 = {
        disabled
        comment   = "Diogene87 project is dead"
        version   = %{V_narcisse81}
        url       = http://sourceforge.net/projects/narcisse81/files/
        regex     = narcisse81-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %patch -p0

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;\(localstatedir./lib\)/diogene87;\1;g' \
        -e 's;\(localstatedir./run\)/diogene87;\1;g' \
        configure conf/Makefile.in
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
    LIBS="%{l_fsl_libs}" \
    ./configure \
        --prefix=%{l_prefix} \
        --datarootdir=%{l_prefix} \
        --localstatedir=%{l_prefix}/var/diogene87 \
        --disable-smart-install

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down installation files
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/diogene87
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/locale
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/*_dev*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/info/*_fr*
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   post-adjust default configuration
    %{l_shtool} subst \
        -e 's;^#\(PID_FILE.*\);\1;' \
        -e 's;^#\(USER_ACCOUNT\)=.*;\1=%{l_rusr};' \
        -e 's;^#\(IPPORT=.*\);\1;' \
        -e 's;^#\(IPADDR\)=.*;\1=127.0.0.1;' \
        $RPM_BUILD_ROOT%{l_prefix}/etc/diogene87/dio87d.conf

    #   install OSSP fsl configuration
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.diogene87} $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   install run-command script
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.diogene87} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   create additional directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/diogene87/log

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/fsl.diogene87' \
        '%config %attr(640,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/diogene87/*' \
        '%attr(700,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/diogene87/run' \
        '%attr(755,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/diogene87/lib' \
        '%attr(755,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/diogene87/log'

%files -f files

%clean

%post
    #   create initial database
    if [ $1 -eq 1 ]; then
        echo "Creating initial Diogene87 database" | %{l_rpmtool} msg -b -t info
        su %{l_rusr} -c "umask 077; $RPM_INSTALL_PREFIX/sbin/dio87d -I 2>/dev/null"
    fi

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

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

