File phpMyFAQ.spec of Package phpMyFAQ

#
# spec file for package phpMyFAQ
#
# Copyright (c) 2025 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/
#


# See also http://en.opensuse.org/openSUSE:Specfile_guidelines

%define source_name phpmyfaq
%define phpmyfaqroot /usr/share/php/%{source_name}
%define minphpversion 8.2.0

Name:           phpMyFAQ
Version:        4.0.12
Release:        0
Summary:        FAQ-Software in php
License:        MPL-2.0
Group:          Productivity/Networking/Web/Frontends
URL:            http://www.phpmyfaq.de
Source0:        http://www.phpmyfaq.de/download/%{name}-%{version}.tar.gz
Source1:        %{name}.conf
Source2:        %{name}-README.SUSE
Source10:       %{name}-%{version}-vendor.tar.gz
Source11:       %{name}-%{version}-node_modules.tar.gz
Source12:       %{name}-%{version}-node_modules-build.tar.gz
Source98:       %{name}-rpmlintrc
Patch2:         %{name}-htaccess.patch
Patch3:         %{name}-remove-OpenTelemetry.patch
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  apache-rpm-macros
BuildRequires:  fdupes
Requires:       nodejs >= 22.0.0
Requires:       php-curl >= %{minphpversion}
Requires:       php-fileinfo >= %{minphpversion}
Requires:       php-filter >= %{minphpversion}
Requires:       php-gd >= %{minphpversion}
Requires:       php-intl >= %{minphpversion}
Requires:       php-json >= %{minphpversion}
Requires:       php-mbstring >= %{minphpversion}
Requires:       php-mysql >= %{minphpversion}
Requires:       php-session >= %{minphpversion}
Requires:       php-sodium >= %{minphpversion}
Requires:       php-spl >= %{minphpversion}
Requires:       php-xmlwriter >= %{minphpversion}
Requires:       php-zip >= %{minphpversion}

%description
phpMyFAQ is a multilingual, scalable, completely database-driven FAQ software
using php

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

%description apache
This subpackage contains the Apache configuration files

%prep
#%%setup -q -n %%{source_name}
%setup -q -b 10 -b 11 -b 12 -n %{name}

%patch -P 2 -p1
%patch -P 3 -p1
install -m644 %{SOURCE2} .
# remove OpenTelemetry
rm -rf src/libs/open-telemetry
# rpmlint suse-filelist-forbidden
find . -type f -name '*.orig' -exec rm {} \;
find . -type f -name '.gitignore' -exec rm {} \;
find . -type f -name '*.sh' -exec sed -i -e 's|\/usr\/bin\/env bash|\/usr\/bin\/bash|g' {} \;
# rpmlint zero-length
find . -type f -name '.gitkeep' -exec rm {} \;

%build
# Nothing to build

%install
install -d -m0755 %{buildroot}%{phpmyfaqroot}
install -d -m0755 %{buildroot}%{_sysconfdir}/%{source_name}
install -d -m0755 %{buildroot}%{phpmyfaqroot}/attachments
install -d -m0755 %{buildroot}%{phpmyfaqroot}/data
install -d -m0755 %{buildroot}%{phpmyfaqroot}/images
cp -dR phpmyfaq/* %{buildroot}%{phpmyfaqroot}
##install phpmyfaq.conf to apache conf.d
##install -D -m0640 %%{SOURCE1} %%{buildroot}%%{apache_sysconfdir}/conf.d/%%{source_name}.conf
# install patched .htaccess to apache conf.d
install -D -m0640 phpmyfaq/.htaccess %{buildroot}%{apache_sysconfdir}/conf.d/%{source_name}.conf
ln -s %{apache_sysconfdir}/conf.d/%{source_name}.conf %{buildroot}%{phpmyfaqroot}/.htaccess
# move phpmyfaq configfiles to sysconfdir
mv %{buildroot}%{phpmyfaqroot}/content/core/config/* \
   %{buildroot}%{_sysconfdir}/%{source_name}
rm -d %{buildroot}%{phpmyfaqroot}/content/core/config
ln -s %{_sysconfdir}/%{source_name} %{buildroot}%{phpmyfaqroot}/content/core/config
# generate file list
find %{buildroot}%{phpmyfaqroot} -mindepth 1 -maxdepth 1 -type d | sed -e "s@%{buildroot}@@" > FILELIST
find %{buildroot}%{phpmyfaqroot} -maxdepth 1 -type f | sed -e "s@%{buildroot}@@" >> FILELIST
# rpmlint
%fdupes %{buildroot}%{phpmyfaqroot}

%pre
# only on update move old config to upstream orig old config path
if [ "$1" -gt 1 ] ; then
  if [ -d "/etc/phpmyfaq" ] ; then
    if [ ! -e "%{phpmyfaqroot}/content/core/config" ] ; then
      echo "o %{name} pre-install: Move/Copy files to new location..."
      mkdir -m 0750 %{phpmyfaqroot}/config || :
      cp -aR /etc/phpmyfaq/* %{phpmyfaqroot}/config/ || :
    fi
  fi
fi

%post
%{__chown} -R %{apache_user}:%{apache_group} %{phpmyfaqroot}
# only on update move to new location
if [ "$1" -gt 1 ] ; then
  if [ -d "/srv/www/phpmyfaq" ] ; then
    echo "o %{name} post-install: Move/Copy files to new location..."
    cp -aR /srv/www/phpmyfaq/attachments/* %{phpmyfaqroot}/attachments/ || :
    cp -aR /srv/www/phpmyfaq/data/* %{phpmyfaqroot}/data/ || :
    cp -aR /srv/www/phpmyfaq/images/* %{phpmyfaqroot}/images/ || :
    rm -rf /srv/www/phpmyfaq || :
  fi
  if [ -e "%{phpmyfaqroot}/content/core/config" ] ; then
    # remove old orig files from version < 4 again after update
    rm -rf %{phpmyfaqroot}/config
  fi
fi

%post apache
%restart_on_update apache2

%postun apache
%restart_on_update apache2

%files -f FILELIST
%doc %{name}-README.SUSE
%dir %{_datadir}/php
%defattr(640,root,root,750)
%dir %attr(0770,root,%{apache_group}) %{_sysconfdir}/%{source_name}
%config(noreplace) %attr(640,%{apache_user},%{apache_group}) %{_sysconfdir}/%{source_name}/*
%dir %attr(0750,%{apache_user},%{apache_group}) %{phpmyfaqroot}

%files apache
%config(noreplace) %attr(640,%{apache_user},%{apache_group}) %{apache_sysconfdir}/conf.d/%{source_name}.conf
%{phpmyfaqroot}/.htaccess

%changelog
openSUSE Build Service is sponsored by