File icingaweb2.spec of Package icingaweb2

# Icinga Web 2 | (c) 2013-2017 Icinga Development Team | GPLv2+

%define revision 1

Name:           icingaweb2
Version:        2.11.4
Release:        %{revision}%{?dist}
Summary:        Icinga Web 2
Group:          Applications/System
License:        GPLv2+ and MIT and BSD
URL:            https://icinga.com
Source0:        https://github.com/Icinga/%{name}/archive/v%{version}.tar.gz
Source1:		icingaweb2-rpm.tgz
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}
Packager:       Icinga GmbH <info@icinga.com>

%if 0%{?fedora} || 0%{?rhel} || 0%{?amzn}
%if 0%{?rhel} == 7
%define php_scl         rh-php73
%endif

%if 0%{?el5}%{?el6}%{?amzn}
%define use_selinux 0
%else
%define use_selinux 1
%endif

%if 0%{?php_scl:1}
%define php_scl_prefix  %{php_scl}-
%define php_runtime     %{php_scl_prefix}php-fpm
%define php_bin         /opt/rh/%{php_scl}/root/usr/bin/php
%define php_fpm         1
%else
%define php_runtime     %{php}
%endif

%define php             %{?php_scl_prefix}php
%define php_cli         %{php}-cli
%define php_common      %{php}-common
%define wwwconfigdir    %{_sysconfdir}/httpd/conf.d
%define wwwuser         apache

# extra requirements on RHEL
Requires:               %{php}-mysqlnd
Requires:               %{php}-pgsql
Requires:               %{php}-ldap
%endif

# minimum required PHP version
%define php_version 8.0

# unsupported PHP version
%define php_unsupported_version 8.3

%if 0%{?suse_version}
%define wwwconfigdir    %{_sysconfdir}/apache2/conf.d
%define wwwuser         wwwrun
%define php             php
%define php_runtime     mod_php_any
%define php_common      %{php}
%define php_cli         %{php}
%endif

%{?amzn:Requires(pre):          shadow-utils}
%{?fedora:Requires(pre):        shadow-utils}
%{?rhel:Requires(pre):          shadow-utils}
%{?suse_version:Requires(pre):  pwdutils}

Requires:                       %{php_runtime} >= %{php_version}
Requires:                       %{php_common} >= %{php_version}
Conflicts:                      %{php_runtime} >= %{php_unsupported_version}
%if 0%{?suse_version}
Requires:                       apache2
%endif

Requires:                       icinga-l10n >= 1.3.0
Requires:                       icingacli = %{version}-%{release}
Requires:                       %{name}-common = %{version}-%{release}
Requires:                       php-Icinga = %{version}-%{release}
Requires:                       icinga-php-library >= 0.13.1
Requires:                       icinga-php-thirdparty >= 0.12.1

%define basedir         %{_datadir}/%{name}
%define bindir          %{_bindir}
%define storagedir      %{_sharedstatedir}/%{name}
%define configdir       %{_sysconfdir}/%{name}
%define logdir          %{_localstatedir}/log/%{name}
%define phpdir          %{_datadir}/php
%define icingawebgroup  icingaweb2
%define docsdir         %{_datadir}/doc/%{name}


%description
Icinga Web 2


%package common
Summary:                        Common files for Icinga Web 2 and the Icinga CLI
Group:                          Applications/System
%{?amzn:Requires(pre):          shadow-utils}
%{?fedora:Requires(pre):        shadow-utils}
%{?rhel:Requires(pre):          shadow-utils}
%{?suse_version:Requires(pre):  pwdutils}
%if 0%{?suse_version} > 1320
Requires(pre):                  system-user-wwwrun
%endif

%description common
Common files for Icinga Web 2 and the Icinga CLI


%package -n php-Icinga
Summary:                    Icinga Web 2 PHP library
Group:                      Development/Libraries
Obsoletes:                  php-Icinga <= 2.12.0
Obsoletes:                  icingaweb2-vendor-dompdf <= 2.12.0
Obsoletes:                  icingaweb2-vendor-HTMLPurifier <= 1:2.12.0
Obsoletes:                  icingaweb2-vendor-JShrink <= 2.12.0
Obsoletes:                  icingaweb2-vendor-lessphp <= 2.12.0
Obsoletes:                  icingaweb2-vendor-Parsedown <= 2.12.0
Obsoletes:                  icingaweb2-vendor-zf1 <= 2.12.0
Requires:                   %{php_common} >= %{php_version}
Requires:                   %{php}-gd %{php}-intl %{php}-mbstring
%if 0%{?sle_version} >= 150200
Requires:                   %{php}-dom %{php}-curl %{php}-fileinfo
%endif
%{?rhel:Requires:           %{php}-pdo %{php}-xml}
%if 0%{?rhel} >= 8 || 0%{?fedora} >= 30
Requires:                   %{php}-json
%endif rhel >= 8 || fedora >= 30
%{?amzn:Requires:           %{php}-pecl-imagick}
%{?fedora:Requires:         php-pecl-imagick}
%{?suse_version:Requires:   %{php}-gettext %{php}-json %{php}-openssl %{php}-posix}

Requires:                  icinga-php-library >= 0.13.1
Requires:                  icinga-php-thirdparty >= 0.12.1

%description -n php-Icinga
Icinga Web 2 PHP library


%package -n icingacli
Summary:                    Icinga CLI
Group:                      Applications/System
Requires:                   icinga-l10n >= 1.3.0
Requires:                   %{name}-common = %{version}-%{release}
Requires:                   php-Icinga = %{version}-%{release}
Requires:                   icinga-php-library >= 0.13.1
Requires:                   icinga-php-thirdparty >= 0.12.1
Requires:                   bash-completion
Requires:                   %{php_cli} >= %{php_version}


%description -n icingacli
Icinga CLI


%if 0%{?use_selinux}
%define selinux_variants mls targeted

%package selinux
Summary:        SELinux policy for Icinga Web 2
BuildRequires:  checkpolicy, selinux-policy-devel, hardlink
Requires:           %{name} = %{version}-%{release}
Requires(post):     policycoreutils
Requires(postun):   policycoreutils

%description selinux
SELinux policy for Icinga Web 2
%endif

%prep
%setup -q -D -T -b 0
mkdir sources && cd sources
gzip -dc %{SOURCE1} | tar -xvvf -
cd ..

#%if 0%{?use_selinux}
#mkdir selinux
#cp -p packages/selinux/icingaweb2.{fc,if,te} selinux
#%endif

%build
%if 0%{?use_selinux}
cd sources/SELinux
for selinuxvariant in %{selinux_variants}
do
  make NAME=${selinuxvariant} -f /usr/share/selinux/devel/Makefile
  mv icingaweb2.pp icingaweb2.pp.${selinuxvariant}
  make NAME=${selinuxvariant} -f /usr/share/selinux/devel/Makefile clean
done
cd -
%endif

%install

install -d %{buildroot}/%{basedir}
cp -pr application doc library modules public schema %{buildroot}/%{basedir}
install -dm 2770 %{buildroot}/%{_sysconfdir}/icingaweb2 %{buildroot}/%{_sysconfdir}/icingaweb2/{enabledModules,modules}
install -Dpm 0644 etc/bash_completion.d/icingacli %{buildroot}/%{_datadir}/bash-completion/completions/icingacli
cp -p sources/index.php %{buildroot}/%{basedir}/public
install -d %{buildroot}/%{_datadir}/php
mv %{buildroot}/%{basedir}/library/Icinga %{buildroot}/%{_datadir}/php
install -dm 2770 %{buildroot}/%{_localstatedir}/cache/icingaweb2 %{buildroot}/%{_sharedstatedir}/icingaweb2
install -dm 2775 %{buildroot}/%{logdir}/icingaweb2
install -Dpm 0644 sources/icingaweb2.conf %{buildroot}/%{wwwconfigdir}/icingaweb2.conf
install -Dpm 0755 sources/icingacli %{buildroot}/%{_bindir}/icingacli

%if 0%{?use_selinux}
for selinuxvariant in %{selinux_variants}
do
	install -Dpm 0644 sources/SELinux/icingaweb2.pp.${selinuxvariant} %{buildroot}/%{_datadir}/selinux/${selinuxvariant}/icingaweb2.pp
done
cd -
# TODO: Fix build problems on Icinga, see https://github.com/Icinga/puppet-icinga_build/issues/11
#/usr/sbin/hardlink -cv %{buildroot}%{_datadir}/selinux
%endif

%pre
getent group icingacmd >/dev/null || groupadd -r icingacmd
%if 0%{?suse_version} && 0%{?suse_version} < 01200
usermod -A icingacmd,%{icingawebgroup} %{wwwuser}
%else
usermod -a -G icingacmd,%{icingawebgroup} %{wwwuser}
%endif
exit 0

%clean
rm -rf %{buildroot}

%files
%doc CHANGELOG.md
%doc README.md
%docdir /%{basedir}/doc
%license LICENSE
/%{basedir}/application/controllers
/%{basedir}/application/fonts
/%{basedir}/application/forms
/%{basedir}/application/layouts
/%{basedir}/application/views
/%{basedir}/application/VERSION
/%{basedir}/doc
/%{basedir}/modules
/%{basedir}/public
/%{basedir}/schema
%if 0%{?suse_version}
# for lint on OBS
%dir %{dirname:%{wwwconfigdir}}
%dir %{wwwconfigdir}
%endif
%config(noreplace) %{wwwconfigdir}/icingaweb2.conf

%pre common
getent group %{icingawebgroup} >/dev/null || groupadd -r %{icingawebgroup}
exit 0

%files common
%attr(-, -, icingaweb2) %dir %{_localstatedir}/cache/icingaweb2
%attr(-, -, icingaweb2) %dir %{logdir}/icingaweb2
%attr(-, -, icingaweb2) %dir %{_sharedstatedir}/icingaweb2
%attr(-, -, icingaweb2) %config(noreplace) %dir %{_sysconfdir}/icingaweb2
%attr(-, -, icingaweb2) %config(noreplace) %dir %{_sysconfdir}/icingaweb2/modules
%attr(-, -, icingaweb2) %dir %{_sysconfdir}/icingaweb2/enabledModules

%files -n php-Icinga
%defattr(-,root,root)
%if 0%{?suse_version}
# for lint on OBS
%dir %{phpdir}
%endif
%{phpdir}/Icinga

%files -n icingacli
%defattr(-,root,root)
%license LICENSE
%{basedir}/application/clicommands
%{_datadir}/bash-completion/completions/icingacli
%{bindir}/icingacli

%if 0%{?use_selinux}
%post selinux
for selinuxvariant in %{selinux_variants}
do
  %{_sbindir}/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/icingaweb2.pp &> /dev/null || :
done
%{_sbindir}/restorecon -R %{basedir} &> /dev/null || :
%{_sbindir}/restorecon -R %{configdir} &> /dev/null || :
%{_sbindir}/restorecon -R %{logdir} &> /dev/null || :
%{_sbindir}/restorecon -R %{storagedir} &> /dev/null || :


%postun selinux
if [ $1 -eq 0 ] ; then
  for selinuxvariant in %{selinux_variants}
  do
     %{_sbindir}/semodule -s ${selinuxvariant} -r icingaweb2 &> /dev/null || :
  done
  [ -d %{basedir} ] && %{_sbindir}/restorecon -R %{basedir} &> /dev/null || :
  [ -d %{configdir} ] && %{_sbindir}/restorecon -R %{configdir} &> /dev/null || :
  [ -d %{logdir} ] && %{_sbindir}/restorecon -R %{logdir} &> /dev/null || :
  [ -d %{storagedir} ] && %{_sbindir}/restorecon -R %{storagedir} &> /dev/null || :
fi

%files selinux
%license LICENSE
%{_datadir}/selinux/*/icingaweb2.pp
%endif


%changelog
* Wed Jul 06 2022 Johannes Meyer <johannes.meyer@icinga.com> 2.11.1-1
- Update to 2.11.1

* Thu Jun 30 2022 Eric Lippmann <eric.lippmann@icinga.com> 2.11.0-1
- Update to 2.11.0

* Wed Apr 06 2022 Johannes Meyer <johannes.meyer@icinga.com> 2.10.1-1
- Update to 2.10.1

* Wed Mar 23 2022 Johannes Meyer <johannes.meyer@icinga.com> 2.10.0-1
- Update to 2.10.0

* Tue Mar 08 2022 Johannes Meyer <johannes.meyer@icinga.com> 2.9.6-1
- Update to 2.9.6

* Thu Nov 18 2021 Henrik Triem <henrik.triem@icinga.com> 2.9.5-1
- Update to 2.9.5

* Wed Nov 10 2021 Johannes Meyer <johannes.meyer@icinga.com> 2.9.4-1
- Update to 2.9.4

* Tue Aug 10 2021 Johannes Meyer <johannes.meyer@icinga.com> 2.9.3-1
- Update to 2.9.3

* Wed Jul 28 2021 Johannes Meyer <johannes.meyer@icinga.com> 2.9.2-1
- Update to 2.9.2

* Tue Jul 27 2021 Johannes Meyer <johannes.meyer@icinga.com> 2.9.1-1
- Update to 2.9.1

* Thu Jul 8 2021 Johannes Meyer <johannes.meyer@icinga.com> 2.9.0-1
- Update to 2.9.0

* Tue Aug 18 2020 Johannes Meyer <johannes.meyer@icinga.com> 2.8.2-1
- Update to 2.8.2

* Mon Jun 29 2020 Johannes Meyer <johannes.meyer@icinga.com> 2.8.1-1
- Update to 2.8.1

* Mon Jun 8 2020 Johannes Meyer <johannes.meyer@icinga.com> 2.8.0-1
- Update to 2.8.0
- Add new requirement for package icinga-l10n
- [EPEL 7] We now require PHP 7.3 instead of PHP 7.1
- Please check uprading docs at /usr/share/icingaweb2/doc/80-Upgrading.md

* Fri Oct 18 2019 Johannes Meyer <johannes.meyer@icinga.com> 2.7.3-1
- Update to 2.7.3

* Wed Oct 16 2019 Johannes Meyer <johannes.meyer@icinga.com> 2.7.2-1
- Update to 2.7.2

* Wed Aug 14 2019 Johannes Meyer <johannes.meyer@icinga.com> 2.7.1-1
- Update to 2.7.1

* Tue Jul 30 2019 Johannes Meyer <johannes.meyer@icinga.com> 2.7.0-1
- Update to 2.7.0

* Wed Apr 24 2019 Johannes Meyer <johannes.meyer@icinga.com> 2.6.3-1
- Update to 2.6.3

* Wed Nov 21 2018 Eric Lippmann <eric.lippmann@icinga.com> 2.6.2-1
- Update to 2.6.2

* Thu Aug 02 2018 Eric Lippmann <eric.lippmann@icinga.com> 2.6.1-1
- Update to 2.6.1

* Thu Jul 19 2018 Blerim Sheqa <blerim.sheqa@icinga.com> 2.6.0-1
- Update to 2.6.0

* Fri Apr 27 2018 Eric Lippmann <eric.lippmann@icinga.com> 2.5.3-1
- Update to 2.5.3

* Thu Apr 26 2018 Eric Lippmann <eric.lippmann@icinga.com> 2.5.2-1
- Update to 2.5.2

* Mon Jan 22 2018 Markus Frosch <markus.frosch@icinga.com> 2.5.1-1
- Update to 2.5.1
- Remove FPM patches

* Wed Nov 29 2017 Eric Lippmann <eric.lippmann@icinga.com> 2.5.0-2
- FPM: Add patch to support both Apache >= 2.4 and Apache < 2.4

* Tue Nov 28 2017 Eric Lippmann <eric.lippmann@icinga.com> 2.5.0-1
- Install error_unavailable.html
- Add patch to fix Apache FPM config

* Mon Nov 27 2017 Markus Frosch <markus.frosch@icinga.com> 2.5.0-1
- Update to 2.5.0
- All packages now require PHP >= 5.6
- [EPEL 6 + 7] We now require PHP 7 from SCL packages, php-fpm as runtime engine
- [SUSE / openSUSE] Requirements will force the installation of php7
- Please check upgrading docs at /usr/share/icingaweb2/doc/80-Upgrading.md

* Thu Sep 28 2017 Markus Frosch <markus.frosch@icinga.com> 2.4.2-1
- Update to 2.4.2
openSUSE Build Service is sponsored by