Blob Blame History Raw
%global pypi_name mailman

# The user and group Mailman will run as, same values as in the mailman 2 RPM
%global mmuser       mailman
%global mmuserid     41
%global mmgroup      mailman
%global mmgroupid    41

%{?python_enable_dependency_generator}

%if 0%{?epel} && 0%{?epel} < 8
# We need to force Python 3.6 in EPEL
%global python3_pkgversion 36
%global __python3 /usr/bin/python3.6
%else
%{!?python3_pkgversion: %global python3_pkgversion 3}
%endif



Name:           mailman3
Version:        3.2.0
Release:        1%{?dist}
Summary:        The GNU mailing list manager

License:        GPLv3
URL:            http://www.list.org
Source0:        https://pypi.python.org/packages/source/m/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
Source1:        mailman3.cfg
Source2:        mailman3-tmpfiles.conf
Source3:        mailman3.service
Source4:        mailman3.logrotate
Source5:        mailman3-digests.service
Source6:        mailman3-digests.timer

# <https://gitlab.com/mailman/mailman/merge_requests/64>
Patch10:        %{name}-administrivia-headers.patch
# <https://gitlab.com/mailman/mailman/merge_requests/70>
Patch11:        %{name}-subject-prefix.patch
# Compatibility with click>=7.0
# https://gitlab.com/mailman/mailman/merge_requests/417
Patch12:        %{name}-click7.patch
# Compatibility with Python 3.7
# https://gitlab.com/mailman/mailman/commit/2dd2dc7ed2dfabbac029d3ec830004ff25c32340
Patch13:        %{name}-py37.patch


BuildArch:      noarch

BuildRequires:  python%{python3_pkgversion}-devel >= 3.5
BuildRequires:  python%{python3_pkgversion}-setuptools

%if %{undefined python_enable_dependency_generator}
Requires:       python%{python3_pkgversion} >= 3.5
Requires:       python%{python3_pkgversion}-setuptools
Requires:       python%{python3_pkgversion}-aiosmtpd
Requires:       python%{python3_pkgversion}-alembic
Requires:       python%{python3_pkgversion}-atpublic
Requires:       python%{python3_pkgversion}-click
Requires:       python%{python3_pkgversion}-dns >= 1.14.0
Requires:       python%{python3_pkgversion}-falcon >= 1.0.0
Requires:       python%{python3_pkgversion}-flufl-bounce
Requires:       python%{python3_pkgversion}-flufl-i18n >= 2.0.1
Requires:       python%{python3_pkgversion}-flufl-lock >= 3.1
Requires:       python%{python3_pkgversion}-lazr-config
# Versionned dep on python-passlib, or else it fails with AttributeError in
# mailman/utilities/passwords.py", line 43: 'CryptContext' has no attribute 'from_string'
Requires:       python%{python3_pkgversion}-passlib >= 1.6.0
Requires:       python%{python3_pkgversion}-requests
# Uses the Query.one_or_none() method introduced in SQLAlchemy 1.0.9
Requires:       python%{python3_pkgversion}-sqlalchemy >= 1.0.9
Requires:       python%{python3_pkgversion}-zope-component
Requires:       python%{python3_pkgversion}-zope-configuration
Requires:       python%{python3_pkgversion}-zope-event
Requires:       python%{python3_pkgversion}-zope-interface
%endif

# To run the test suite:
BuildRequires:  python%{python3_pkgversion}-aiosmtpd
BuildRequires:  python%{python3_pkgversion}-alembic
BuildRequires:  python%{python3_pkgversion}-atpublic
BuildRequires:  python%{python3_pkgversion}-click
BuildRequires:  python%{python3_pkgversion}-dns >= 1.14.0
BuildRequires:  python%{python3_pkgversion}-falcon >= 1.0.0
BuildRequires:  python%{python3_pkgversion}-flufl-bounce
BuildRequires:  python%{python3_pkgversion}-flufl-i18n
BuildRequires:  python%{python3_pkgversion}-flufl-lock
BuildRequires:  python%{python3_pkgversion}-flufl-testing
BuildRequires:  python%{python3_pkgversion}-lazr-config
BuildRequires:  python%{python3_pkgversion}-lazr-smtptest
BuildRequires:  python%{python3_pkgversion}-mock
BuildRequires:  python%{python3_pkgversion}-nose2
BuildRequires:  python%{python3_pkgversion}-passlib >= 1.6.0
BuildRequires:  python%{python3_pkgversion}-psycopg2
BuildRequires:  python%{python3_pkgversion}-requests
# Uses the Query.one_or_none() method introduced in SQLAlchemy 1.0.9
BuildRequires:  python%{python3_pkgversion}-sqlalchemy >= 1.0.9
BuildRequires:  python%{python3_pkgversion}-zope-component
BuildRequires:  python%{python3_pkgversion}-zope-configuration
BuildRequires:  python%{python3_pkgversion}-zope-event
BuildRequires:  python%{python3_pkgversion}-zope-interface

# SELinux https://fedoraproject.org/wiki/SELinux/IndependentPolicy#Creating_the_Spec_File
Provides:  %{name}-selinux == %{version}-%{release}
%global selinux_variants mls targeted
Requires: selinux-policy >= %{_selinux_policy_version}
BuildRequires: git
BuildRequires: pkgconfig(systemd)
BuildRequires: selinux-policy
BuildRequires: selinux-policy-devel
Requires(post): selinux-policy-base >= %{_selinux_policy_version}
Requires(post): libselinux-utils
Requires(post): policycoreutils
%if 0%{?fedora}
Requires(post): policycoreutils-python-utils
%else
Requires(post): policycoreutils-python
%endif
# SELinux https://fedoraproject.org/wiki/SELinux_Policy_Modules_Packaging_Draft
BuildRequires:  checkpolicy, selinux-policy-devel
BuildRequires:  hardlink

# Scriptlets
%{?systemd_requires}
BuildRequires:    systemd
Requires(pre):    shadow-utils


%description
This is GNU Mailman, a mailing list management system distributed under the
terms of the GNU General Public License (GPL) version 3 or later.  The name of
this software is spelled 'Mailman' with a leading capital 'M' but with a lower
case second `m'.  Any other spelling is incorrect.


%prep
%setup -q -n %{pypi_name}-%{version}
%patch10 -p1
%patch11 -p1
%if 0%{?fedora} && 0%{?fedora} > 28
%patch12 -p1
%patch13 -p1
%endif

# SELinux
mkdir SELinux
echo '%{_localstatedir}/lib/%{name}/data(/.*)? gen_context(system_u:object_r:etc_mail_t,s0)' \
    > SELinux/%{name}.fc
# remember to bump the following version if the policy is updated
cat > SELinux/%{name}.te << EOF
policy_module(%{name}, 1.4)
EOF


%build
%py3_build

cd SELinux
for selinuxvariant in %{selinux_variants}; do
  make NAME=${selinuxvariant} -f /usr/share/selinux/devel/Makefile
  mv %{name}.pp %{name}.pp.${selinuxvariant}
  make NAME=${selinuxvariant} -f /usr/share/selinux/devel/Makefile clean
done
cd -


%install
%py3_install

# move scripts away from _bindir to avoid conflicts and create a wrapper script
mkdir -p %{buildroot}%{_libexecdir}/%{name}
mv %{buildroot}%{_bindir}/* %{buildroot}%{_libexecdir}/%{name}/
cat > %{buildroot}%{_bindir}/%{name} << EOF
#!/bin/sh
if [ "\$(whoami)" != "mailman" ]; then
    echo "This command must be run under the mailman user."
    exit 1
fi
%{_libexecdir}/%{name}/mailman \$@
EOF
chmod +x %{buildroot}%{_bindir}/%{name}

# service files
install -D -m 0640 %{SOURCE1} %{buildroot}%{_sysconfdir}/mailman.cfg
install -D -m 0644 %{SOURCE2} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
install -D -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d/
sed -e 's,@LOGDIR@,%{_localstatedir}/log/%{name},g;s,@BINDIR@,%{_bindir},g' \
    %{SOURCE4} > %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
# periodic task
install -D -m 0644 %{SOURCE5} %{buildroot}%{_unitdir}/%{name}-digests.service
install -D -m 0644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}-digests.timer

mkdir -p %{buildroot}%{_localstatedir}/{lib,spool,log}/%{name}
mkdir -p %{buildroot}/run/%{name} %{buildroot}/run/lock/%{name}
mkdir -p %{buildroot}%{_sysconfdir}/%{name}.d
# Mailman will auto-create the following dir, but not with the correct group
# owner (MTAs such as Postfix must read and write to it). Set it here in RPM's
# file listing.
mkdir -p %{buildroot}%{_localstatedir}/lib/%{name}/data

# SELinux
for selinuxvariant in %{selinux_variants}; do
  install -d %{buildroot}%{_datadir}/selinux/${selinuxvariant}
  install -p -m 644 SELinux/%{name}.pp.${selinuxvariant} \
    %{buildroot}%{_datadir}/selinux/${selinuxvariant}/%{name}.pp
done
/usr/sbin/hardlink -cv %{buildroot}%{_datadir}/selinux


%check
# Mailman3 can only be tested when its installed (it starts runners and won't
# find the buildroot), so we use a virtualenv.
pyvenv-%{python3_version} --system-site-packages --without-pip --clear venv
venv/bin/python setup.py develop
venv/bin/python -m nose2 -v


%pre
# User & Group
getent group %{mmgroup} >/dev/null || \
    groupadd -g %{mmgroupid} %{mmgroup} >/dev/null
getent passwd %{mmuser} >/dev/null || \
    useradd -r -u %{mmuserid} -g %{mmgroupid} -d %{_localstatedir}/lib/%{name} -s /sbin/nologin \
        -c "Mailman, the mailing-list manager" %{mmuser} >/dev/null
# SELinux
for selinuxvariant in %{selinux_variants}; do
    %selinux_relabel_pre -s ${selinuxvariant}
done

%post
# Service
%systemd_post %{name}.service %{name}-digests.timer
# SELinux
for selinuxvariant in %{selinux_variants}; do
    %selinux_modules_install -s ${selinuxvariant} %{_datadir}/selinux/${selinuxvariant}/%{name}.pp || :
done

%preun
# Service
%systemd_preun %{name}.service %{name}-digests.timer

%postun
# Service
%systemd_postun_with_restart %{name}.service %{name}-digests.timer
# SELinux
if [ $1 -eq 0 ] ; then
  for selinuxvariant in %{selinux_variants}; do
    %selinux_modules_uninstall -s ${selinuxvariant} %{_datadir}/selinux/${selinuxvariant}/%{name}.pp || :
  done
fi

%posttrans
# SELinux
for selinuxvariant in %{selinux_variants}; do
    %selinux_relabel_post -s ${selinuxvariant}
done


%files
%doc README.rst
%license COPYING
%{_bindir}/%{name}
%{_libexecdir}/%{name}
%{python3_sitelib}/%{pypi_name}
%{python3_sitelib}/%{pypi_name}-*-py?.?.egg-info
%{_unitdir}/*.service
%{_unitdir}/*.timer
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%config(noreplace) %attr(640,mailman,mailman) %{_sysconfdir}/mailman.cfg
%dir %{_sysconfdir}/%{name}.d
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%dir %attr(755,mailman,mailman) %{_localstatedir}/lib/%{name}
%dir %attr(2775,mailman,mail)   %{_localstatedir}/lib/%{name}/data
%dir %attr(755,mailman,mailman) %{_localstatedir}/spool/%{name}
%dir %attr(755,mailman,mailman) %{_localstatedir}/log/%{name}
%dir %attr(755,mailman,mailman) /run/%{name}
%dir %attr(755,mailman,mailman) /run/lock/%{name}
# SELinux
%doc SELinux/*
%{_datadir}/selinux/*/%{name}.pp


%changelog
* Fri Aug 03 2018 Aurelien Bompard <abompard@fedoraproject.org> - 3.2.0-1
- Version 3.2.0
- Update dependencies
- Merge the -selinux subpackage
- Use the SELinux macros

* Tue Mar 06 2018 Aurelien Bompard <abompard@fedoraproject.org> - 3.1.1-0.7
- Rebuild

* Tue Feb 13 2018 Aurelien Bompard <abompard@fedoraproject.org> - 3.1.1-0.6
- git update to 8207caa09

* Mon May 29 2017 Aurelien Bompard <abompard@fedoraproject.org> - 3.1.1-0.1
- version 3.1.0 final

* Thu Feb 09 2017 Aurelien Bompard <abompard@fedoraproject.org> - 3.1.0-0.30
- add a cron job to send digests daily

* Wed Apr 29 2015 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-1
- version 3.0.0 final

* Fri Jul 18 2014 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-0.18.bzr7251
- add Patch11 (missing PostgreSQL upgrade file)

* Mon Nov 25 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-0.11.bzr7226
- add SELinux policy module, according to:
  http://fedoraproject.org/wiki/SELinux_Policy_Modules_Packaging_Draft

* Sun Oct 27 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-0.10.bzr7226
- update to BZR snapshot (rev7226)

* Thu Aug 29 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-0.6.bzr7218
- update to BZR snapshot (rev7218)

* Wed Aug 28 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0-0.6.bzr7217
- update to BZR snapshot (rev7217)
- drop patch 0
- rename to mailman3 and make it parallel-installable with Mailman 2

* Wed Jul 24 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3:3.0.0-0.6
- update to BZR snapshot (rev7215)
- drop patch 1

* Thu Mar 07 2013 Aurelien Bompard <abompard@fedoraproject.org> - 3:3.0.0-0.2.b3
- update to beta3
- add a systemd service and a default config file

* Wed Nov 28 2012 Aurelien Bompard <abompard@fedoraproject.org> - 3.0.0b2-1
- Initial package.