File ampache.spec of Package ampache

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


Name:           ampache
Version:        6.4.0
Release:        0
Summary:        PHP-Based MP3 Database Web Interface
License:        AGPL-3.0-or-later
Group:          Productivity/Networking/Web/Frontends
URL:            http://www.ampache.org/
Source:         https://github.com/ampache/ampache/archive/%{version}/%{name}-%{version}.tar.gz
Source1:        httpd.conf.ampache
Source2:        ampache-rpmlintrc
Source5:        ampache-README.SUSE
Source10:       ampache-%{version}-vendor.tar.gz
Patch1:         ampache-confpath.patch
Patch2:         ampache-config.patch
Patch3:         ampache-systemd.patch
BuildRequires:  apache-rpm-macros
BuildRequires:  fdupes
###Requires:       http_daemon
Requires:       php-bz2
Requires:       php-composer
Requires:       php-curl
Requires:       php-exif
Requires:       php-gd
Requires:       php-gettext
Requires:       php-hash
Requires:       php-iconv
Requires:       php-intl
Requires:       php-json
Requires:       php-mysql
Requires:       php-pdo
Requires:       php-session
Requires:       php-zlib
Recommends:     %{name}-lang = %{version}
Recommends:     flac
Recommends:     vorbis-tools
BuildArch:      noarch
%{?systemd_requires}

%description
Ampache is a PHP-based tool for managing, updating, and playing your
MP3 files via a Web interface. It allows you to save play lists, create
user accounts, and share your music catalogs with other Ampache
servers. It uses a MySQL database.

Read the README files about configuring ampache.

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

%description apache
This subpackage contains the Apache configuration files

%lang_package

%prep
%setup -q -b 10
%patch -P 1 -p1
%patch -P 2 -p1
%patch -P 3 -p1
# rpmlint: unwanted files
find . -type f -name \*.orig -print0 | xargs -0 --no-run-if-empty rm -rf
find . -type d -name CVS -print0 | xargs -0 --no-run-if-empty rm -rf
rm `find . -name ".empty" -or -name ".gitignore" -or -name ".travis.yml" -or -name "*.php.orig"`
# rpmlint: non-executable-script
find . -type f -name "*.sh" -print0 | xargs -0 chmod ugo+x
# rpmlint: script-without-shebang
chmod -x public/albums.php
chmod -x public/artists.php
chmod -x public/install.php
chmod -x public/server/json.server.php
chmod -x public/upnp/control-reply.php
find ./public/themes -type f -exec chmod -x {} \;
find ./public/templates -type f -exec chmod -x {} \;
find ./src/Module -type f -exec chmod -x {} \;
find ./vendor -type f -exec chmod -x {} \;
# remove example from vendor because of link error
rm -rf vendor/php-tmdb/api/examples
# remove exe files
find . -type f -name "*.exe" -print0 | xargs -0 --no-run-if-empty rm -rf
# fix env-script-interpreter
find . -type f -exec sed -i -e 's|/usr/bin/env php|/usr/bin/php|g' {} \;
find . -type f -exec sed -i -e 's|/usr/bin/env python|/usr/bin/python|g' {} \;
find . -type f -exec sed -i -e 's|/usr/bin/env perl|/usr/bin/perl|g' {} \;
find . -type f -exec sed -i -e 's|/usr/bin/env bash|/bin/bash|g' {} \;
find . -type f -exec sed -i -e 's|/usr/bin/env sh|/bin/bash|g' {} \;
# rpmlint: htaccess-file
rm public/daap/.htaccess \
   public/lib/javascript/.htaccess \
   public/play/.htaccess.dist \
   public/rest/.htaccess.dist \
   public/server/.htaccess \
   public/templates/.htaccess

%build

%install
ampache_root=%{buildroot}/%{apache_serverroot}/ampache
mkdir -p $ampache_root
mkdir -p %{buildroot}%{apache_sysconfdir}/conf.d
mkdir -p %{buildroot}%{_sysconfdir}/ampache
mkdir -p %{buildroot}%{_localstatedir}/log/ampache
mkdir -p %{buildroot}%{_docdir}/%{name}
install -m 644 %{SOURCE1} %{buildroot}%{apache_sysconfdir}/conf.d/ampache.conf
install -m 644 %{SOURCE5} README.SUSE
# fix apache things
sed -i -e 's|@APACHE_SERVERROOT@|%{apache_serverroot}|g' %{buildroot}%{apache_sysconfdir}/conf.d/ampache.conf
sed -i -e 's|@APACHE_SERVERROOT@|%{apache_serverroot}|g' README.SUSE
#
cp -a bin locale public resources src tests vendor $ampache_root/
cp -a *.php composer.* $ampache_root/
cp -p config/ampache.cfg.php.dist %{buildroot}%{_sysconfdir}/ampache/ampache.cfg.php.dist
cp -p config/ampache.cfg.php.dist %{buildroot}%{_sysconfdir}/ampache/ampache.cfg.php
cp -p config/registration_agreement.php.dist %{buildroot}%{_sysconfdir}/ampache/registration_agreement.php.dist
cp -p config/registration_agreement.php.dist %{buildroot}%{_sysconfdir}/ampache/registration_agreement.php
#
ln -s -f %{apache_serverroot}/%{name}/resources/sql/ampache.sql %{buildroot}%{_docdir}/%{name}/ampache.sql
# cron service
install -D -m 0644 docs/examples/%{name}_cron.service %{buildroot}%{_unitdir}/%{name}-cron.service
install -D -m 0644 docs/examples/%{name}_cron.timer %{buildroot}%{_unitdir}/%{name}-cron.timer
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-cron
#
%fdupes %{ampache_root}
# man pages
gzip docs/man/man1/ampache.1
# find language files
%find_lang %{name} --all-name

%pre
%service_add_pre %{name}-cron.service %{name}-cron.timer

%post
%service_add_post %{name}-cron.service %{name}-cron.timer
# only after update
if [ "$1" -gt 1 ]; then
  echo "o %{name} post-install: Update Database after update of package..."
  su %{apache_user} -s /bin/sh -c "cd %{apache_serverroot}/%{name}; PATH=%{_bindir}:$PATH php bin/cli admin:updateDatabase -e" || :
fi

%preun
%service_del_preun %{name}-cron.service %{name}-cron.timer

%postun
%service_del_postun %{name}-cron.service %{name}-cron.timer

%files
%defattr(644,root,root,755)
%doc docs/* README* config
%{_docdir}/%{name}/ampache.sql
%defattr(-,root,root)
%{_unitdir}/%{name}-cron.service
%{_unitdir}/%{name}-cron.timer
%{_sbindir}/rc%{name}-cron
%dir %{_sysconfdir}/ampache
%config(noreplace) %attr(660,root,%{apache_group}) %{_sysconfdir}/ampache/ampache.cfg.php
%config(noreplace) %attr(660,root,%{apache_group}) %{_sysconfdir}/ampache/registration_agreement.php
%config %attr(640,root,%{apache_group}) %{_sysconfdir}/ampache/ampache.cfg.php.dist
%config %attr(640,root,%{apache_group}) %{_sysconfdir}/ampache/registration_agreement.php.dist
%dir %attr(-,%{apache_user},root) %{_localstatedir}/log/ampache
%dir %attr(775,root,%{apache_group}) %{apache_serverroot}/ampache
%{apache_serverroot}/ampache/*.php
%dir %{apache_serverroot}/ampache/bin
%config(noreplace) %{apache_serverroot}/ampache/bin/*
%{apache_serverroot}/ampache/locale
%exclude %{apache_serverroot}/%{name}/locale/*/LC_MESSAGES/messages.mo
%exclude %{apache_serverroot}/%{name}/vendor/scn/phptal/tests/files/locale/*/LC_MESSAGES/*.mo
%{apache_serverroot}/ampache/public
%{apache_serverroot}/ampache/resources
%{apache_serverroot}/ampache/src
%{apache_serverroot}/ampache/tests
%{apache_serverroot}/ampache/vendor
%dir %{apache_serverroot}/ampache/public/templates
%config %{apache_serverroot}/ampache/public/templates/*
%{apache_serverroot}/ampache/composer.*

%files apache
%config (noreplace) %{apache_sysconfdir}/conf.d/%{name}.conf

%files lang -f %{name}.lang

%changelog
openSUSE Build Service is sponsored by