File matrix-synapse.spec of Package matrix-synapse

%global unmangled_version 1.35.1

Summary: Reference Synapse Home Server
Name: matrix-synapse
Version: %{unmangled_version}%{?unmangled_release:.%{unmangled_release}}
Release: 1%{?dist}
Source0: https://github.com/matrix-org/synapse/archive/v%{unmangled_version}%{?unmangled_release?-r%{unmangled_release}}/synapse-%{unmangled_version}%{?unmangled_release:-r%{unmangled_release}}.tar.gz
Source1: synapse-tmpfile.conf
Source2: synapse.sysconfig
Source3: synapse.service
Patch0: matrix-synapse-proper-paths.patch
Patch2: matrix-synapse-test-paths.patch
Patch3: matrix-synapse-cryptography-version.patch
License: ASL 2.0
Group: Development/Libraries
Prefix: %{_prefix}
BuildArch: noarch
BuildRequires: systemd-units

BuildRequires: python3-devel
BuildRequires: python3-twisted >= 18.9.0
BuildRequires: python3-mock >= 2.0
BuildRequires: python3-parameterized >= 0.7.0
BuildRequires: python3-unpaddedbase64 >= 1.1.0
BuildRequires: python3-canonicaljson >= 1.4.0
BuildRequires: python3-signedjson >= 1.1.0
BuildRequires: python3-service-identity >= 1.0.0
BuildRequires: python3-pyOpenSSL >= 16.0.0
BuildRequires: python3-yaml >= 3.11
BuildRequires: python3-pyasn1 >= 0.1.9
BuildRequires: python3-pyasn1-modules >= 0.0.7
BuildRequires: python3-pynacl >= 1.2.1
BuildRequires: python3-idna >= 2.5
BuildRequires: python3-bcrypt >= 3.1.0
BuildRequires: python3-frozendict >= 1
BuildRequires: python3-pillow >= 4.3.0
BuildRequires: python3-sortedcontainers >= 1.4.4
BuildRequires: python3-pysaml2 >= 4.5.0
BuildRequires: python3-pymacaroons >= 0.13.0
BuildRequires: python3-bleach >= 1.4.3
BuildRequires: python3-netaddr >= 0.7.18
BuildRequires: python3-jinja2 >= 2.9
BuildRequires: python3-matrix-synapse-ldap3 >= 0.1
BuildRequires: python3-lxml >= 3.5.0
BuildRequires: python3-msgpack >= 0.5.2
BuildRequires: python3-jsonschema >= 2.5.1
BuildRequires: python3-phonenumbers >= 8.2.0
BuildRequires: python3-prometheus_client >= 0.4.0
BuildRequires: python3-attrs >= 19.1.0
BuildRequires: python3-treq >= 15.1
BuildRequires: python3-sentry-sdk >= 0.7.2
BuildRequires: python3-jwt >= 1.6.4
BuildRequires: python3-typing-extensions >= 3.7.4
BuildRequires: python3-authlib >= 0.14.0
BuildRequires: python3-txredisapi >= 1.4.7
BuildRequires: python3-hiredis
BuildRequires: python3-ijson >= 3.0
BuildRequires: xmlsec1

%systemd_requires

Requires: python3-matrix-synapse = %{version}

%description
Matrix is an ambitious new ecosystem for open federated Instant Messaging and
VoIP.  The basics you need to know to get up and running are:

- Everything in Matrix happens in a room.  Rooms are distributed and do not
  exist on any single server.  Rooms can be located using convenience aliases 
  like ``#matrix:matrix.org`` or ``#test:localhost:8448``.

- Matrix user IDs look like ``@matthew:matrix.org`` (although in the future
  you will normally refer to yourself and others using a 3PID: email
  address, phone number, etc rather than manipulating Matrix user IDs)

The overall architecture is::

      client <----> homeserver <=====================> homeserver <----> client
             https://somewhere.org/_matrix      https://elsewhere.net/_matrix

``#matrix:matrix.org`` is the official support room for Matrix, and can be
accessed by the web client at http://matrix.org/beta or via an IRC bridge at
irc://irc.freenode.net/matrix.

Synapse is currently in rapid development, but as of version 0.5 we believe it 
is sufficiently stable to be run as an internet-facing service for real usage!

%package -n python3-matrix-synapse
Summary: Python 3 Libraries For Reference Synapse Home Server
%{?python_provide:%python_provide python3-matrix-synapse}
Requires: %{name}
Requires: python3-unpaddedbase64 >= 1.1.0
Requires: python3-canonicaljson >= 1.4.0
Requires: python3-signedjson >= 1.1.0
Requires: python3-twisted >= 18.9.0
Requires: python3-service-identity >= 1.0.0
Requires: python3-pyOpenSSL >= 16.0.0
Requires: python3-yaml >= 3.11
Requires: python3-pyasn1 >= 0.1.9
Requires: python3-pyasn1-modules >= 0.0.7
Requires: python3-pynacl >= 1.2.1
Requires: python3-idna >= 2.5
Requires: python3-bcrypt >= 3.1.0
Requires: python3-frozendict >= 1
Requires: python3-pillow >= 4.3.0
Requires: python3-sortedcontainers >= 1.4.4
Requires: python3-pysaml2 >= 4.5.0
Requires: python3-pymacaroons >= 0.13.0
Requires: python3-bleach >= 1.4.3
Requires: python3-netaddr >= 0.7.18
Requires: python3-jinja2 >= 2.9
Requires: python3-matrix-synapse-ldap3 >= 0.1
Requires: python3-lxml >= 3.5.0
Requires: python3-msgpack >= 0.5.2
Requires: python3-jsonschema >= 2.5.1
Requires: python3-phonenumbers >= 8.2.0
Requires: python3-prometheus_client >= 0.4.0
Requires: python3-attrs >= 19.1.0
Requires: python3-treq >= 15.1
Requires: python3-sentry-sdk >= 0.7.2
Requires: python3-jwt >= 1.6.4
Requires: python3-typing-extensions >= 3.7.4
Requires: python3-authlib >= 0.14.0
Requires: python3-txredisapi >= 1.4.7
Requires: python3-hiredis
Requires: python3-ijson >= 3.0
Requires: python3-systemd >= 231
Requires: xmlsec1

%description -n python3-matrix-synapse
Matrix is an ambitious new ecosystem for open federated Instant Messaging and
VoIP.
This package provides Python 3 libraries implementing Synapse homeserver.

%prep
%setup -n synapse-%{unmangled_version}%{?unmangled_release?:-r%{unmangled_release}}
%patch0 -p1
%patch2 -p1
%patch3 -p1

%build
%py3_build

%install
%{__python3} setup.py install \
  --install-scripts='%{_libexecdir}/%{name}' \
  --skip-build \
  --single-version-externally-managed \
  -O2 \
  --root='%{buildroot}'
%{__cat} > %{buildroot}%{_libexecdir}/%{name}/synapse <<EOF
#!/bin/sh
exec %{__python3} -m synapse.app.homeserver --config-path=%{_sysconfdir}/synapse/homeserver.yaml
EOF
%{__chmod} a+x %{buildroot}%{_libexecdir}/%{name}/synapse
%{__rm} -rf %{buildroot}%{python3_sitelib}/synmark

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_sbindir}"
%{__ln_s} "%{_libexecdir}/%{name}/synctl" \
          "%{_libexecdir}/%{name}/register_new_matrix_user" \
          "%{_libexecdir}/%{name}/synapse" \
          "${RPM_BUILD_ROOT}%{_sbindir}"

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_sysconfdir}/synapse"
%{__install} -m 0644 contrib/systemd/log_config.yaml \
             "${RPM_BUILD_ROOT}%{_sysconfdir}/synapse"

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_unitdir}"
%{__install} -m 0644 %{SOURCE3} "${RPM_BUILD_ROOT}%{_unitdir}"

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_prefix}/lib/tmpfiles.d"
%{__install} -m0644 %{SOURCE1} \
             "${RPM_BUILD_ROOT}%{_prefix}/lib/tmpfiles.d/synapse.conf"

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig"
%{__install} -m0644 %{SOURCE2} \
             "${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/synapse"

%{__mkdir_p} "${RPM_BUILD_ROOT}%{_localstatedir}/run/synapse"
%{__mkdir_p} "${RPM_BUILD_ROOT}%{_localstatedir}/lib/synapse"
%{__mkdir_p} "${RPM_BUILD_ROOT}%{_localstatedir}/log/synapse"

%check
PYTHONPATH=. %{_bindir}/trial-3 tests

%pre
getent group synapse &>/dev/null || groupadd -r synapse
getent passwd synapse &>/dev/null || \
    /usr/sbin/useradd -r -g synapse -s /sbin/nologin -c 'Matrix Synapse' \
        -d %{_localstatedir}/lib/synapse synapse

%post
%systemd_post synapse.service

%preun
%systemd_preun synapse.service

%postun
%systemd_postun_with_restart synapse.service

%files
%defattr(-,root,root)
%doc *.rst
%license LICENSE
%attr(0710,root,synapse) %dir %{_sysconfdir}/synapse
%config %{_sysconfdir}/synapse/*
%config %{_sysconfdir}/sysconfig/synapse
%{_sbindir}/*
%{_libexecdir}/matrix-synapse
%{_unitdir}/synapse.service
%{_prefix}/lib/tmpfiles.d/synapse.conf
%attr(0710,synapse,synapse) %{_localstatedir}/run/synapse
%attr(0710,synapse,synapse) %{_localstatedir}/lib/synapse
%attr(0750,synapse,synapse) %{_localstatedir}/log/synapse

%files -n python3-matrix-synapse
%defattr(-,root,root)
%doc *.rst
%license LICENSE
%{python3_sitelib}/synapse
%{python3_sitelib}/matrix_synapse-%{version}*.egg-info