##
##  postfix-mailgraph.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 information
Name:         postfix-mailgraph
Summary:      Postfix Mail Graphing
URL:          http://mailgraph.schweikert.ch/
Vendor:       David Schweikert
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      GPL
Version:      1.14
Release:      20080101

#   list of sources
Source0:      http://mailgraph.schweikert.ch/pub/mailgraph-%{version}.tar.gz
Source1:      rc.postfix-mailgraph
Patch0:       postfix-mailgraph.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, perl, perl-sys, rrdtool, postfix

%description
    Mailgraph is a very simple mail statistics RRDtool frontend for the
    Postfix MTA that produces daily, weekly, monthly and yearly graphs
    of received/sent and bounced/rejected mail.

%track
    prog postfix-mailgraph = {
        version   = %{version}
        url       = http://mailgraph.schweikert.ch/pub/
        regex     = mailgraph-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n mailgraph-%{version}
    %patch -p0

%build

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/cgi \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/var/postfix-mailgraph/rrd \
        $RPM_BUILD_ROOT%{l_prefix}/var/postfix-mailgraph/img \
        $RPM_BUILD_ROOT%{l_prefix}/var/postfix-mailgraph/run
    %{l_shtool} install -c -m 755 \
        -e 's;#!/usr/bin/perl;#!%{l_prefix}/bin/perl;' \
        -e 's;/var/log/mailgraph\.log;%{l_prefix}/var/postfix-mailgraph/run/mailgraph.log;' \
        -e 's;/var/run/mailgraph\.pid;%{l_prefix}/var/postfix-mailgraph/run/mailgraph.pid;' \
        -e 's;/var/log/syslog;%{l_prefix}/var/postfix/log/postfix.log;' \
        -e 's;/var/log;%{l_prefix}/var/postfix-mailgraph/rrd;' \
        mailgraph.pl $RPM_BUILD_ROOT%{l_prefix}/sbin/mailgraph
    %{l_shtool} install -c -m 755 \
        -e 's;#!/usr/bin/perl;#!%{l_prefix}/bin/perl;' \
        -e 's;mailgraph\.cgi;mailgraph;' \
        -e 's;mailgraph\.rrd;%{l_prefix}/var/postfix-mailgraph/rrd/mailgraph.rrd;' \
        -e 's;mailgraph_virus\.rrd;%{l_prefix}/var/postfix-mailgraph/rrd/mailgraph_virus.rrd;' \
        -e 's;/tmp/mailgraph;%{l_prefix}/var/postfix-mailgraph/img;' \
        mailgraph.cgi $RPM_BUILD_ROOT%{l_prefix}/cgi/mailgraph
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.postfix-mailgraph} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(755,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/postfix-mailgraph/img'

%files -f files

%clean

