File lychee.spec of Package lychee

#
# spec file for package lychee
#
# Copyright (c) 2024 Andreas Schneider <asn@cryptomilk.org>
#
# 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 http://bugs.opensuse.org/
#

#%%define requires_eq() %%nil
%if "x%{?lychee_php}" == "x"
%global lychee_php php8
%endif

%define lychee_configdir  %{_sysconfdir}/%{name}
%define lychee_basedir    /srv/www/webapps/%{name}
%define lychee_docroot    /srv/www/webapps/%{name}/public
%define lychee_upload     %{lychee_docroot}/uploads
%define lychee_homedir    /var/lib/%{name}
%define lychee_cachedir   /var/cache/%{name}
%define lychee_sessiondir %{lychee_cachedir}/sessions
%define lychee_tmpdir     %{lychee_cachedir}/tmp
%define lychee_logdir     /var/log/%{name}
%define lychee_upgrade_trigger %{lychee_basedir}/storage/framework/pending_upgrade

%define apparmor_dir          /etc/apparmor.d/php-fpm.d
%define php_fpm_d             /etc/%{lychee_php}/fpm/php-fpm.d
%define user_group_name       lychee

%define pkg_name Lychee

Name:           lychee
Version:        6.2.0
Release:        0
Summary:        A great looking and easy-to-use photo-management-system
License:        MIT
Group:          Productivity/Publishing/Other
URL:            https://github.com/LycheeOrg/Lychee
Source0:        %{url}/archive/refs/tags/v%{version}/%{pkg_name}-%{version}.tar.gz
Source1:        %{pkg_name}-%{version}-vendor.tar.zst
Source2:        lychee.conf
Source3:        lychee-php-fpm.conf
Source4:        lychee-apparmor.conf
Source5:        lychee-user.conf

Source10:       lychee-manage.sh
Source11:       lychee-upgrade.sh

Source20:       lychee.logrotate

Patch0:         lychee-config-path.patch
Patch1:         lychee-app-path.patch

BuildArch:      noarch

BuildRequires:  %{lychee_php}
BuildRequires:  %{lychee_php}-cli
BuildRequires:  %{lychee_php}-bcmath
BuildRequires:  %{lychee_php}-ctype
BuildRequires:  %{lychee_php}-exif
BuildRequires:  %{lychee_php}-fileinfo
BuildRequires:  %{lychee_php}-fpm
BuildRequires:  %{lychee_php}-gd
BuildRequires:  %{lychee_php}-mbstring
BuildRequires:  %{lychee_php}-mysql
BuildRequires:  %{lychee_php}-openssl
BuildRequires:  %{lychee_php}-pdo
BuildRequires:  %{lychee_php}-sodium
BuildRequires:  %{lychee_php}-tokenizer
BuildRequires:  apparmor-abstractions
BuildRequires:  apparmor-rpm-macros
BuildRequires:  fdupes
BuildRequires:  logrotate
BuildRequires:  npm
BuildRequires:  php-fpm-apparmor
BuildRequires:  rsync
BuildRequires:  zstd
Requires:       %{lychee_php}-bcmath
Requires:       %{lychee_php}-ctype
Requires:       %{lychee_php}-exif
Requires:       %{lychee_php}-fileinfo
Requires:       %{lychee_php}-gd
Requires:       %{lychee_php}-mbstring
Requires:       %{lychee_php}-mysql
Requires:       %{lychee_php}-openssl
Requires:       %{lychee_php}-sodium
Requires:       %{lychee_php}-tokenizer
Requires(post): %{lychee_php}-cli
Requires(posttrans): %{lychee_php}-cli
Requires:       sudo
Requires(post): sudo
Requires(posttrans): sudo
Recommends:     lychee-php-fpm
Recommends:     %{lychee_php}-imagick

Suggests:       logrotate


%description
Lychee is a free photo-management tool, which runs on your server or web-space.
Installing is a matter of seconds. Upload, manage and share photos like from a
native application. Lychee comes with everything you need and all your photos
are stored securely.


%package php-fpm
Group:          Productivity/Networking/Web/Utilities
%requires_eq    %{lychee_php}-fpm
%requires_eq    php-fpm-apparmor
Requires:       apparmor-abstractions
Requires:       lychee = %{version}
Requires:       %{lychee_php}-fpm
Requires:       system-user-%{name}
Summary:        Lychee - PHP FPM configuration


%description php-fpm
A great looking and easy-to-use photo-management-system.

This package holds the php-fpm configuration.

%package -n system-user-%{name}
Summary:        System user and group %{name}
BuildArch:      noarch
BuildRequires:  sysuser-tools
%sysusers_requires

%description -n system-user-%{name}
System user for use by Lychee.


%prep
%autosetup -n %{pkg_name}-%{version} -p1 -a1
find -name "\.git*" -print0 | xargs -0 rm -rf

for S in $(grep -l '#!.*php' \
    artisan \
    vendor/bin/* \
    ) ; do
        SB="${S}.backup"
        cp ${S} ${SB}
        perl -p -i -e 's|#!/usr/bin/env php|#!%{_bindir}/php|g' $S
        diff -urN ${SB} ${S} || :
        rm ${SB}
done

%build
npm run build

%sysusers_generate_pre %{SOURCE5} %{name} system-user-%{name}.conf

%install
install -d -m 0755 \
    %{buildroot}/%{lychee_basedir} \
    %{buildroot}/%{lychee_docroot}

rsync -av \
    app \
    artisan \
    bootstrap \
    config \
    database \
    lang \
    phpstan \
    resources \
    routes \
    storage \
    vendor \
    composer.json \
    composer.lock \
    index.php \
    simple_error_template.html \
    version.md \
    %{buildroot}%{lychee_basedir}

rsync -av \
    public/ \
    %{buildroot}/%{lychee_docroot}

install -d -m 0770 \
    %{buildroot}/%{lychee_configdir}  \
    %{buildroot}/%{lychee_datadir}    \
    %{buildroot}/%{lychee_sessiondir} \
    %{buildroot}/%{lychee_tmpdir}     \
    %{buildroot}/%{lychee_logdir}

install -d -m 0770 \
    %{buildroot}/%{lychee_homedir}    \
    %{buildroot}/%{lychee_homedir}/storage/framework    \

# config file
install -m 0600 %{SOURCE2} %{buildroot}%{lychee_configdir}/lychee.conf

# php-fpm
install -d -m 0755 %{buildroot}%{php_fpm_d}
install -m 0644 %{SOURCE3} %{buildroot}%{php_fpm_d}/lychee.conf

# apparmor
install -d -m 0755 %{buildroot}%{apparmor_dir}
install -m 0644 %{SOURCE4} %{buildroot}%{apparmor_dir}/lychee

# manage script
install -d -m 0755 %{buildroot}%{_sbindir}
install -m 0750 %{SOURCE10} %{buildroot}%{_sbindir}/lychee-manage
install -m 0750 %{SOURCE11} %{buildroot}%{_sbindir}/lychee-upgrade

# fix permissions
find %{buildroot}%{lychee_docroot} -type f -print0 | xargs -0 chmod -x
find %{buildroot}%{lychee_basedir}/resources -type f -print0 | xargs -0 chmod -x
find %{buildroot}%{lychee_basedir}/vendor -type f -print0 | xargs -0 chmod -x

# Cleanup vendor dir
rm -f  %{buildroot}%{lychee_basedir}/vendor/spatie/laravel-image-optimizer/phpunit.xml.dist.bak
rm -f  %{buildroot}%{lychee_basedir}/vendor/spatie/laravel-typescript-transformer/phpunit.xml.dist.bak

touch %{buildroot}/%{lychee_logdir}/upgrade.log

# logrotate
install -d -m 0755 %{buildroot}%{_sysconfdir}/logrotate.d
install -m 0644 %{SOURCE20} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

# Find duplicates
%fdupes %{buildroot}%{lychee_basedir}

install -D -m 0644 %{SOURCE5} %{buildroot}%{_sysusersdir}/system-user-%{name}.conf

%post
if grep -q "APP_KEY=SomeRandomString" %{lychee_configdir}/lychee.conf; then
    /usr/sbin/lychee-manage key:generate --force
fi

%postun
if [ -x "%{_sbindir}/lychee-upgrade" ]; then
    touch %{lychee_upgrade_trigger}
fi

%posttrans
if [ -x "%{_sbindir}/lychee-upgrade" ]; then
    %{_sbindir}/lychee-upgrade
fi

%pre -n system-user-%{name} -f %{name}.pre

%files
%license LICENSE
%doc README.md SECURITY.md

%if 0%{?suse_version} >= 1600
%dir /srv/www
%endif

%dir /srv/www/webapps

%{_sbindir}/lychee-manage
%{_sbindir}/lychee-upgrade

%dir %{_sysconfdir}/logrotate.d
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}

%defattr(-,root,%{user_group_name})
%dir %{lychee_basedir}
%{lychee_basedir}/app
%{lychee_basedir}/artisan
%dir %{lychee_basedir}/bootstrap
%{lychee_basedir}/bootstrap/app.php
%{lychee_basedir}/bootstrap/initialize.php
%{lychee_basedir}/bootstrap/PanicAttack.php
%{lychee_basedir}/bootstrap/cache
%{lychee_basedir}/config
%{lychee_basedir}/database
%{lychee_basedir}/lang
%{lychee_basedir}/phpstan
%{lychee_basedir}/resources
%{lychee_basedir}/routes
%{lychee_basedir}/simple_error_template.html
%dir %{lychee_basedir}/storage
%dir %{lychee_basedir}/storage/app
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/bootstrap
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/bootstrap/cache
%dir %{lychee_basedir}/storage/debugbar
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/framework
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/framework/cache
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/framework/cache/data
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/framework/sessions
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_basedir}/storage/framework/views
%{lychee_basedir}/storage/logs
%{lychee_basedir}/vendor
%{lychee_basedir}/composer.json
%{lychee_basedir}/composer.lock
%{lychee_basedir}/index.php
%{lychee_basedir}/version.md

%dir %{lychee_docroot}
%{lychee_docroot}/.htaccess
%{lychee_docroot}/.user.ini
%{lychee_docroot}/build
%{lychee_docroot}/dist
%{lychee_docroot}/favicon.ico
%{lychee_docroot}/fonts
%{lychee_docroot}/img
%{lychee_docroot}/index.php
%{lychee_docroot}/installer
%{lychee_docroot}/Lychee-front
%{lychee_docroot}/robots.txt
%{lychee_docroot}/storage
%{lychee_docroot}/vendor
%{lychee_docroot}/web.config

%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_docroot}/sym

%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/import
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/import/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/medium
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/medium/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/medium2x
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/medium2x/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/original
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/original/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/small
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/small/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/small2x
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/small2x/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/thumb
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/thumb/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/thumb2x
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/thumb2x/index.html
%dir %attr(0755,%{user_group_name},%{user_group_name}) %{lychee_upload}/tracks
%attr(0644,%{user_group_name},%{user_group_name}) %{lychee_upload}/tracks/index.html

%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_cachedir}
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_sessiondir}
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_tmpdir}

# /etc/lychee
%dir %attr(0750,%{user_group_name},root) %{lychee_configdir}
%config(noreplace) %attr(0640,%{user_group_name},root) %{lychee_configdir}/lychee.conf

# /var/log/lychee
%dir %attr(0750,%{user_group_name},%{user_group_name}) %{lychee_logdir}
%ghost %attr(0640,lychee,root) %{lychee_logdir}/upgrade.log

%files php-fpm
%config(noreplace) %{php_fpm_d}/lychee.conf
%config(noreplace) %{apparmor_dir}/lychee

%files -n system-user-%{name}
%{_sysusersdir}/system-user-%{name}.conf

%changelog
openSUSE Build Service is sponsored by