File smokeping.spec of Package smokeping

#
# spec file for package smokeping by vicidial
#
# Copyright (c) 2020 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/
#


# These mostly define the default options for the installed config file
# It's done this way so it's more distro friendly
%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.8.2
Release:        0
Summary:        Advanced network latency monitor
License:        GPL-2.0
Group:          System/Monitoring
Url:            http://oss.oetiker.ch/smokeping/
Source0:        https://oss.oetiker.ch/smokeping/pub/%{name}-%{version}.tar.gz
Source2:        %{name}.conf
Source3:        README.SUSE
Source4:        smokeping.cgi
Source5:        smokeinfo.1
Source6:        smokeping.service
Source7:        smokeping-tmpfiles.conf
Patch0:         smokeping-2.6.7-silence.patch
Patch1:         smokeping-2.7.0-config.patch
Patch2:         smokeping-2.8.2-paths.patch
Patch3:         smokeping-2.8.2-no-3rd-party.patch
Patch4:         smokeping-2.8.2-remove-date.patch
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

# stuff we need
BuildRequires:  apache2-prefork
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  coreutils
BuildRequires:  make
BuildRequires:  openssl-devel
BuildRequires:  perl(Authen::Radius)
BuildRequires:  perl(CGI)
BuildRequires:  perl(CGI::Fast)
BuildRequires:  perl(Config::Grammar)
BuildRequires:  perl(Data::Dumper)
BuildRequires:  perl(Digest::HMAC_MD5)
BuildRequires:  perl(Digest::MD5)
BuildRequires:  perl(ExtUtils::MakeMaker)
BuildRequires:  perl(ExtUtils::Manifest)
BuildRequires:  perl(FCGI)
BuildRequires:  perl(File::Basename)
BuildRequires:  perl(Getopt::Long)
BuildRequires:  perl(IO::Pty)
BuildRequires:  perl(IO::Socket::SSL)
BuildRequires:  perl(LWP)
BuildRequires:  perl(LWP::UserAgent)
BuildRequires:  perl(Net::DNS)
BuildRequires:  perl(Net::LDAP)
BuildRequires:  perl(Net::OpenSSH)
BuildRequires:  perl(Net::SNMP)
BuildRequires:  perl(Net::Telnet)
BuildRequires:  perl(POSIX)
BuildRequires:  perl(Pod::Usage)
BuildRequires:  perl(RRDs)
BuildRequires:  perl(Safe)
BuildRequires:  perl(Socket6)
BuildRequires:  perl(Storable)
BuildRequires:  perl(Sys::Hostname)
BuildRequires:  perl(Sys::Syslog)
BuildRequires:  perl(Time::HiRes)
BuildRequires:  perl(URI::Escape)
BuildRequires:  perl(strict)
BuildRequires:  perl(vars)
BuildRequires:  perl(warnings)
BuildRequires:  systemd
%{?systemd_requires}
%if 0%{?sles_version} > 11 || 0%{?suse_version} >= 1140
%perl_requires
%endif


# Stuff needed to install
Requires(pre):  %fillup_prereq
Requires(pre):  httpd
Requires:       apache2-mod_fcgid
Requires:       bind-utils
Requires:       curl
Requires:       echoping
Requires:       findutils
Requires:       fping
Requires:       httpd
Requires:       perl(CGI::Fast)
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)
Requires:       rrdtool
Requires:       smtp_daemon
Requires:       traceroute


%description
SmokePing is a deluxe latency measurement tool. It can measure, store and
display latency, latency distribution and packet loss. SmokePing uses RRDtool
to maintain a longterm data-store and to draw pretty graphs, giving up to the
minute information on the state of each network connection.


%prep
%autosetup -p1

# Make CHANGES UTF8 readable
iconv -f ISO-8859-1 -t utf-8 -o CHANGES.utf8 CHANGES
touch -r CHANGES CHANGES.utf8 
mv CHANGES.utf8 CHANGES

# remove some external modules
#rm -f lib/{SNMP_Session,SNMP_util,BER}.pm
rm -rf thirdparty/
rm lib/Smokeping/probes/Radius.pm
[ -e VERSION ] || echo %{version} > VERSION


%build
autoreconf --force --install --verbose --make
%configure --sysconfdir=%{_sysconfdir}/ --libdir=%{perl_vendorlib} --with-htdocs-dir=%{htdocs_dir}/smokeping --enable-pkgonly --disable-silent-rules

# Below makes changes to stock config file so it works when installed on distro
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   = http://localhost/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
sed -i 's+js/+/smokeping/js/+g' etc/basepage.html.dist
sed -i 's+css/+/smokeping/css/+g' etc/basepage.html.dist


%install
make install DESTDIR=%{buildroot} perllibdir=%{perl_vendorlib}

# Setup systemd/init scripts
install -Dd -m 0755 %{buildroot}%{_sbindir}
install -Dm 0644 %{SOURCE6} %{buildroot}/%{_unitdir}/%{name}.service
ln -s -f service %{buildroot}%{_sbindir}/rc%{name}
install -d -m 0755 %{buildroot}%_tmpfilesdir
install -m 0644 %{SOURCE7} %{buildroot}%_tmpfilesdir/smokeping.conf

# apache config and wrapper
install -D -m 0644 %{SOURCE2} %{buildroot}%{apache_conf}/%{name}.conf
install -D -m 0755 %{SOURCE4} %{buildroot}%{cgi_dir}/%{name}

# Local dirs for data
install -d -m 0751 %{buildroot}%{home_dir}
install -d -m 0751 %{buildroot}%{cache_dir}
install -d -m 0751 %{buildroot}%{data_dir}

# Extra man pages
install -D -m 0644 %{SOURCE5} %{buildroot}%{_mandir}/man1/smokeinfo.1
install -d -m 0755 %{buildroot}%{_mandir}/man1
install -D -m 0644  %{SOURCE3} %{buildroot}%{_datadir}/%{name}/README.SUSE

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

# Make the distro configs the defaults
for f in config basepage.html smokemail tmail smokeping_secrets ; do
    mv %{buildroot}%{_sysconfdir}/%{name}/$f.dist \
       %{buildroot}%{_sysconfdir}/%{name}/$f
done

# Do some system setup rework
rm -f %{buildroot}%{_datadir}/smokeping/htdocs/smokeping.fcgi.dist


%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 ||:
%service_add_pre %{name}.service %{name}.socket

%post
%fillup_only %{name}
%service_add_post %{name}.service
%tmpfiles_create %_tmpfilesdir/smokeping.conf
chmod 0440 /etc/smokeping/smokeping_secrets

%preun
%stop_on_removal %{name}
%service_del_preun %{name}.service

%postun
%restart_on_update %{name}
%service_del_postun %{name}.service


%files
%defattr(-, root, root, 0755)
%dir %attr(0751,root,%{name}) %{conf_dir}
%dir %{_datadir}/%{name}
%dir %{home_dir}
%dir %attr(0755,wwwrun,%{name}) %{cache_dir}
%dir %attr(0755,%{name},www) %{data_dir}
%{_sbindir}/rc%{name}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/smokeping.conf
%{_sbindir}/%{name}
%config(noreplace) %attr(0644,root,%{name}) %{_sysconfdir}/%{name}/*
%config(noreplace) %{apache_conf}/%{name}.conf
%{htdocs_dir}/smokeping/
%{cgi_dir}/%{name}
%{_bindir}/smokeinfo
%{_bindir}/tSmoke
%{_bindir}/smokeping_cgi
%{perl_vendorlib}/Smokeping/
%{perl_vendorlib}/Smokeping.pm
%{perl_vendorlib}/BER.pm
%{perl_vendorlib}/SNMP_Session.pm
%{perl_vendorlib}/SNMP_util.pm
%{_datadir}/%{name}/README.SUSE
%{_mandir}/man?/?mokeping*
%{_mandir}/man1/smokeinfo.1*
%{_mandir}/man1/tSmoke*
%ghost %attr(0750,%{name},root) %{run_dir}/

%changelog
openSUSE Build Service is sponsored by