File smokeping.spec of Package smokeping

# spec file for package smokeping
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
# 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

%if 0%{?suse_version} >= 1210
%bcond_without systemd
%bcond_with systemd

%{!?_rundir: %{expand: %%global _rundir %{_localstatedir}/run}}
%{!?_initddir: %{expand: %%global _initddir %{_initrddir}}}

%define home_dir    %{_localstatedir}/lib/%{name}
%define data_dir    %{home_dir}/data
%define run_dir     %_rundir/%{name}
%define cache_dir   %home_dir/cache
%define conf_dir    %{_sysconfdir}/%{name}
%define cgi_dir     /srv/www/cgi-bin/
%define htdocs_dir  /srv/www/htdocs/
%define apache_conf %{_sysconfdir}/apache2/conf.d/

Name:           smokeping
Version:        2.6.11
Release:        0

Summary:        Advanced network latency monitor
License:        GPL-2.0
Group:          System/Monitoring

Source1:        %{name}.init
Source2:        %{name}.conf
Source3:        README.SUSE
Source4:        smokeping.cgi
Source5:        smokeinfo.1
Source6:        smokeping.service
Source7:        smokeping-tmpfiles.conf
Patch1:         smokeping_reload.patch

%if 0%{?suse_version} > 1110
BuildArch:      noarch

# for path ownership
BuildRequires:  apache2-prefork
BuildRequires:  perl(Config::Grammar)
BuildRequires:  perl(Digest::HMAC_MD5)
BuildRequires:  perl(CGI)
BuildRequires:  perl(CGI::Fast)
BuildRequires:  perl(FCGI)
BuildRequires:  perl(IO::Tty)
BuildRequires:  perl(LWP)
BuildRequires:  perl(Net::DNS)
BuildRequires:  perl(Net::LDAP)
BuildRequires:  perl(Net::OpenSSH)
BuildRequires:  perl(Net::SNMP)
BuildRequires:  perl(Net::Telnet)
BuildRequires:  perl(RRDs)

%if %{with systemd}
BuildRequires:  systemd

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%if 0%{?sles_version} > 11 || 0%{?suse_version} >= 1140

Requires(pre):  %fillup_prereq
Requires(pre):  %insserv_prereq
Requires:       bind-utils
Requires:       curl
Requires:       echoping
Requires:       fping
Requires:       smtp_daemon
Requires:       perl(Config::Grammar)
Requires:       perl(Digest::HMAC_MD5)
Requires:       perl(FCGI)
Requires:       perl(IO::Socket::SSL)
Requires:       perl(IO::Tty)
Requires:       perl(LWP)
Requires:       perl(Net::DNS)
Requires:       perl(Net::LDAP)
Requires:       perl(Net::OpenSSH)
Requires:       perl(Net::SNMP)
Requires:       perl(Net::Telnet)
Requires:       perl(RRDs)
Requires:       perl(Socket6)

SmokePing is a network latency monitor which works in a way that is similar to
MRTG. It measures network latency to a configurable set of destinations on the
network, and displays its findings in easy-to-read Web pages. SmokePing has
special support for monitoring hosts with dynamic IP addresses. SmokePing uses
RRDtool as its logging and graphing back-end, making the system very efficient.
The presentation of the data on the Web is done through a CGI which creates
graphs on demand.

%setup -q
%patch1 -p0

%configure --with-htdocs-dir=%{htdocs_dir}/smokeping --sysconfdir=/etc/smokeping
cat << EOF >> fix_defaults
s@sendmail\s*=.*@sendmail = /usr/sbin/sendmail@g
s@imgcache\s*=.*@imgcache = %{cache_dir}@g
s@imgurl\s*=.*@imgurl   = /smokeping/cache@g
s@datadir\s*=.*@datadir  = %{data_dir}@g
s@^piddir\s*=.*@piddir   = %{run_dir}@g
s@cgiurl\s*=.*@cgiurl   = /cgi-bin/smokeping@g
s@owner\s*=.*@owner    = Root at badly configured smokeping box@g
s/contact\s*=.*/contact  = root@localhost/g
s/to\s*=.*/to = root@localhost/g
s/from\s*=.*/from = root@localhost/g
s@mailhost\s*=.*@mailhost = localhost@g

sed -i -f fix_defaults etc/config.dist etc/basepage.html.dist

make install DESTDIR=%{buildroot} perllibdir=%{perl_vendorlib}
install -Dd -m 0755 \
%if %{with systemd}
%__install -Dm 0644 %{SOURCE6} %{buildroot}/%{_unitdir}/%{name}.service
ln -s -f service %{buildroot}%{_sbindir}/rc%{name}
# init script
install -D -m 0755 %{SOURCE1} %{buildroot}%{_initddir}/%{name}
ln -s -f %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
# apache config
install -D -m 0644 %{SOURCE2} %{buildroot}%{apache_conf}/%{name}.conf
# cgi wrapper
install -D -m 0755 %{SOURCE4} %{buildroot}%{cgi_dir}/%{name}
install -d -m 0751 %{buildroot}%{home_dir}
install -d -m 0751 %{buildroot}%{cache_dir}
install -d -m 0751 %{buildroot}%{data_dir}
install -d -m 0755 %{buildroot}%{_mandir}/man1
install -D -m 0644 %{SOURCE5} %{buildroot}%{_mandir}/man1/smokeinfo.1
install -D -m 0644  %{SOURCE3} %{buildroot}%{_datadir}/%{name}/README.SUSE
# Tmpfiles systemd handling config
%if %{with systemd}
install -d -m 0755 %{buildroot}%_tmpfilesdir
install -m 0644 %{SOURCE7} %{buildroot}%_tmpfilesdir/smokeping.conf

# ghost file requirement
install -d -m 0755 %{buildroot}%{run_dir}

/usr/sbin/groupadd -r %{name} &>/dev/null ||:
/usr/sbin/useradd -g %{name} -s /bin/false -r -c "user for %{name}" -d %{home_dir} %{name} &>/dev/null ||:
%if %{with systemd}
%service_add_pre %{name}.service %{name}.socket

%fillup_only %{name}
%if %{with systemd}
%service_add_post %{name}.service
%if 0%{?sle_version} >= 120200 || 0%{?suse_version} > 1320
%tmpfiles_create %_tmpfilesdir/smokeping.conf
systemd-tmpfiles --create %_tmpfilesdir/smokeping.conf

%stop_on_removal %{name}
%if %{with systemd}
%service_del_preun %{name}.service

%restart_on_update %{name}
%if %{with systemd}
%service_del_postun %{name}.service

%defattr(-, root, root, 0755)
%dir %attr(0751,root,%{name})  %{conf_dir}
%dir %{conf_dir}/examples
%config %{conf_dir}/examples/config*
%config(noreplace) %attr(0644,root,%{name}) %{conf_dir}/*dist
%config(noreplace) %{apache_conf}/%{name}.conf

%if %{with systemd}
%dir %{_datadir}/%{name}


%dir %attr(0751,wwwrun,root)  %{cache_dir}/
%dir %attr(0751,%{name},root) %{data_dir}/
%dir %attr(0751,root,root)    %{home_dir}/
%ghost %attr(0750,%{name},root) %{run_dir}/