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

%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.9.1
Release:        0
License:        GPL-2.0
Summary:        Open Source host, service and network monitoring Web UI
Url:            http://www.icinga.org/
Group:          System/Monitoring
Source0:        http://downloads.sourceforge.net/project/icinga/icinga-web/%{version}/icinga-web-%{version}.tar.gz
Source1:        http://downloads.sourceforge.net/project/icinga/icinga-web/%{version}/icinga-web-%{version}.tar.gz.asc
Source2:        icinga-web.keyring
Source3:        README.SUSE
Source4:        create_mysqldb.sh
# PATCH-FIX-SUSE icinga-web-builddir.patch [bnc#123456]
Patch1:         icinga-web-builddir.patch
# PATCH-FIX-SUSE icinga-web-apache.conf.patch - Fix Apache permissions
Patch2:         icinga-web-apache.conf.patch
%if 0%{?suse_version} >= 1230
BuildRequires:  gpg-offline
%endif
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
%endif
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


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

%package BPAddon
Summary:        Provides the business process cronk for Icinga
Group:          System/Monitoring
Requires:       %{name} = %{version}
Requires:       php-sqlite

%description BPAddon
The BPAddon creates links into the Icinga web frontend to access the business process addon

%prep
%{?gpg_verify: %gpg_verify %{S:1}}
%setup -q
%patch1 -p1
%patch2 -p1
#fix 1.8.2 E: spurious-executable-perm (Badness: 50)
chmod -x contrib/businessprocess-icinga-cronk/doc/*
chmod -x contrib/PNP_Integration/doc/*

%build
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" \
	--with-icinga-objects-dir="%{icinga_sysconfdir}/objects"


%install
mkdir -p %{buildroot}%{apacheconfdir}
make install scheduler-install \
    install-apache-config \
    DESTDIR=%{buildroot} \
    INSTALL_OPTS="" \
    INSTALL_OPTS_WEB="" \
    INSTALL_OPTS_CACHE="" \
    COMMAND_OPTS="" \
    INIT_OPTS=""

# we only want clearcache.sh prefixed in {_sbindir}, generated from configure
mkdir -p %{buildroot}%{_sbindir}
mv %{buildroot}%{_datadir}/%{name}/bin/clearcache.sh %{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/clearcache.sh

# 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 BPAddon
cd contrib/businessprocess-icinga-cronk
sed -i -e 's|/usr/local/nagiosbp/etc|/etc/icinga/nagiosbp|' \
	-e 's|/usr/local/nagiosbp/bin|%{_bindir}|' BPAddon/config/bp.xml
sed -i -e 's|<ae:parameter name="pass">icingaadmin</ae:parameter>|<ae:parameter name="pass">password</ae:parameter>|g' BPAddon/config/cronks.xml
echo -e "y\n%{buildroot}/%{_datadir}/%{name}"| ./install.sh
cd -

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

%post
%{name}-clearcache

# 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)
else
    wwwusr=$(awk '/^[ \t]*User[ \t]+[a-zA-Z0-9]+/ {print $2}' etc/apache2/*.conf)
fi
if [ "z" == "z$wwwusr" ]; then # otherwise, use the default
    wwwusr=%{icinga_command_user}
fi
# 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
else
    # modify apache user, adding it to icinga_command_group
    %if 0%{?suse_version} > 1220
        usermod -a -G %{icinga_command_group} $wwwusr
    %else
        groupmod -A $wwwusr %{icinga_command_group} 2>/dev/null
    %endif
fi

if [ "$1" = "1" ]; then
    # this is the initial installation: enable icinga
    test -x %{_sbindir}/a2enflag && %{_sbindir}/a2enflag ICINGAWEB >/dev/null
fi
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

%preun
%restart_on_update apache2

%postun
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
fi


%post pnp_integration
%{name}-clearcache

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

%post BPAddon
%{name}-clearcache

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

%files
# main dirs
%defattr(-,root,root)
%dir %{_datadir}/%{name}
%exclude %{_datadir}/%{name}/app/modules/Cronks/data/xml/extensions/pnp-*-extension.xml
%exclude %{_datadir}/%{name}/app/modules/BPAddon
%{_datadir}/%{name}/app
%{_datadir}/%{name}/etc
%{_datadir}/%{name}/lib
%{_datadir}/%{name}/pub
# only temporary, for backward compability
%dir %{_datadir}/%{name}/bin
%{_datadir}/%{name}/bin/clearcache.sh
# documentation
%doc %{_defaultdocdir}/%{name}
# configs
%defattr(-,root,root)
%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
# report permissions
%dir %attr(-,%{icinga_command_user},%{apachegroup}) %dir %{reportingcachedir}
#binaries
%defattr(-,root,root)
%{_sbindir}/%{name}-clearcache

%files pnp_integration
%defattr(-,root,root)
%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/*

%files BPAddon
%defattr(-,root,root)
%doc contrib/businessprocess-icinga-cronk/doc/CHANGELOG
%doc contrib/businessprocess-icinga-cronk/doc/INSTALL
%dir %{_datadir}/%{name}/app/modules/BPAddon
%dir %{_datadir}/%{name}/app/modules/BPAddon/config
%config(noreplace) %{_datadir}/%{name}/app/modules/BPAddon/config/*.xml
%{_datadir}/%{name}/app/modules/BPAddon/actions
%{_datadir}/%{name}/app/modules/BPAddon/lib
%{_datadir}/%{name}/app/modules/BPAddon/models
%{_datadir}/%{name}/app/modules/BPAddon/pub
%{_datadir}/%{name}/app/modules/BPAddon/templates
%{_datadir}/%{name}/app/modules/BPAddon/validate
%{_datadir}/%{name}/app/modules/BPAddon/views


%changelog