File privatebin.spec of Package privatebin

#
# spec file for package privatebin
#
# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2020 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 https://bugs.opensuse.org/
#

%if "x%{?privatebin_php}" == "x"
%global privatebin_php php8
%endif

%define privatebin_configdir  %{_sysconfdir}/%{name}/
%define privatebin_basedir    /srv/www/webapps/%{name}/
%define privatebin_docroot    /srv/www/webapps/%{name}/public/
%define privatebin_datadir    /srv/www/webapps/%{name}/data/
%define privatebin_homedir    /var/lib/%{name}/
%define privatebin_cachedir   /var/cache/%{name}/
%define privatebin_sessiondir %{privatebin_cachedir}/sessions/
%define privatebin_tmpdir     %{privatebin_cachedir}/tmp/
%define privatebin_logdir     /var/log/%{name}/

%global privatebin_services privatebin-purge.service privatebin-purge.timer

%define apparmor_dir          /etc/apparmor.d/php-fpm.d
%define php_fpm_d             /etc/%{privatebin_php}/fpm/php-fpm.d
%define user_group_name       privatebin

Name:           privatebin
Version:        2.0.3
Release:        1%{?dist}
Summary:        A minimalist pastebin with zero knowledge of pasted data

License:        Zlib
URL:            https://privatebin.info
Group:          Productivity/Networking/Web/Utilities
Source0:        https://github.com/PrivateBin/PrivateBin/archive/%{version}/PrivateBin-%{version}.tar.gz
Source1:        https://github.com/PrivateBin/PrivateBin/releases/download/%{version}/PrivateBin-%{version}.tar.gz.asc
Source2:        privatebin.asc
Source3:        privatebin-php-fpm.conf
Source4:        privatebin-apparmor.conf
Source5:        README.SUSE.md
Source6:        privatebin-purge.service
Source7:        privatebin-purge.timer

Source99:       privatebin-rpmlintrc

BuildArch:      noarch
BuildRequires:  php-fpm-apparmor
BuildRequires:  apparmor-abstractions
BuildRequires:  apparmor-rpm-macros
BuildRequires:  fdupes
BuildRequires:  rsync
BuildRequires:  %{privatebin_php}-fpm
BuildRequires:  %{privatebin_php}-gd
%requires_eq    %{privatebin_php}-gd
Requires:       system-user-%{name}
Recommends:     privatebin-php-fpm

%description
PrivateBin is a minimalist, open source online pastebin where the server has
zero knowledge of pasted data.

Data is encrypted and decrypted in the browser using 256bit AES in Galois
Counter mode.

PrivateBin:
- As a server administrator you don't have to worry if your users post content
  that is considered illegal in your country. You have no knowledge of any of
  the pastes content. If requested or enforced, you can delete any paste from
  your system.
- Pastebin-like system to store text documents, code samples, etc.
- Encryption of data sent to server.
- Possibility to set a password which is required to read the paste. It further
  protects a paste and prevents people stumbling upon your paste's link from
  being able to read it without the password.

%package php-fpm
Group:          Productivity/Networking/Web/Utilities
%requires_eq    %{privatebin_php}-fpm
%requires_eq    php-fpm-apparmor
Requires:       apparmor-abstractions
Requires:       privatebin = %{version}
Summary:        PrivateBin - PHP FPM configuration
%description php-fpm
PrivateBin is a minimalist, open source online pastebin where the server has
zero knowledge of pasted data.

This package holds the php-fpm configuration.

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

%description -n system-user-%{name}
System user for PrivateBin.

%prep
%autosetup -p1 -n PrivateBin-%{version}

for S in $(grep -l '#!.*php' \
    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

tee > %{name}.sysuser <<EOF
u %{user_group_name} - "PrivateBin" %{privatebin_basedir} -
EOF


%build
cp %{SOURCE5} README.SUSE.md
install -d -m 0755 public
mv index.php public/index.php
sed -i "s#^define('PATH'.*#define('PATH', '%{privatebin_basedir}');#" public/index.php

find -name .htaccess -delete

cp cfg/conf.sample.php cfg/conf.php

for d in                   \
        css                \
        i18n               \
        img                \
        js                 \
        browserconfig.xml  \
        manifest.json      \
        robots.txt         \
        .htaccess.disabled \
        ; do
    mv $d public/
done

%sysusers_generate_pre %{name}.sysuser %{name}

%install
install -d -m 0755 \
    %{buildroot}/%{privatebin_basedir} \
    %{buildroot}/%{privatebin_docroot}

install -d -m 0770 \
    %{buildroot}/%{privatebin_configdir}  \
    %{buildroot}/%{privatebin_datadir}    \
    %{buildroot}/%{privatebin_homedir}    \
    %{buildroot}/%{privatebin_sessiondir} \
    %{buildroot}/%{privatebin_tmpdir}     \
    %{buildroot}/%{privatebin_logdir}

rsync -av ${PWD}/ %{buildroot}%{privatebin_basedir}/
rm -rf %{buildroot}%{privatebin_basedir}/cfg
rm -f  %{buildroot}%{privatebin_basedir}/Makefile
rm -f  %{buildroot}%{privatebin_basedir}/Procfile
rm -f  %{buildroot}%{privatebin_basedir}/*.md
rm -f  %{buildroot}%{privatebin_basedir}/codacy-analysis.yml
rm -f  %{buildroot}%{privatebin_basedir}/crowdin.yml
rm -f  %{buildroot}%{privatebin_basedir}/%{name}.pre
rm -f  %{buildroot}%{privatebin_basedir}/%{name}.sysuser

rsync -av ${PWD}/cfg/ %{buildroot}%{privatebin_configdir}/

install -d -m 0755 \
    %{buildroot}%{apparmor_dir}        \
    %{buildroot}%{php_fpm_d}

install -m 0644 %{SOURCE3} %{buildroot}%{php_fpm_d}/privatebin.conf
install -m 0644 %{SOURCE4} %{buildroot}%{apparmor_dir}/privatebin

install -d -m 0755 %{buildroot}%{_unitdir}
install -m 0644 %{SOURCE6} %{buildroot}%{_unitdir}/privatebin-purge.service
install -m 0644 %{SOURCE7} %{buildroot}%{_unitdir}/privatebin-purge.timer

install -d -m 0755 %{buildroot}%{_sbindir}
ln -s /sbin/service %{buildroot}%{_sbindir}/rcprivatebin-purge

install -d -m 0755 %{buildroot}%{_sysusersdir}
install -m 0644 %{name}.sysuser %{buildroot}%{_sysusersdir}/%{name}.conf

%pre
%service_add_pre %{privatebin_services}

%post
%service_add_post %{privatebin_services}

%post php-fpm
%apparmor_reload /etc/apparmor.d/usr.sbin.php-fpm
%service_add_post %{privatebin_services}

%postun
%service_del_postun %{privatebin_services}

%preun
%service_del_preun %{privatebin_services}

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

%files
%license LICENSE.md
%doc README.md README.SUSE.md CHANGELOG.md SECURITY.md CREDITS.md

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

%dir /srv/www/webapps

%defattr(-,root,%{user_group_name})
%dir %{privatebin_configdir}
%config(noreplace) %{privatebin_configdir}/conf.php
%config %{privatebin_configdir}/conf.sample.php

%dir %{privatebin_basedir}
%{privatebin_basedir}/composer.json
%{privatebin_basedir}/composer.lock
%{privatebin_basedir}/bin
%{privatebin_basedir}/lib
%{privatebin_basedir}/tpl
%{privatebin_basedir}/vendor

%dir %{privatebin_docroot}
%{privatebin_docroot}/css
%{privatebin_docroot}/i18n
%{privatebin_docroot}/img
%{privatebin_docroot}/js
%{privatebin_docroot}/.htaccess.disabled
%{privatebin_docroot}/browserconfig.xml
%{privatebin_docroot}/index.php
%{privatebin_docroot}/manifest.json
%{privatebin_docroot}/robots.txt

%dir %{privatebin_datadir}
%dir %{privatebin_cachedir}
%dir %{privatebin_sessiondir}
%dir %{privatebin_tmpdir}
%dir %{privatebin_logdir}
%dir %{privatebin_homedir}

%defattr(-,root,root)
%{_sbindir}/rcprivatebin-purge
%{_unitdir}/privatebin-purge.service
%{_unitdir}/privatebin-purge.timer

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

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

%changelog
openSUSE Build Service is sponsored by