File mailgraph.spec of Package mailgraph

# spec file for package mailgraph
# Copyright (c) 2019 SUSE LLC
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates

%define serverroot %(/usr/sbin/apxs2 -q datadir 2>/dev/null || /usr/sbin/apxs2 -q PREFIX)
%define cgi_dir %{serverroot}/cgi-bin
%define css_dir %{serverroot}/htdocs/css

Name:           mailgraph
Version:        1.14
Release:        0
Summary:        RRDtool frontend for Mail statistics
License:        GPL-2.0-or-later
Group:          Productivity/Networking/Diagnostic
Source0:        %{name}-%{version}.tar.bz2
Source1:        %{name}.init
Source2:        %{name}.service
Source3:        %{name}.logrotate
Source4:        %{name}.sysconfig
Source5:        rrdtool.gif
# PATCH-FIX-openSUSE -- rsyslog support, adapt pathnames for daemon_logfile and daemon_rrd_dir to openSUSE
Patch0:         %{name}-1.14-pl.patch
# PATCH-FIX-openSUSE -- adapt/enhance css usage and skip $uri in ref
Patch1:         %{name}-1.14-cgi.patch
# PATCH-FIX-UPSTREAM -- fix font for a tag
Patch2:         %{name}-1.14-css.patch
# PATCH-FIX-openSUSE -- integrate patch from nagios-plugins-mailgraph
Patch3:         mailgraph_for_nagios-plugins-mailgraph.patch
# PATCH-FIX-UPSTREAM -- do not get an image from every time the mailgraph.cgi is called
Patch4:         mailgraph-1.14-tracking.patch
# PATCH-FIX-UPSTREAM -- include postgrey and greylisting graphs in output (and add corresponding options)
Patch5:         mailgraph-1.14-add_postgrey_and_greylisting_support.patch
# PATCH-FIX-UPSTREAM -- handle postscreen in the same way as smtpd
Patch6:         mailgraph-1.14-add_postscreen_support.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
BuildRequires:  apache2-devel
Requires(pre):  %fillup_prereq
Requires:       apache2-mod_perl
Requires:       logrotate
Requires:       postfix
Requires:       rrdtool
Requires:       perl(File::Tail)
%if 0%{?suse_version} > 1100
Provides:       %{css_dir}
%if 0%{?suse_version} >= 1210
BuildRequires:  pkgconfig(systemd)
%define has_systemd 1
Requires(pre):  %insserv_prereq

Mailgraph is a very simple mail statistics RRDtool frontend for Postfix
that produces daily, weekly, monthly and yearly graphs of received/sent
and bounced/rejected mail (SMTP traffic).

%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1


install -d -m 755 %{buildroot}%{_sbindir}
install -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name}/img
install -d -m 755 %{buildroot}%{_localstatedir}/log/%{name}

install -D -m 755 %{name}.pl %{buildroot}%{_bindir}/%{name}.pl
install -D -m 755 %{name}.cgi %{buildroot}%{cgi_dir}/%{name}.cgi
install -D -m 644 %{name}.css %{buildroot}%{css_dir}/%{name}.css
install -D -m 644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
install -D -m 644 %{S:4} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -D -m 644 %{S:5} %{buildroot}%{css_dir}/rrdtool.gif

# systemd vs SysVinit
%if 0%{?has_systemd}
install -D -m 0644 %{S:2} %{buildroot}%{_unitdir}/%{name}.service
ln -sf %{_sbindir}/service %{buildroot}/%{_sbindir}/rc%{name}
%else #SysVinit
install -D -m 0755 %{S:1} %{buildroot}/%{_sysconfdir}/init.d/%{name}
ln -sf %{_sysconfdir}/init.d/%{name} %{buildroot}/%{_sbindir}/rc%{name}

if [[ -f %{_sysconfdir}/sysconfig/%{name} ]]; then
  sed -i -e 's#^MAILGRAPH_OPTS=" -d -v"$#MAILGRAPH_OPTS=" -v"#'\
    -e 's#^MAILGRAPH_LOG_TYPE=""$#MAILGRAPH_LOG_TYPE="syslog"#'\
    -e 's#^MAILGRAPH_LOG_FILE=""#MAILGRAPH_LOG_FILE="/var/log/mail"#'\
%if 0%{?has_systemd}
%service_add_pre %{name}.service

%if 0%{?has_systemd}
%service_del_preun %{name}.service
%stop_on_removal %{name}

%if 0%{?has_systemd}
%service_add_post %{name}.service
%{fillup_only mailgraph}
%{fillup_and_insserv mailgraph}
install -d %{_localstatedir}/run/%{name}

%if 0%{?has_systemd}
%service_del_postun %{name}.service
%restart_on_update %{name}

%if 0%{?suse_version} >= 01200
%license COPYING
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%dir %{_localstatedir}/lib/%{name}
%attr(755,wwwrun,www) %dir %{_localstatedir}/lib/%{name}/img
%dir %{_localstatedir}/log/%{name}
%if 0%{?has_systemd}