File etherpad-lite.spec of Package etherpad-lite

#
# spec file for package etherpad-lite
#
# Copyright (c) 2014-2025 SUSE LLC and openSUSE contributors
#
# 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 install_dir /srv/www/etherpad-lite
%define log_dir     %{_var}/log/%{name}
%define home_dir    %{_var}/lib/%{name}
%bcond_with    systemd

Name:           etherpad-lite
Version:        2.1.1
Release:        0
Summary:        An Etherpad based on node.js
License:        Apache-2.0
Group:          Productivity/Networking/Web/Utilities
Url:            https://github.com/ether/etherpad-lite
# reference etherpad-lite-README.openSUSE
Source:         etherpad-lite-%{version}.tar.gz
Source1:        vendor.tar.xz
Source9:        %{name}-rpmlintrc
Source10:       %{name}.service
Source11:       etherpad-lite.logrotate
Source13:       etherpad-lite-README.openSUSE
Source14:       etherpad-lite.apparmor
Source15:       etherpad-lite.apparmor.tunables.home
Patch0:         etherpad-lite_default_config.patch
Patch1:         etherpad-lite_move_autogenerated_key_files_to_var.patch
Patch2:         etherpad-lite_avoid_getGitCommit_call.patch
Requires:       apparmor-abstractions
Requires:       nodejs >= 12.17.0
Requires:       curl
Requires:       logrotate
Requires:       pnpm
Recommends:     abiword
BuildRequires:  systemd
%{?systemd_requires}
BuildRequires:  apparmor-abstractions
BuildRequires:  apparmor-rpm-macros
BuildRequires:  nodejs >= 12.17.0
BuildRequires:  npm >= 12.17.0
BuildRequires:  postgresql-devel
BuildRequires:  gcc-c++
BuildRequires:  python3
BuildRequires:  rsync
BuildRequires:  sysuser-tools
BuildRequires:  yarn
%sysusers_requires

%description
An Etherpad based on node.js

- Our goal is to make collaborative editing the standard on the web.

%prep
%autosetup -n %{name}-%{version} -a 1 -p 1
install -m644 %{SOURCE13} README.openSUSE
find . -executable -type f -execdir sed -i '1!b;s|/usr/bin/env |/usr/bin/|' {} +
chmod -R a-x doc/api/*
# refactored cleanup logic forked from AUR https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=etherpad-lite (thanks <3)
find . -type f \
  \( \
    -name '*.gitignore' -o \
    -name '*Dockerfile*' -o \
    -name '*Makefile*' -o \
    -name '*appveyor.yml' -o \
    -name '*.babelrc' -o \
    -name '*.bak' -o \
    -name '*bower.json' -o \
    -name '*.c' -o \
    -name '*.cc' -o \
    -name '*.cpp' -o \
    -name '*.markdown' -o \
    -name '*.rst' -o \
    -name '*.nycrc' -o \
    -name '*.npmignore' -o \
    -name '*.editorconfig' -o \
    -name '*.el' -o \
    -name '*.eslintignore' -o \
    -name '*.eslintrc*' -o \
    -name '*.fimbullinter.yaml' -o \
    -name '*.gitattributes' -o \
    -name '*.gitmodules' -o \
    -name '*.h' -o \
    -name '*.jshintrc' -o \
    -name '*.jscs.json' -o \
    -name '*.log' -o \
    -name '*logo.svg' -o \
    -name '*.nvmrc' -o \
    -name '*.o' -o \
    -name '*package-lock.json' -o \
    -name '*.travis.yml' -o \
    -name '*.prettierrc' -o \
    -name '*.sh' -o \
    -name '*.tags*' -o \
    -name '*.tm_properties' -o \
    -name '*.wotanrc.yaml' -o \
    -name '*tsconfig.json' -o \
    -name '*yarn.lock' \
  \) \
  -delete
find . -type d \
  \( \
    -wholename '*.github' -o \
    -wholename '*.tscache' -o \
    -wholename '*/man' -o \
    -wholename '*/test' -o \
    -wholename '*/scripts' -o \
    -wholename '*/git-hooks' \
  \) \
  -prune \
  -execdir rm -r {} +

# dangling symlinks which no longer exist after the cleanup above
find . -type l \
  -wholename '*/test' \
  -delete

# Debian specific files
rm -r bin/deb-src

# Rubbish?
rm -r doc/.vitepress

tee > %{name}.sysuser <<EOF
u %{name} - "etherpad-lite daemon user" %{home_dir} -
EOF

%build
echo done > src/.ep_initialized

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

pushd node_modules/.pnpm/flatted*/node_modules/flatted/python/
%py3_compile .
popd

%install
install -d %{buildroot}%{install_dir} \
           %{buildroot}%{home_dir}    \
           %{buildroot}%{log_dir}     \
           %{buildroot}%{_sbindir}

install -d %{buildroot}%{install_dir}/var
install -d %{buildroot}%{install_dir}/plugin_packages

rsync -a admin bin doc node_modules src ui %{buildroot}%{install_dir}

touch %{buildroot}%{home_dir}/{APIKEY.txt,SESSIONKEY.txt}

# install settings.json to sysconfdir
install -Dm640 settings.json.template       %{buildroot}%{_sysconfdir}/%{name}/settings.json

chmod -R u=rwX,g=rX,o= %{buildroot}%{_sysconfdir} %{buildroot}%{install_dir}
chmod -R u=rwX,go=     %{buildroot}%{home_dir}    %{buildroot}%{log_dir}

install -d %{buildroot}%{_unitdir}
sed 's|__FULL_PATH_TO__|%{install_dir}|g' %{S:10} > %{buildroot}%{_unitdir}/%{name}.service
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}

# logrotate snipplet
install -Dm644 %{S:11} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

# Ownership of standard log file
touch %{buildroot}%{log_dir}/%{name}.log

install -Dm644 %{name}.sysuser %{buildroot}%{_sysusersdir}/%{name}.conf

install -Dm644 %{SOURCE14} %{buildroot}%{_sysconfdir}/apparmor.d/etherpad
install -Dm644 %{SOURCE15} %{buildroot}%{_sysconfdir}/apparmor.d/tunables/home.d/etherpad

%pre -f %{name}.pre
# START BIG SYSTEMD
%if 0%{?suse_version}
%service_add_pre %{name}.service
%endif

%preun
%if 0%{?suse_version}
%service_del_preun %{name}.service
%else
%systemd_preun %{name}.service
%endif

%post
%{apparmor_reload %{_sysconfdir}/apparmor.d/etherpad}
for i in APIKEY.txt SESSIONKEY.txt ; do
  if [ -e %{install_dir}/$i ] ; then
    mv %{install_dir}/$i  %{home_dir}/$i #||:
    chown %{name}:%{name} %{home_dir}/$i #||:
    chmod u=rw,go=        %{home_dir}/$i #||:
  fi
done
%if 0%{?suse_version}
%service_add_post %{name}.service
%else
%systemd_post %{name}.service
%endif

%postun
%if 0%{?suse_version}
%service_del_postun %{name}.service
%else
%systemd_postun_with_restart %{name}.service
%endif

%files
%defattr(-,root,root)
%doc CHANGELOG.md CONTRIBUTING.md LICENSE README.md settings.json.template README.openSUSE
%doc doc/
%config(noreplace) /etc/logrotate.d/etherpad-lite
%{_sbindir}/rc%{name}
%{_unitdir}/%{name}.service
%defattr(-,root,%{name})
%config(noreplace) %{_sysconfdir}/%{name}/
%dir /srv/www
%dir %{install_dir}
%{install_dir}/admin
%{install_dir}/bin
%{install_dir}/doc
%{install_dir}/node_modules
%{install_dir}/plugin_packages
%{install_dir}/src
%{install_dir}/ui
%attr(0750,%{name},%{name}) %{install_dir}/var
%config(noreplace) %ghost %attr(0600,%{name},%{name})  %{home_dir}/APIKEY.txt
%ghost %config(noreplace) %ghost %attr(0600,%{name},%{name})  %{home_dir}/SESSIONKEY.txt
%dir   %attr(0700,%{name},%{name}) %{log_dir}
%ghost %attr(0600,%{name},%{name}) %{log_dir}/%{name}.log
%dir   %attr(0700,%{name},%{name}) %{home_dir}
%{_sysusersdir}/%{name}.conf
%config %{_sysconfdir}/apparmor.d/etherpad
%config %{_sysconfdir}/apparmor.d/tunables/home.d/etherpad

%changelog
openSUSE Build Service is sponsored by