File matomo.spec of Package matomo

# spec file for package matomo
# 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

# See also

%define apxs %{_sbindir}/apxs2
%define ap_sysconfdir %(%{apxs} -q SYSCONFDIR)
%define ap_serverroot %(%{apxs} -q PREFIX)

%if 0%{?suse_version}
%define ap_usr wwwrun
%define ap_grp www
%define ap_usr nobody
%define ap_grp nogroup

Name:           matomo
Version:        3.9.1
Release:        0
Summary:        Web analytics platform
License:        GPL-3.0-or-later
Group:          Productivity/Networking/Web/Utilities
Source2:        %{name}.conf
Source3:        %{name}.logrotate
Source4:        %{name}-README.SUSE
Source10:       %{name}-archive.cron
Source11:       %{name}-archive.service
Source12:       %{name}-archive.timer
Source99:       %{name}.rpmlintrc
BuildArch:      noarch
%if 0%{?suse_version} >= 1500
Requires(pre):  user(%ap_usr)
Requires(pre):  group(%ap_grp)
Requires(pre):  aaa_base
BuildRequires:  apache2-devel
BuildRequires:  cron
BuildRequires:  fdupes
BuildRequires:  logrotate
BuildRequires:  mariadb
#BuildRequires:  php-json
#BuildRequires:  php-mbstring
#BuildRequires:  php-pdo
BuildRequires:  systemd
BuildRequires:  unzip
Requires:       apache2
Requires:       cron
Requires:       logrotate
Requires:       mariadb
Requires:       mod_php_any >= 5.5.9
Requires:       php-curl
Requires:       php-gd
Requires:       php-json
Requires:       php-mbstring
Requires:       php-mysql
Requires:       php-pdo
Recommends:     php-geoip
Recommends:     apache2-mod_geoip

Conflicts:      piwik

Matomo, formerly Piwik, is a web analytics platform that gives
insights into a website's visitors and marketing campaigns, so the
strategy and online experience of visitors may be optimized.

%setup -q -n matomo
install -m644 %{SOURCE4} README.SUSE
# remove unwanted files
find . -type f "(" -name .htaccess -o -name ")" -delete
#find . -name ".git*" -exec rm -Rf "{}" "+"
find . -type f "(" -name "*.c" -o -name "*.h" ")" -delete
# env-script-interpreter
find . -type f -exec sed -i -e 's|\/usr\/bin\/env php|\/usr\/bin\/php|g' {} +

# nothing to build

# make directories
install -d -m0755 %{buildroot}/%{ap_serverroot}/%{name}
install -d -m0755 %{buildroot}/%{_sysconfdir}/%{name}
install -d -m0755 %{buildroot}/%{_defaultdocdir}/%{name}
# copy src from build to buildroot
mv *SUSE %{buildroot}/%{_defaultdocdir}/%{name}
mv LEGALNOTICE %{buildroot}/%{_defaultdocdir}/%{name}
mv LICENSE %{buildroot}/%{_defaultdocdir}/%{name}
mv "misc/How to install Matomo.html" %{buildroot}/%{_defaultdocdir}/%{name}
mv *md %{buildroot}/%{_defaultdocdir}/%{name}
cp -dR * %{buildroot}/%{ap_serverroot}/%{name}
# install matomo.conf to apache conf.d
install -D -m0640 %{SOURCE2} %{buildroot}/%{ap_sysconfdir}/conf.d/%{name}.conf
# install logrotate
install -D -m0644 %{SOURCE3} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}
# move config to etc/matomo and make symlink
mv %{buildroot}/%{ap_serverroot}/%{name}/config/* \
rm -d %{buildroot}/%{ap_serverroot}/%{name}/config
ln -s %{_sysconfdir}/%{name} %{buildroot}/%{ap_serverroot}/%{name}/config
# install cronscript and systemd-timer
install -d -m 0755 %{buildroot}/%{_sysconfdir}/cron.d
install -d -m 0755 %{buildroot}/var/log/%{name}
install -D -m 0644 %{SOURCE10} %{buildroot}/%{_sysconfdir}/cron.d/%{name}-archive
install -D -m 0644 %{SOURCE11} %{buildroot}%{_unitdir}/%{name}-archive.service
install -D -m 0644 %{SOURCE12} %{buildroot}%{_unitdir}/%{name}-archive.timer
sed -i -e 's|@ap_serverroot@|%{ap_serverroot}|g' %{buildroot}%{_sysconfdir}/cron.d/%{name}-archive
sed -i -e 's|@ap_serverroot@|%{ap_serverroot}|g' %{buildroot}%{_unitdir}/%{name}-archive.service

%fdupes %{buildroot}/%{_prefix}
%fdupes %{buildroot}/srv

%service_add_pre matomo-archive.timer matomo-archive.service

chown -R %{ap_usr}:%{ap_grp} %{ap_serverroot}/%{name}
%service_add_post matomo-archive.timer matomo-archive.service apache2.service
# Update matomo if this is an upgrade $1 == 2
echo "matomo: Update matomo:core..."
if [ $1 -gt 1 ]; then
  su wwwrun -s /bin/sh -c "%{_bindir}/php %{ap_serverroot}/%{name}/console config:set 'Tracker.record_statistics="0"'" || :
  su wwwrun -s /bin/sh -c "%{_bindir}/php %{ap_serverroot}/%{name}/console config:set 'General.maintenance_mode="1"'" || :
  su wwwrun -s /bin/sh -c "%{_bindir}/php %{ap_serverroot}/%{name}/console core:update --yes" || :
  su wwwrun -s /bin/sh -c "%{_bindir}/php %{ap_serverroot}/%{name}/console config:set 'General.maintenance_mode="0"'" || :
  su wwwrun -s /bin/sh -c "%{_bindir}/php %{ap_serverroot}/%{name}/console config:set 'Tracker.record_statistics="1"'" || :

%service_del_preun matomo-archive.timer matomo-archive.service

%service_del_postun matomo-archive.timer matomo-archive.service apache2.service

%dir %{_defaultdocdir}/%{name}
%config(noreplace) %{ap_sysconfdir}/conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/cron.d/%{name}-archive
%dir %attr(0750,%{ap_usr},%{ap_grp}) %{_sysconfdir}/%{name}
%dir %attr(0750,%{ap_usr},%{ap_grp}) %{_sysconfdir}/%{name}/environment
%dir %{ap_serverroot}/%{name}
%dir /var/log/%{name}
%config(noreplace)  %attr(600,%{ap_usr},%{ap_grp}) %{_sysconfdir}/%{name}/*php
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/console
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/misc/cron/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/misc/log-analytics/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/misc/composer/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/misc/composer/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/leafo/lessphp/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/leafo/lessphp/lessify
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/leafo/lessphp/plessc
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/pear/archive_tar/sync-php4
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/szymach/c-pchart/
%attr(0770,%{ap_usr},%{ap_grp}) %{ap_serverroot}/%{name}/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php

openSUSE Build Service is sponsored by