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 http://bugs.opensuse.org/
#


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

%{!?_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

Url:            http://oss.oetiker.ch/smokeping/
Source0:        http://oss.oetiker.ch/smokeping/pub/%{name}-%{version}.tar.gz
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
%endif

# 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
%{?systemd_requires}
%endif

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

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

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)

%description
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.

%prep
%setup -q
%patch1 -p0

%build
%configure --with-htdocs-dir=%{htdocs_dir}/smokeping --sysconfdir=/etc/smokeping
make
cat << EOF >> fix_defaults
s@/usr/etc@%{conf_dir}@g
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
s@src="cropper@src="/smokeping/cropper@g
EOF

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

%install
make install DESTDIR=%{buildroot} perllibdir=%{perl_vendorlib}
install -Dd -m 0755 \
%{buildroot}%{_sbindir}
%if %{with systemd}
%__install -Dm 0644 %{SOURCE6} %{buildroot}/%{_unitdir}/%{name}.service
ln -s -f service %{buildroot}%{_sbindir}/rc%{name}
%else
# init script
install -D -m 0755 %{SOURCE1} %{buildroot}%{_initddir}/%{name}
ln -s -f %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif
# 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
#SUSE README
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
%endif

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

%pre
/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
%endif

%post
%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
%else
systemd-tmpfiles --create %_tmpfilesdir/smokeping.conf
%endif
%endif

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

%postun
%insserv_cleanup
%restart_on_update %{name}
%if %{with systemd}
%service_del_postun %{name}.service
%endif

%files
%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}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/smokeping.conf
%else
%{_initddir}/%{name}
%endif
%{_sbindir}/rc%{name}
%{_bindir}/%{name}
%{_bindir}/smokeinfo
%{_bindir}/tSmoke
%{_bindir}/smokeping_cgi
%{cgi_dir}/%{name}
%{htdocs_dir}/smokeping/
%{perl_vendorlib}/BER.pm
%{perl_vendorlib}/Smokeping/
%{perl_vendorlib}/Smokeping.pm
%{perl_vendorlib}/SNMP_Session.pm
%{perl_vendorlib}/SNMP_util.pm
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/README.SUSE

%{_mandir}/man?/?mokeping*
%{_mandir}/man1/smokeinfo.1*
%{_mandir}/man1/tSmoke*

%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}/

%changelog