File postfix-mta-sts-resolver.spec of Package postfix-mta-sts-resolver
#
# spec file for package postfix-mta-sts-resolver
#
# Copyright (c) 2018-2025 Matthias Fehring <buschmann23@opensuse.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/
#
%bcond_without redis
%bcond_without sqlite
%bcond_without postgres
%bcond_without uvloop
%bcond_with tests
%{?sle15_python_module_pythons}
%define _grpname mta-sts
%define _usrname mta-sts
%define _confdir %{_sysconfdir}
%define _conffile mta-sts-daemon.yml
# only build for Python 3.11 on Leap 15.6
%define pythons python3
%define pyreqprefix python3
%if 0%{?suse_version} < 1600
%define pythons python311
%define pyreqprefix python311
%endif
Name: postfix-mta-sts-resolver
Version: 1.5.0
Release: 0
Summary: Postfix MTA-STS Resolver
License: MIT
Group: Productivity/Networking/Email/Utilities
Url: https://github.com/Snawoot/postfix-mta-sts-resolver
Source0: https://github.com/Snawoot/postfix-mta-sts-resolver/releases/download/v%{version}/%{name}-%{version}.tar.gz
Source1: https://github.com/Snawoot/postfix-mta-sts-resolver/releases/download/v%{version}/%{name}-%{version}.tar.gz.asc
# GPG Public Key from Vladislav Yarmak linked at https://github.com/Snawoot/postfix-mta-sts-resolver/blob/master/SECURITY.md
# and downloaded from https://keybase.io/yarmak/pgp_keys.asc
Source2: %{name}.keyring
BuildRequires: python-rpm-macros
BuildRequires: system-user-mta-sts
BuildRequires: %{python_module wheel}
BuildRequires: %{python_module setuptools >= 38.6.0}
# for creating man pages
BuildRequires: rubygem(asciidoctor)
%if 0%{with tests}
BuildRequires: %{python_module aiodns >= 1.1.1}
BuildRequires: %{python_module pycares >= 2.3.0}
BuildRequires: %{python_module aiohttp >= 3.4.4}
BuildRequires: %{python_module PyYAML >= 3.12}
%if 0%{with sqlite}
BuildRequires: %{python_module aiosqlite >= 0.10.0}
%endif
%if 0%{with redis}
BuildRequires: %{python_module redis >= 4.2.0}
%endif
%if 0%{with postgres}
BuildRequires: %{python_module asyncpg >= 0.27}
%endif
%if 0%{with uvloop}
BuildRequires: %{python_module uvloop >= 0.11.0}
%endif
BuildRequires: %{python_module pytest >= 3.0.0}
BuildRequires: %{python_module pytest-asyncio}
BuildRequires: %{python_module pytest-timeout}
BuildRequires: %{python_module async_generator}
BuildRequires: %{python_module twine >= 1.11.0}
BuildRequires: %{python_module cryptography >= 1.6}
%endif
Requires(pre): user(mta-sts)
Requires: %{pyreqprefix}-aiodns >= 1.1.1
Requires: %{pyreqprefix}-pycares >= 2.3.0
Requires: %{pyreqprefix}-aiohttp >= 3.4.4
Requires: %{pyreqprefix}-PyYAML >= 3.12
%if 0%{with uvloop}
Recommends: %{pyreqprefix}-uvloop >= 0.11.0
%endif
%if 0%{with sqlite}
Suggests: %{pyreqprefix}-aiosqlite >= 0.10.0
%endif
%if 0%{with redis}
Suggests: %{pyreqprefix}-redis >= 4.2.0
%endif
%if 0%{with postgres}
Suggests: %{pyreqprefix}-asyncpg >= 0.27
%endif
%{?systemd_requires}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%description
Daemon which provides TLS client policy for Postfix via socketmap,
according to domain MTA-STS policy.
%prep
%setup -q
# set correct path in example file for convenience
sed -e 's|^path.*|path: "/run/postfix-mta-sts-resolver/mta-sts.sock"|' \
-i config_examples/mta-sts-daemon.yml.sqlite_unixsock
# remove shebangs
sed -i -e '/#!\/usr\/bin\/env python3/d' \
postfix_mta_sts_resolver/__main__.py postfix_mta_sts_resolver/daemon.py
%build
%python_build
# create man pages
asciidoctor man/mta-sts-daemon.1.adoc -b manpage -d manpage
asciidoctor man/mta-sts-daemon.yml.5.adoc -b manpage -d manpage
asciidoctor man/mta-sts-query.1.adoc -b manpage -d manpage
%install
%python_install
# install config file
%{__install} -d %{buildroot}%{_confdir}
%{__install} -m 0644 config_examples/mta-sts-daemon.yml.internal %{buildroot}%{_confdir}/%{_conffile}
# install man pages
%{__install} -d %{buildroot}%{_mandir}/man1/
%{__install} -d %{buildroot}%{_mandir}/man5/
%{__install} -m 0644 man/mta-sts-daemon.1 %{buildroot}%{_mandir}/man1/
%{__install} -m 0644 man/mta-sts-query.1 %{buildroot}%{_mandir}/man1/
%{__install} -m 0644 man/mta-sts-daemon.yml.5 %{buildroot}%{_mandir}/man5/
# create rclink
%{__install} -d %{buildroot}%{_sbindir}
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
# create sysconfig file
%{__install} -d %{buildroot}%{_fillupdir}
%{__cat} > %{buildroot}%{_fillupdir}/sysconfig.%{name} << 'EOF'
# Set the necessary startup options
OPTIONS="-c %{_confdir}/%{_conffile} -v info"
EOF
# create systemd service file
%{__install} -d -m 0755 %{buildroot}%{_unitdir}
%{__cat} > %{buildroot}%{_unitdir}/%{name}.service << 'EOF'
[Unit]
Description=Daemon providing MTA-STS policy for Postfix
Documentation=https://github.com/Snawoot/%{name}
Requires=var-run.mount
After=var-run.mount network.target nss-lookup.target syslog.target redis.target
Before=postfix.service
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/%{name}
ExecStart=/usr/bin/mta-sts-daemon $OPTIONS
Restart=always
KillMode=process
TimeoutStartSec=10
TimeoutStopSec=30
User=%{_usrname}
Group=%{_grpname}
RuntimeDirectory=%{name}
[Install]
WantedBy=multi-user.target
EOF
# NOTE: tests are currently not running properly because of
# missing dependencies
%if 0%{with tests}
%check
%if 0%{with uvloop}
export TOXENV="py%{python_version_nodots}-uvloop"
%else
export TOXENV="py%{python_version_nodots}"
%endif
%pytest
%endif
%pre
%service_add_pre %{name}.service
%preun
%service_del_preun %{name}.service
%post
%service_add_post %{name}.service
%{fillup_only postfix-mta-sts-resolver}
%postun
%service_del_postun %{name}.service
%files
%defattr(-,root,root,-)
%license LICENSE
%doc README.md config_examples
%{_bindir}/mta-sts-daemon
%{_bindir}/mta-sts-query
%{_sbindir}/rc%{name}
%config(noreplace) %{_confdir}/%{_conffile}
%{python_sitelib}/postfix_mta_sts_resolver-%{version}-py*egg-info
%{python_sitelib}/postfix_mta_sts_resolver
%dir %{_fillupdir}
%{_fillupdir}/sysconfig.%{name}
%attr(0644,root,root) %{_unitdir}/%{name}.service
%{_mandir}/man1/mta-sts-daemon.1%{ext_man}
%{_mandir}/man1/mta-sts-query.1%{ext_man}
%{_mandir}/man5/mta-sts-daemon.yml.5%{ext_man}
%changelog