File humhub.spec of Package humhub

#
# spec file for package humhub
#
# Copyright (c) 2021 SUSE LLC
#
# 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}/php/%{name}
Name:           humhub
Version:        1.17.4
Release:        0
Summary:        Open Source Social Network
License:        AGPL-3.0-or-later
Group:          Productivity/Networking/Web/Utilities
URL:            https://www.humhub.com/
Source:         %{name}-%{version}.tar.xz
#
# zypper install php-composer
# cd humhub
# composer install --no-dev --no-scripts --ignore-platform-reqs
#  => check "scripts" section in composer.json
# export version=%%{version}; tar -cvJf ../humhub-${version}-vendor.tar.xz protected/vendor/
#
Source1:        %{name}-%{version}-vendor.tar.xz
Source2:        humhub-apache.conf
Source3:        humhub-cron.service
Source4:        humhub-cron.timer
Source5:        humhub-queue.service
Source6:        humhub-queue.timer
Source10:       humhub-rpmlintrc
BuildRequires:  apache-rpm-macros
BuildRequires:  fdupes
BuildRequires:  logrotate
BuildRequires:  mariadb
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(systemd)
Requires:       php-curl
Requires:       php-exif
Requires:       php-fileinfo
Requires:       php-gd
Requires:       php-intl
Requires:       php-mbstring
Requires:       php-mysql
Requires:       php-pdo
Requires:       php-zip
Requires(pre):  php >= 8.1
Recommends:     php-APCu
Recommends:     php-ldap
Recommends:     php-memcached
BuildArch:      noarch

%description
HumHub is a feature rich and highly flexible OpenSource Social Network Kit
written in PHP.

It's perfect for individual:

* Social Intranets
* Enterprise Social Networks
* Private Social Networks

%package apache
Summary:        Apache configuration for %{name}
Group:          Productivity/Networking/Web/Utilities
BuildRequires:  apache2
Requires:       apache2
Requires:       mod_php_any >= 8.1
Supplements:    (apache2 and %name)

%description apache
This subpackage contains the Apache configuration files

%prep
%setup -q -a1
# remove unwanted files
for file in .editorconfig .eslintrc .eslintrc.json .gitattributes .gitkeep .htaccess .npmignore .php_cs .php_cs.dist .phpstorm.meta.php .rake_t_cache .sami.php .scrutinizer.yml .travis.yml .travis.sh .travis.install.sh .jshintrc .stylelintrc ; do
  find . -type f -name $file -delete
done
find . -type f "(" -name "*.c" -o -name "*.h" -o -name "*.js.orig" -o -name "yii.bat" -o -name ".gitignore" -o -name ".coveralls.yml" -o -name ".prettierignore" -o -name ".eslintignore" -o -name ".tm_properties" -o -name ".zuul.yml" -o -name ".nycrc" -o -name ".codoopts" -o -name ".jscsrc" -o -name ".jshintignore"  ")" -delete
for dir in .github .idea .travis; do
	find . -type d -name "$dir" -prune -exec rm -rf {} + || :
done

# env-script-interpreter
find . -type f -exec sed -i -e 's|\/usr\/bin\/env php|\/usr\/bin\/php|g' {} +

%build
# nothing to build

%install
install -d -m0755 %{buildroot}/%{installdir}

# copy src from build to buildroot
cp -dR * %{buildroot}/%{installdir}/
rm %{buildroot}/%{installdir}/*.md

# create missing directories
mkdir -p %{buildroot}%{installdir}/uploads/icon %{buildroot}%{installdir}/uploads/logo_image

# install apache config
mkdir -p %{buildroot}/%{apache_sysconfdir}/conf.d
sed -e 's|__humhub_web__|%{installdir}|g' \
    -e 's|__humhub_conf__|%{_sysconfdir}/%{name}|g' \
    -e 's|__humhub_log__|%{_localstatedir}/log/%{name}|g' \
    %{SOURCE2} > %{buildroot}/%{apache_sysconfdir}/conf.d/%{name}.conf
# cron timer
install -D -m 644 %{SOURCE4} %{buildroot}/%{_unitdir}/humhub-cron.timer
install -D -m 644 %{SOURCE6} %{buildroot}/%{_unitdir}/humhub-queue.timer
# cron job
sed -e 's|__humhub_web__|%{installdir}|g' \
	%{SOURCE3} > %{buildroot}/%{_unitdir}/humhub-cron.service
sed -e 's|__humhub_web__|%{installdir}|g' \
	%{SOURCE5} > %{buildroot}/%{_unitdir}/humhub-queue.service

# reduce size, run fdupes
%fdupes %{buildroot}/%{installdir}

%pre
%service_add_pre humhub-cron.timer humhub-queue.timer

%post
%service_add_post humhub-cron.timer humhub-queue.timer

%post apache
# extra post here because of rights apache_user
# nginx for example has other user
if [ $1 -gt 1 ]; then
  echo "o %{name}: cache/flush-all..."
  su %{apache_user} -s /bin/sh -c "%{_bindir}/php %{installdir}/protected/yii cache/flush-all --interactive=0" || :
  echo "o %{name}: migrate/up..." 
  su %{apache_user} -s /bin/sh -c "%{_bindir}/php %{installdir}/protected/yii migrate/up --include-module-migrations=1 --interactive=0" || :
  echo "o %{name}: module/update-all..."
  su %{apache_user} -s /bin/sh -c "%{_bindir}/php %{installdir}/protected/yii module/update-all --interactive=0" || :
fi

%preun
%service_del_preun humhub-cron.timer humhub-queue.timer

%postun
%service_del_postun humhub-cron.timer humhub-queue.timer

%files
%defattr(0644,root,root,0755)
%doc *.md
%dir %{_datadir}/php
%dir %{installdir}
%dir %{installdir}/protected
%{_unitdir}/humhub-cron.timer
%{_unitdir}/humhub-cron.service
%{_unitdir}/humhub-queue.timer
%{_unitdir}/humhub-queue.service
%attr(0755,root,root) %{installdir}/protected/yii
%config(noreplace) %{installdir}/index.php
%{installdir}/LICENSE
%{installdir}/LICENSE.AGPL-3.0-or-later
%{installdir}/index-test.php
%{installdir}/protected/config/README.md
%{installdir}/uploads/index.html
%{installdir}/static
%{installdir}/themes
%{installdir}/protected/humhub
%{installdir}/protected/vendor
%{installdir}/*json
%{installdir}/*.js
%{installdir}/*.txt
%{installdir}/*.lock

%files apache
# dirs here because of rights apache_user and apach_group
# nginx for example has other rights
%config(noreplace) %{apache_sysconfdir}/conf.d/%{name}.conf
%defattr(0640,%{apache_user},%{apache_group},0750)
%dir %{installdir}/protected/runtime
%dir %{installdir}/assets
%dir %{installdir}/protected/config
%config(noreplace) %{installdir}/protected/config/*.php
%dir %{installdir}/protected/modules
%dir %{installdir}/uploads
%dir %{installdir}/uploads/file
%{installdir}/uploads/file/*
%dir %{installdir}/uploads/icon
%dir %{installdir}/uploads/logo_image
%dir %{installdir}/uploads/profile_image
%{installdir}/uploads/profile_image/*

%changelog
openSUSE Build Service is sponsored by