File nsca.spec of Package nsca

#
# spec file for package nsca
#
# Copyright (c) 2021 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 https://bugs.opensuse.org/
#


%if 0%{?suse_version} >= 1230
%bcond_without systemd
%else
%bcond_with systemd
%endif
#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
Name:           nsca
Version:        2.10.0
Release:        0
Summary:        The Nagios Service Check Acceptor
License:        GPL-2.0-or-later
Group:          System/Monitoring
URL:            https://www.nagios.org/
Source0:        %{name}-%{version}.tar.gz
Source1:        rcnsca
Source2:        nsca-rpmlintrc
Source3:        nsca-SuSEfirewall2
Source4:        send_nsca.1
Source5:        nsca.1
Source6:        usr.bin.nsca
Source7:        nsca.service
Source8:        nsca-sysconfig
# PATCH-FIX-OPENSUSE disable the xinetd service per default - in that case it is also not
# needed to bind on any specific address
Patch2:         nsca.xinetd.patch
# PATCH-FIX-OPENSUSE adapt the spool directory to follow openSUSE guidelines
Patch3:         nsca.spooldir.patch
# PATCH-FIX-UPSTREAM - make sure there are no extraneous group memberships when dropping root privileges
Patch4:         nsca-clean-setgroups.patch
# PATCH-FIX-UPSTREAM - https://github.com/NagiosEnterprises/nsca/pull/50
Patch5:         send_nsca_implicit_declaration.patch
BuildRequires:  nagios-rpm-macros
BuildRequires:  tcpd-devel
Requires(post): %fillup_prereq
Recommends:     apparmor-parser
Recommends:     monitoring_daemon
Provides:       nagios-nsca = %{version}
Obsoletes:      nagios-nsca < 2.9.0
%if %suse_version < 1500
BuildRequires:  libmcrypt-devel
%endif
%if 0%{?suse_version}
Requires(pre):  %fillup_prereq
%endif
%if %{with systemd}
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
%else
# FIXME: use proper Requires(pre/post/preun/...)
PreReq:         %insserv_prereq
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build


%description
The purpose of this add-on is to allow the execution of NetSaint and
Nagios plug-ins on a remote host in a manner that is as transparent as
possible. This is the server part including the daemon without the
client program.

%package client
Summary:        The Nagios Service Check Acceptor Client
Group:          System/Monitoring
Provides:       nagios-nsca-client = %{version}
Obsoletes:      nagios-nsca-client < 2.9.0

%description client
The purpose of this add-on is to allow the execution of NetSaint and
Nagios plug-ins on a remote host in a manner that is as transparent as
possible. This package includes only the client program.

%prep
%setup -q
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1

%build
export CFLAGS="%{optflags}"
%if 0%{?suse_version} > 1000
export CFLAGS="$CFLAGS -fstack-protector"
%endif
%configure \
	--sysconfdir=%{_sysconfdir} \
	--localstatedir=%{nagios_spooldir} \
	--with-nsca-user=%{nagios_user} \
	--with-nsca-grp=%{nagios_group} \
	--with-nsca-port=5667
make all

%install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_sbindir}
mkdir -p %{buildroot}%{_sysconfdir}/apparmor.d/local
mkdir -p %{buildroot}%{_initddir}/
mkdir -p %{buildroot}%{_sysconfdir}/xinetd.d/
mkdir -p %{buildroot}%{_fillupdir}
install -m 755 src/nsca %{buildroot}%{_bindir}/
install -m 755 src/send_nsca %{buildroot}%{_bindir}/
install -m 644 sample-config/nsca.cfg %{buildroot}%{_sysconfdir}/
install -m 644 sample-config/send_nsca.cfg %{buildroot}%{_sysconfdir}/
install -m 644 sample-config/nsca.xinetd %{buildroot}%{_sysconfdir}/xinetd.d/nsca
install -m 644 %{SOURCE8} %{buildroot}%{_fillupdir}/sysconfig.nsca
# startup scripts
%if %{with systemd}
install -Dm0644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}.service
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%else
install -m 755 %{SOURCE1}    %{buildroot}%{_sysconfdir}/init.d/nsca
ln -sf ../../%{_sysconfdir}/init.d/nsca %{buildroot}%{_sbindir}/rcnsca
%endif
# sysconfig file
install -D -m 0644 %{SOURCE8} %{buildroot}%{_fillupdir}/sysconfig.%{name}
# install SuSEfirewall2 script
%if 0%{?suse_version} <= 1500
install -Dm644 %{SOURCE3} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
# install man pages
install -Dm644 %{SOURCE4} %{buildroot}%{_mandir}/man1/send_nsca.1
install -m644  %{SOURCE5} %{buildroot}%{_mandir}/man1/nsca.1
# install apparmor profile
install -Dm644 %{SOURCE6} %{buildroot}%{_sysconfdir}/apparmor.d/usr.bin.nsca
echo "# Site-specific additions and overrides for 'usr.bin.nsca'" > %{buildroot}%{_sysconfdir}/apparmor.d/local/usr.bin.nsca

%if %{with systemd}
%pre
%service_add_pre %{name}.service
%endif

%post
%{fillup_only nsca}
%if %{with systemd}
%service_add_post %{name}.service
%endif

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

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

%triggerun -- nagios-nsca < 2.9.2
STATUS='%{_localstatedir}/adm/update-scripts/%{name}'
%if %{with systemd}
if [ -x %{_bindir}/systemctl ]; then
	%{_bindir}/systemctl status nsca.service >/dev/null
	if test $? = 0; then
		echo "%{_bindir}/systemctl restart nsca.service" >> "$STATUS"
	else
        touch "$STATUS"
    fi
	%{_bindir}/systemctl status xinetd.service >/dev/null
	if test $? = 0; then
		echo "%{_bindir}/systemctl try-restart xinetd.service" >> "$STATUS"
	else
        touch "$STATUS"
    fi
    chmod +x "$STATUS"
fi
%else
if [ -x %{_sysconfdir}/init.d/nsca ]; then
	%{_sysconfdir}/init.d/nsca status >/dev/null
	if test $? = 0; then
		echo "%{_sysconfdir}/init.d/nsca restart" >> "$STATUS"
	else
		touch "$STATUS"
	fi
	chmod +x "$STATUS"
fi
if [ -x %{_sysconfdir}/init.d/xinetd ]; then
    %{_sysconfdir}/init.d/xinetd status >/dev/null
    if test $? = 0; then
        echo "%{_sysconfdir}/init.d/xinetd try-restart" >> "$STATUS"
    else
        touch "$STATUS"
    fi
    chmod +x "$STATUS"
fi
%endif

%triggerpostun -- nagios-nsca < 2.9.2
# Move /etc/nagios/nsca.conf to /etc/nsca.conf when updating from an old version
# and inform the admin about the move.
cd %{_sysconfdir}
if test -e nagios/nsca.conf.rpmsave -a ! -e nsca.conf.rpmnew; then
    mv nsca/nsca.conf nsca.conf.rpmnew
    mv nagios/nsca.conf.rpmsave nsca.conf
    test -L %{nagios_sysconfdir}/nsca.conf || ln -s %{_sysconfdir}/nsca.conf %{nagios_sysconfdir}/nsca.conf
fi
sed -i "s|%{nagios_sysconfdir}/nsca.cfg|%{_sysconfdir}/nsca.cfg|g" %{_sysconfdir}/xinetd.d/nsca || :
if [ -e %{_localstatedir}/adm/update-scripts/%{name} ]; then
    /bin/sh %{_localstatedir}/adm/update-scripts/%{name}
    rm %{_localstatedir}/adm/update-scripts/%{name}
fi

%triggerpostun -- nagios-nsca-client < 2.9.2
# Move /etc/nagios/send_nsca.cfg to /etc/send_nsca.cfg when updating from an old version
# and inform the admin about the move.
cd %{_sysconfdir}
if test -e nagios/send_nsca.cfg.rpmsave -a ! -e send_nsca.cfg.rpmnew; then
	mv nsca/send_nsca.cfg send_nsca.cfg.rpmnew
	mv nagios/send_nsca.cfg send_nsca.cfg
    test -L %{nagios_sysconfdir}/send_nsca.cfg || ln -s %{_sysconfdir}/send_nsca.cfg %{nagios_sysconfdir}/send_nsca.cfg
fi

%clean
rm -rf %{buildroot};

%files
%defattr(-,root,root)
%doc CHANGELOG.md CONTRIBUTORS.md README.md SECURITY.md
%license LICENSE.md
%dir %{_sysconfdir}/apparmor.d
%dir %{_sysconfdir}/apparmor.d/local
%{_bindir}/nsca
%if %{with systemd}
%{_unitdir}/%{name}.service
%else
%{_sysconfdir}/init.d/nsca
%endif
%{_sbindir}/rcnsca
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.bin.nsca
%config(noreplace) %{_sysconfdir}/apparmor.d/local/usr.bin.nsca
%config(noreplace) %{_sysconfdir}/nsca.cfg
%if 0%{?suse_version} >= 1500
%dir %{_sysconfdir}/xinetd.d
%endif
%config(noreplace) %{_sysconfdir}/xinetd.d/nsca
%if 0%{?suse_version} <= 1500
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
%{_fillupdir}/sysconfig.%{name}
%{_mandir}/man1/nsca.1%{?ext_man}

%files client
%defattr(-,root,root)
%{_bindir}/send_nsca
%{_mandir}/man1/send_nsca.1%{?ext_man}
%config(noreplace) %{_sysconfdir}/send_nsca.cfg

%changelog
openSUSE Build Service is sponsored by