File matrix-synapse.spec of Package matrix-synapse
#
# spec file for package matrix-synapse
#
# Copyright (c) 2023 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/
#
%global rustflags '-Clink-arg=-Wl,-z,relro,-z,now'
%define pythons python311
Name: matrix-synapse
Version: 1.108.0
Release: 0
Summary: Homeserver for the Matrix decentralised comms protocol
License: Apache-2.0
Group: Productivity/Networking/Instant Messenger
URL: https://element-hq.github.io/synapse/
Source: matrix-synapse-%{version}.tar.xz
Source1: vendor.tar.xz
Source2: cargo_config
Source10: %{name}-user.conf
Source11: %{name}-tmpfiles
Source12: %{name}-sysconfig
Source13: %{name}-default
Source14: %{name}-service
Source15: %{name}-wrapper
Source16: %{name}-logrotate
Source17: %{name}.apache
Source18: %{name}.apache-vhost
Source19: %{name}.well-known-server
Source20: %{name}-firewalld
Source21: %{name}-firewall
Source30: %{name}-init.sh
Source31: %{name}-generate-new-config.sh
Source90: README.SUSE
Source99: %{name}-rpmlintrc
BuildRequires: cargo
BuildRequires: cargo-packaging
BuildRequires: fdupes
BuildRequires: firewall-macros
BuildRequires: python-rpm-macros
BuildRequires: systemd-rpm-macros
BuildRequires: sysuser-tools
BuildRequires: %{python_module pip}
BuildRequires: %{python_module wheel}
BuildRequires: %{python_module poetry-core >= 1.1.0}
BuildRequires: %{python_module setuptools-rust >= 1.3}
# /SECTION STANDARD
BuildRequires: %{python_module jsonschema >= 4.22.0}
%requires_ge %{python_flavor}-jsonschema
BuildRequires: %{python_module immutabledict >= 4.2.0}
%requires_ge %{python_flavor}-immutabledict
BuildRequires: %{python_module unpaddedbase64 >= 2.1.0}
%requires_ge %{python_flavor}-unpaddedbase64
BuildRequires: %{python_module canonicaljson >= 2.0.0}
%requires_ge %{python_flavor}-canonicaljson
BuildRequires: %{python_module signedjson >= 1.1.0}
%requires_ge %{python_flavor}-signedjson
BuildRequires: %{python_module service_identity >= 18.1.0}
%requires_ge %{python_flavor}-service_identity
BuildRequires: %{python_module Twisted >= 18.9.0}
%requires_ge %{python_flavor}-Twisted
BuildRequires: %{python_module treq >= 15.1}
%requires_ge %{python_flavor}-treq
BuildRequires: %{python_module pyOpenSSL >= 16.0.0}
%requires_ge %{python_flavor}-pyOpenSSL
BuildRequires: %{python_module PyYAML >= 3.13}
%requires_ge %{python_flavor}-PyYAML
BuildRequires: %{python_module pyasn1 >= 0.1.9}
%requires_ge %{python_flavor}-pyasn1
BuildRequires: %{python_module pyasn1-modules >= 0.0.7}
%requires_ge %{python_flavor}-pyasn1-modules
BuildRequires: %{python_module bcrypt >= 3.1.7}
%requires_ge %{python_flavor}-bcrypt
BuildRequires: %{python_module Pillow >= 10.3.0}
%requires_ge %{python_flavor}-Pillow
BuildRequires: %{python_module sortedcontainers >= 1.5.2}
%requires_ge %{python_flavor}-sortedcontainers
BuildRequires: %{python_module pymacaroons >= 0.13.0}
%requires_ge %{python_flavor}-pymacaroons
BuildRequires: %{python_module msgpack >= 0.5.2}
%requires_ge %{python_flavor}-msgpack
BuildRequires: %{python_module phonenumbers >= 8.13.35}
%requires_ge %{python_flavor}-phonenumbers
BuildRequires: %{python_module prometheus-client >= 0.4.0}
%requires_ge %{python_flavor}-prometheus-client
BuildRequires: %{python_module attrs >= 19.2.0}
%requires_ge %{python_flavor}-attrs
BuildRequires: %{python_module netaddr >= 0.7.18}
%requires_ge %{python_flavor}-netaddr
BuildRequires: %{python_module Jinja2 >= 3.0}
%requires_ge %{python_flavor}-Jinja2
BuildRequires: %{python_module bleach >= 1.4.3}
%requires_ge %{python_flavor}-bleach
BuildRequires: %{python_module typing-extensions >= 3.10.0.1}
%requires_ge %{python_flavor}-typing-extensions
BuildRequires: %{python_module cryptography >= 42.0.7}
%requires_ge %{python_flavor}-cryptography
BuildRequires: %{python_module ijson >= 3.1.4}
%requires_ge %{python_flavor}-ijson
BuildRequires: %{python_module matrix-python-common >= 1.3.0}
%requires_ge %{python_flavor}-matrix-python-common
BuildRequires: %{python_module packaging >= 16.1}
%requires_ge %{python_flavor}-packaging
#BuildRequires: %%{python_module importlib_metadata = { version = ">=1.4", python = "<3.8" }
#%%requires_ge %%{python_flavor}-importlib_metadata
BuildRequires: %{python_module pydantic >= 1.7.4}
%requires_ge %{python_flavor}-pydantic
# /SECTION
# /SECTION OPTIONAL
BuildRequires: %{python_module matrix-synapse-ldap3 >= 0.1}
%requires_ge %{python_flavor}-matrix-synapse-ldap3
BuildRequires: %{python_module psycopg2 >= 2.8}
%requires_ge %{python_flavor}-psycopg2
BuildRequires: %{python_module psycopg2cffi >= 2.8}
%requires_ge %{python_flavor}-psycopg2cffi
#BuildRequires: %%{python_module psycopg2cffi-compat >= 1.1}
#%%requires_ge %%{python_flavor}-psycopg2cffi-compat
BuildRequires: %{python_module pysaml2 >= 4.5.0}
%requires_ge %{python_flavor}-pysaml2
BuildRequires: %{python_module Authlib >= 0.15.1}
%requires_ge %{python_flavor}-Authlib
BuildRequires: %{python_module systemd >= 231}
%requires_ge %{python_flavor}-systemd
BuildRequires: %{python_module lxml >= 5.1.0}
%requires_ge %{python_flavor}-lxml
BuildRequires: %{python_module sentry-sdk >= 1.40.4}
%requires_ge %{python_flavor}-sentry-sdk
BuildRequires: %{python_module opentracing >= 2.2.0}
%requires_ge %{python_flavor}-opentracing
#BuildRequires: %%{python_module jaeger-client >= 4.0.0}
#%%requires_ge %%{python_flavor}-jaeger-client
BuildRequires: %{python_module txredisapi >= 1.4.7}
%requires_ge %{python_flavor}-txredisapi
BuildRequires: %{python_module hiredis}
%requires_ge %{python_flavor}-hiredis
BuildRequires: %{python_module Pympler}
%requires_ge %{python_flavor}-Pympler
BuildRequires: %{python_module parameterized >= 0.7.4}
%requires_ge %{python_flavor}-parameterized
BuildRequires: %{python_module idna >= 3.7}
%requires_ge %{python_flavor}-idna
BuildRequires: %{python_module PyICU >= 2.10.2}
%requires_ge %{python_flavor}-PyICU
# /SECTION
# /SECTION TEST
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module pluggy}
BuildRequires: %{python_module anyio}
# /SECTION
Requires: libjemalloc2
Requires: logrotate
Requires: apache2
Requires(post): %fillup_prereq
Recommends: sqlite3 > 3.11
Recommends: config(postgresql-server) >= 11.0
Provides: matrix-synapse = %{version}
%sysusers_requires
%{?systemd_requires}
%description
Synapse is a Python-based reference "homeserver" implementation of
Matrix. Matrix is a system for federated Instant Messaging and VoIP.
%prep
#%%autosetup -p1 -n matrix-synapse-%%{version}
%setup -qa1
mkdir .cargo
install -D -m 0644 %{SOURCE2} .cargo/config
install -D -m 0644 %{SOURCE90} .
# Fix: found a virtual manifest at `/home/abuild/rpmbuild/BUILD/matrix-synapse-%%{version}/Cargo.toml` instead of a package manifest
#rm %%{_builddir}/matrix-synapse-%%{version}/Cargo.toml
%build
%sysusers_generate_pre %{SOURCE10} %{name} %{name}-user.conf
#RUSTFLAGS=%%{rustflags} cargo build --release --workspace
%pyproject_wheel
%install
# User and Groups
mkdir -p %{buildroot}%{_sysusersdir}
install -m 0644 %{SOURCE10} %{buildroot}%{_sysusersdir}/%{name}.conf
#RUSTFLAGS=%%{rustflags} cargo install --root=%%{buildroot}%%{_prefix} --path .
%pyproject_install
# tmpfiles.d /var/run
install -d -m 0755 %{buildroot}%{_tmpfilesdir}
install -D -m 0644 %{SOURCE11} %{buildroot}%{_tmpfilesdir}/%{name}.conf
# etc and sysconfig and default
install -D -m 0644 contrib/systemd/log_config.yaml %{buildroot}%{_sysconfdir}/%{name}/log_config.yaml
install -D -m 0644 contrib/example_log_config.yaml %{buildroot}%{_sysconfdir}/%{name}/log_config_without_systemd.yaml
# sysconfig and default
install -D -m 0644 %{SOURCE12} %{buildroot}%{_fillupdir}/sysconfig.matrix-synapse
install -D -m 0644 %{SOURCE13} %{buildroot}%{_sysconfdir}/default/%{name}
# systemd
install -D -m 0644 %{SOURCE14} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 %{SOURCE14} %{buildroot}%{_sysconfdir}/systemd/system/%{name}.service # To enable after=postgresql if postgresql wanted
install -d -m 0755 %{buildroot}%{_sbindir}/
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
# wrapper
install -D -m 0755 %{SOURCE15} %{buildroot}%{_bindir}/matrix-synapse
# logrotate
install -D -m 0644 %{SOURCE16} %{buildroot}%{_sysconfdir}/logrotate.d/python-%{name}
# apache
install -d -m 0755 %{buildroot}%{_sysconfdir}/apache2/conf.d/
install -D -m 0644 %{SOURCE17} %{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}.conf
install -d -m 0755 %{buildroot}%{_sysconfdir}/apache2/vhosts.d/
install -D -m 0644 %{SOURCE18} %{buildroot}%{_sysconfdir}/apache2/vhosts.d/%{name}.conf
install -d -m 0755 %{buildroot}/srv/www/vhosts/matrix/.well-known/matrix
install -D -m 0644 %{SOURCE19} %{buildroot}/srv/www/vhosts/matrix/.well-known/matrix/server
# firewall
%if 0%{?suse_version} >= 1500
install -d %{buildroot}%{_libexecdir}/firewalld/services/
install -D -m0644 %{SOURCE20} %{buildroot}%{_libexecdir}/firewalld/services/matrix-synapse.xml
%else
install -d %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/
install -D -m0644 %{SOURCE21} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
# matrix-synapse-init.sh and matrix-synapse-generate-config.sh
install -D -m 0755 %{SOURCE30} %{buildroot}%{_sbindir}/matrix-synapse-init.sh
install -D -m 0755 %{SOURCE31} %{buildroot}%{_sbindir}/matrix-synapse-generate-new-config.sh
# fix flavor after clone
sed -i 's|@PYTHON_FLAVOR@|python%{python_bin_suffix}|g' %{buildroot}%{_bindir}/matrix-synapse
sed -i 's|/usr/bin/env python3|\/usr\/bin\/python%{python_bin_suffix}|g' %{buildroot}%{python_sitearch}/synapse/_scripts/*.py
sed -i 's|/usr/bin/env python|\/usr\/bin\/python%{python_bin_suffix}|g' %{buildroot}%{python_sitearch}/synapse/_scripts/*.py
# UserDir, LogDir, RunDir
install -d -m 0750 %{buildroot}%{_localstatedir}/lib/%{name}
install -d -m 0750 %{buildroot}%{_localstatedir}/log/%{name}
install -d -m 0770 %{buildroot}%{_rundir}/%{pkgname}
# fdupes
%fdupes %{buildroot}%{python_sitearch}
%check
#CHOOSE: %%pytest OR %%pyunittest -v OR CUSTOM
# Custom: %%python_expand PYTHONPATH=. trial-%%{$python_bin_suffix} tests
# %%pytest_arch
%pre -f %{name}.pre
%service_add_pre matrix-synapse.service
%post
%service_add_post matrix-synapse.service
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf
%{fillup_only -n matrix-synapse}
%if 0%{?suse_version} >= 1500
%firewalld_reload
%endif
# after update
if [ "$1" -eq 2 ] ; then
%restart_on_update matrix-synapse.service
fi
%preun
%service_del_preun matrix-synapse.service
%postun
%service_del_postun matrix-synapse.service
%files
%doc AUTHORS.rst CHANGES.md README.rst changelog.d/.gitignore
%doc README.SUSE
%license LICENSE
#
%config(noreplace) /srv/www/vhosts/matrix/.well-known/matrix/server
%config(noreplace) %{_sysconfdir}/default/%{name}
%config(noreplace) %{_sysconfdir}/matrix-synapse/log_config.yaml
%config(noreplace) %{_sysconfdir}/matrix-synapse/log_config_without_systemd.yaml
%config(noreplace) %{_sysconfdir}/logrotate.d/python-%{name}
%config(noreplace) %{_sysconfdir}/apache2/conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/apache2/vhosts.d/%{name}.conf
#
%{_fillupdir}/sysconfig.matrix-synapse
%{_sysusersdir}/%{name}.conf
%{_tmpfilesdir}/%{name}.conf
# systemd
%dir %{_sysconfdir}/systemd
%dir %{_sysconfdir}/systemd/system
%config(noreplace) %{_sysconfdir}/systemd/system/%{name}.service
%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}
# firewall
%if 0%{?suse_version} >= 1500
%dir %{_libexecdir}/firewalld
%dir %{_libexecdir}/firewalld/services
%{_libexecdir}/firewalld/services/matrix-synapse.xml
%else
%config(noreplace) %{_sysconfdir}/sysconfig/SuSEFirewall2.d/services/%{name}
%endif
# Some Dirs
%dir %{_sysconfdir}/apache2
%dir %{_sysconfdir}/apache2/conf.d
%dir %{_sysconfdir}/apache2/vhosts.d
%dir /srv/www/vhosts
%dir /srv/www/vhosts/matrix
%dir /srv/www/vhosts/matrix/.well-known
%dir /srv/www/vhosts/matrix/.well-known/matrix
# etcDir, UserDir, LogDir, RunDir
%dir %attr(0750,synapse,synapse) %{_sysconfdir}/matrix-synapse
%dir %attr(0750,synapse,synapse) %{_localstatedir}/lib/matrix-synapse
%dir %attr(0750,synapse,synapse) %{_localstatedir}/log/matrix-synapse
%ghost %dir %attr(770,synapse,synapse) /run/matrix-synapse
# other bin
%{_sbindir}/matrix-synapse-init.sh
%{_sbindir}/matrix-synapse-generate-new-config.sh
# binaries
%{_bindir}/generate_config
%{_bindir}/generate_signing_key
%{_bindir}/hash_password
%{_bindir}/register_new_matrix_user
%{_bindir}/synapse_port_db
%{_bindir}/synctl
%{_bindir}/matrix-synapse
%{_bindir}/export_signing_key
%{_bindir}/generate_log_config
%{_bindir}/synapse_homeserver
%{_bindir}/synapse_worker
%{_bindir}/synapse_review_recent_signups
%{_bindir}/update_synapse_database
# python
%{python_sitearch}/synapse
%{python_sitearch}/matrix_synapse-%{version}.dist-info
%changelog