File icinga-web.spec of Package icinga-web

# 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.

#required icinga version
%define required_version 1.13

%define logmsg logger -t %{name}/rpm

%define logdir %{_localstatedir}/log/%{name}
%define cachedir %{_localstatedir}/cache/%{name}
%define reportingcachedir %{cachedir}/reporting

%define apacheconfdir  %{_sysconfdir}/apache2/conf.d
%define apachegroup www

Name:           icinga-web
Version:        1.13.1
Release:        0
License:        GPL-2.0
Summary:        Open Source host, service and network monitoring Web UI
Group:          System/Monitoring
Source2:        icinga-web.keyring
Source3:        README.SUSE
# PATCH-FIX-SUSE icinga-web-builddir.patch [bnc#123456]
Patch0:         icinga-web-builddir.patch
# PATCH-FIX-OPENSUSE fix-apache-conf-on-opensuse131.patch -- 13.1 has issues with new apache confs
Patch1:         fix-apache-conf-on-opensuse131.patch
BuildRequires:  nagios-rpm-macros
BuildRequires:  apache2-devel
BuildRequires:  icinga >= %{required_version}
BuildRequires:  mysql-devel
BuildRequires:  php >= 5.2.3
BuildRequires:  php-devel >= 5.2.3
BuildRequires:  php-json
BuildRequires:  php-sockets
BuildRequires:  php-xsl
BuildRequires:  php-dom
BuildRequires:  php-pear
%if 0%{?suse_version} > 1020
BuildRequires:  fdupes
BuildArch:      noarch
AutoReqProv:    Off
Requires:       mod_php_any
Requires:       bash
Requires:       coreutils
Requires:       icinga-idoutils >= %{required_version}
Requires:       pcre >= 7.6
Requires:       perl
Requires:       php >= 5.2.3
Requires:       php-pear
Requires:       php-xsl
Requires:       php-ldap
Requires:       php-pdo
Requires:       php-dom
Requires:       php-spl
Requires:       php-tokenizer
Requires:       php-xml
Requires:       php-gettext
Requires:       php-gd
Requires:       python
Requires:       php-ctype
Requires:       php-json
Recommends:     php-soap
Recommends:     php-xmlrpc
Recommends:     php-iconv
Recommends:     php-gd
Recommends:     php-hash
Recommends:     php-mysql
Recommends:     php-pgsql
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Requires(pre):  http_daemon

Icinga Web is highly dynamic and laid out as a dashboard with tabs which allow
the user to flip between different views that they need at any one time. These
can be customized to suit the users' day-to-day needs as all displays are
persistent and remain when the user returns. With an AJAX search tool, filter
capabilities, and compound commands, the differences to the classic Nagios
interface are plenty.

%package pnp_integration
Summary:        Provides the PNP integration functionality for Icinga
Group:          System/Monitoring
Requires:       %{name} = %{version}
Requires:       pnp4nagios

%description pnp_integration
The pnp_integration creates links into the Icinga web frontend to access pnp4nagios.

%setup -q
%patch0 -p1
%if 0%{?suse_version} == 1310
%patch1 -p1

export MYSQL="%{_bindir}/mysql"
export PHP="%{_bindir}/php5"
%configure \
	--prefix="%{_datadir}/%{name}" \
	--datadir="%{_datadir}/%{name}" \
	--datarootdir="%{_datadir}/%{name}" \
	--with-conf-dir="%{_sysconfdir}/%{name}" \
	--with-web-path="/%{name}" \
	--with-web-user="%{icinga_command_user}" \
	--with-web-group="%{apachegroup}" \
	--with-api-cmd-file="%{icinga_cmdfile}" \
	--with-log-dir="%{logdir}" \
	--with-cache-dir="%{cachedir}" \
	--with-reporting-tmp-dir="%{reportingcachedir}" \
	--with-web-apache-path="%{apacheconfdir}" \
	--with-icinga-bin="%{_sbindir}/icinga" \
	--with-icinga-cfg="%{icinga_sysconfdir}/icinga.cfg" \

mkdir -p %{buildroot}%{apacheconfdir}
make install scheduler-install \
    install-apache-config \
    DESTDIR=%{buildroot} \

# we only want prefixed in {_sbindir}, generated from configure
mkdir -p %{buildroot}%{_sbindir}
mv %{buildroot}%{_datadir}/%{name}/bin/ %{buildroot}%{_sbindir}/%{name}-clearcache

# wipe the rest of bin/, we don't need prepackage stuff in installed envs
rm "%{buildroot}%{_datadir}/%{name}/bin/"*

# install a link to clearcache to keep backward compatibility
ln -s %{_sbindir}/%{name}-clearcache %{buildroot}%{_datadir}/%{name}/bin/

# create new reporting cache directory and remove the original one
mkdir -p %{buildroot}%{reportingcachedir}
rm -r %{buildroot}%{_datadir}/%{name}/app/modules/Reporting/data

# install PNP_Integration
mkdir -p %{buildroot}/%{_datadir}/%{name}/app/modules/Cronks/data/xml/extensions
%{__cp} -p contrib/PNP_Integration/templateExtensions/pnp-*.xml %{buildroot}/%{_datadir}/%{name}/app/modules/Cronks/data/xml/extensions/

# install db creation script
install -d -m755 %{buildroot}%{_defaultdocdir}/%{name}/examples
install -m755 %{SOURCE4} %{buildroot}%{_defaultdocdir}/%{name}/examples

# install documentation
mkdir -p %{buildroot}/%{_defaultdocdir}/%{name}
pushd %{buildroot}/%{_datadir}/%{name}/doc/ 1>/dev/null
    cp LICENSE CHANGELOG* %{SOURCE3} %{buildroot}/%{_defaultdocdir}/%{name}/
popd 1>/dev/null
rm -r %{buildroot}/%{_datadir}/%{name}/doc

# remove unneeded files and dirs
find %{buildroot}%{_datadir}/%{name} -name .htaccess -delete
find %{buildroot}%{_datadir}/%{name} -name .keep -delete

# save space, use symlinks
%if 0%{?suse_version} > 1020
    %fdupes %{buildroot}


# If apache is installed, and we can find the apache user, set a shell var
if [ -f etc/apache2/uid.conf ]; then
    wwwusr=$(awk '/^[ \t]*User[ \t]+[a-zA-Z0-9]+/ {print $2}' etc/apache2/uid.conf)
    wwwusr=$(awk '/^[ \t]*User[ \t]+[a-zA-Z0-9]+/ {print $2}' etc/apache2/*.conf)
if [ "z" == "z$wwwusr" ]; then # otherwise, use the default
# if apache user is not in icinga_command_group, add it
if /usr/bin/id -Gn $wwwusr 2>/dev/null | /bin/grep -q %{icinga_command_group} > /dev/null 2>&1 ; then
    : # $wwwusr (default: %%{icinga_command_user}) is already in %%{icinga_command_group} group
    # modify apache user, adding it to icinga_command_group
    %if 0%{?suse_version} > 1220
        usermod -a -G %{icinga_command_group} $wwwusr
        groupmod -A $wwwusr %{icinga_command_group} 2>/dev/null

if [ "$1" = "1" ]; then
    # this is the initial installation: enable icinga
    test -x %{_sbindir}/a2enflag && %{_sbindir}/a2enflag ICINGAWEB >/dev/null
a2enmod rewrite

%{logmsg} "icinga-web installed: Don't forget to install/upgrade your db schema,  check /usr/share/doc/packages/icinga-web/README.SUSE"

%restart_on_update apache2

%restart_on_update apache2

if [ "$1" = "0" ]; then
	# deinstallation of the package - remove the apache flag
	test -x %{_sbindir}/a2disflag && %{_sbindir}/a2disflag ICINGAWEB >/dev/null
	%restart_on_update apache2

%post pnp_integration

%postun pnp_integration
%if 0%{?suse_version} >= 1110
    if [ -f %{_sbindir}/%{name}-clearcache ]; then

# main dirs
%dir %{_datadir}/%{name}
%exclude %{_datadir}/%{name}/app/modules/Cronks/data/xml/extensions/pnp-*-extension.xml
# only temporary, for backward compability
%dir %{_datadir}/%{name}/bin
# documentation
%doc %{_defaultdocdir}/%{name}
# configs
%config(noreplace) %attr(-,root,root) %{apacheconfdir}/icinga-web.conf
%dir %{_sysconfdir}/%{name}
%config(noreplace) %attr(644,root,root) %{_sysconfdir}/%{name}/*.xml
# logs+cache
%attr(-,%{icinga_command_user},%{apachegroup}) %dir %{logdir}
%dir %attr(-,%{icinga_command_user},%{apachegroup}) %{cachedir}
%dir %attr(-,%{icinga_command_user},%{apachegroup}) %{cachedir}/config
# data directory writable for web server
%attr(-,%{icinga_command_user},%{apachegroup})  %{_datadir}/%{name}/app/data/tmp
# report permissions
%dir %attr(-,%{icinga_command_user},%{apachegroup}) %dir %{reportingcachedir}

%files pnp_integration
%doc contrib/PNP_Integration/README contrib/PNP_Integration/INSTALL 
%doc contrib/nginx
%doc contrib/PNP_Integration/doc/CHANGELOG
%dir %{_datadir}/icinga-web/app/modules/Cronks/data/xml/extensions
%config(noreplace) %attr(644,root,root) %{_datadir}/%{name}/app/modules/Cronks/data/xml/extensions/*