File nagiosql.spec of Package nagiosql

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


%define         installdir %{_datadir}/%{name}
%define         apache2_sysconfdir %{_sysconfdir}/apache2/conf.d
Name:           nagiosql
Version:        3.4.0
Release:        0
Summary:        Nagios configuration tool
License:        GPL-2.0-or-later
Group:          System/Monitoring
URL:            https://sourceforge.net/projects/nagiosql/
Source0:        https://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%20%{version}/nagiosql-%{version}.tar.bz2
Source1:        https://downloads.sourceforge.net/project/nagiosql/nagiosql/Documentation/NagiosQL_3.2_Installation_DE.pdf
Source2:        https://downloads.sourceforge.net/project/nagiosql/nagiosql/Documentation/NagiosQL_3.2_Installation_EN.pdf
Source3:        %{name}-httpd.conf
Source99:       %{name}-rpmlintrc
BuildRequires:  fdupes
BuildRequires:  nagios-rpm-macros
Requires:       apache2
Requires:       bash
Requires:       mod_php_any
Requires:       mysql >= 5.0
Requires:       nagios < 5.0
Requires:       nagios >= 2.0
Requires:       php-filter
Requires:       php-gettext
Requires:       php-mysql
Requires:       php-session
# FIXME: use proper Requires(pre/post/preun/...)
PreReq:         apache2
Recommends:     php-curl
Recommends:     php-ftp
#Recommends:     php5-ssh2
BuildArch:      noarch
AutoReq:        off

%description
NagiosQL is a professional, web based configuration tool for Nagios 2.x/3.x and
other Nagios based monitoring tools. It is designed for large enterprise
requirements as well as small environments. Any Nagios functionalities are
supported.

%package install
Summary:        Installation files for NagiosQL
Group:          System/Monitoring
Requires:       %{name} = %{version}
Requires(pre):  coreutils

%description install
This package contains installation file for the initial setup of
NagiosQL. It should be deinstalled after the initial setup.

%package install-nagios
Summary:        Installation files for NagiosQL and Nagios
Group:          System/Monitoring
Requires:       %{name}-install = %{version}
Requires(pre):  coreutils

%description install-nagios
This package contains installation file for the initial setup of
NagiosQL and an adapted initial mysql schema file for Nagios.

It should be deinstalled after the initial setup.

%package install-icinga
Summary:        Installation files for NagiosQL and Icinga
Group:          System/Monitoring
Requires:       %{name}-install = %{version}
Requires(pre):  coreutils

%description install-icinga
This package contains installation file for the initial setup of
NagiosQL and an adapted initial mysql schema file for Icinga.

It should be deinstalled after the initial setup.

%prep
%setup -q
install -m644 %{SOURCE1} .
install -m644 %{SOURCE2} .
sed -e "s|/opt/nagios%{_sysconfdir}/objects/|%{nagios_sysconfdir}/objects|g" \
	-e "s|%{_localstatedir}/nagios/rw/nagios.cmd|%{nagios_command_file}|g" \
	-e "s|/opt/nagios/bin/nagios|%{_sbindir}/nagios|g" \
	-e "s|%{_localstatedir}/nagios/nagios.lock|%{_var}/run/nagios/nagios.pid|g" \
	-e "s|%{_sysconfdir}/nagiosql/nagios.cfg|%{nagios_sysconfdir}/nagios.cfg|g" \
		install/sql/nagiosQL_v32_db_mysql.sql > install/sql/nagiosQL_v32_db_mysql.sql.new
mv -f install/sql/nagiosQL_v32_db_mysql.sql.new install/sql/nagiosQL_v32_db_mysql_for_nagios.sql

sed -e "s|/opt/nagios%{_sysconfdir}/objects/|%{icinga_sysconfdir}/objects|g" \
    -e "s|%{_localstatedir}/nagios/rw/nagios.cmd|%{icinga_command_file}|g" \
    -e "s|/opt/nagios/bin/nagios|%{_sbindir}/icinga|g" \
    -e "s|%{_localstatedir}/nagios/nagios.lock|%{_var}/run/icinga/icinga.pid|g" \
    -e "s|%{_sysconfdir}/nagiosql/nagios.cfg|%{icinga_sysconfdir}/icinga.cfg|g" \
        install/sql/nagiosQL_v32_db_mysql.sql > install/sql/nagiosQL_v32_db_mysql.sql.new
mv -f install/sql/nagiosQL_v32_db_mysql.sql.new install/sql/nagiosQL_v32_db_mysql_for_icinga.sql

%build
# nothing to build

%install
# install configuration directories
mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/{auth,hosts,services,backup}
mkdir    %{buildroot}/%{_sysconfdir}/%{name}/backup/{hosts,services}
# install webfronent
mkdir -p %{buildroot}/%{installdir}
cp -a * %{buildroot}/%{installdir}/
# do not package the documentation twice: we install it in docdir
rm -rf %{buildroot}/%{installdir}/doc
rm %{buildroot}/%{installdir}/*.pdf
# install apache configuration
install -Dm0644 %{SOURCE3} %{buildroot}/%{apache2_sysconfdir}/%{name}.conf
# fix rpmlint
chmod +x %{buildroot}%{_datadir}/nagiosql/scripts/do_config.php
# fdupes
%fdupes %{buildroot}/%{installdir}


%post
# Update ?
if [ ${1:-0} -eq 1 ]; then
    if [ -x %{_sbindir}/a2enmod ]; then
        %{_sbindir}/a2enmod php5 >/dev/null || :
    fi
    if [ -x %{_sbindir}/a2enflag ]; then
        %{_sbindir}/a2enflag NAGIOSQL >/dev/null || :
    fi
fi
%restart_on_update apache2

%preun
%restart_on_update apache2

%post install-nagios
if [ ! -e %{installdir}/install/sql/nagiosQL_v32_db_mysql.sql ]; then
	ln -s %{installdir}/install/sql/nagiosQL_v32_db_mysql_for_nagios.sql %{installdir}/install/sql/nagiosQL_v32_db_mysql.sql
fi

%post install-icinga
if [ ! -e %{installdir}/install/sql/nagiosQL_v32_db_mysql.sql ]; then
	ln -s %{installdir}/install/sql/nagiosQL_v32_db_mysql_for_icinga.sql %{installdir}/install/sql/nagiosQL_v32_db_mysql.sql
fi

%files
%doc doc/* *.pdf
%dir %{installdir}
%config(noreplace) %{apache2_sysconfdir}/%{name}.conf
%{installdir}/*.php
%{installdir}/*.ico
%{installdir}/admin
%{installdir}/functions
%{installdir}/images
%{installdir}/libraries
%{installdir}/scripts
%{installdir}/templates
%defattr(750,%{nagios_command_user},%{nagios_group})
%dir %{_sysconfdir}/%{name}
%{_sysconfdir}/%{name}/*
%defattr(640,wwwrun,root,0750)
%dir %{installdir}/config
%{installdir}/config/*

%files install
%{installdir}/install
%exclude %{installdir}/install/sql/nagiosQL_v32_db_mysql_for_icinga.sql
%exclude %{installdir}/install/sql/nagiosQL_v32_db_mysql_for_nagios.sql
%ghost %attr(644,root,root) %{installdir}/install/sql/nagiosQL_v32_db_mysql.sql

%files install-nagios
%{installdir}/install/sql/nagiosQL_v32_db_mysql_for_nagios.sql

%files install-icinga
%{installdir}/install/sql/nagiosQL_v32_db_mysql_for_icinga.sql

%changelog
openSUSE Build Service is sponsored by