From 9eab35adee855a036c52fa5682499464eb227592 Mon Sep 17 00:00:00 2001 From: Richard Shaw Date: Jul 27 2020 17:34:10 +0000 Subject: Add conditionals for EL 7 / Python 2. --- diff --git a/fail2ban.spec b/fail2ban.spec index 7abe5b4..3a5e346 100644 --- a/fail2ban.spec +++ b/fail2ban.spec @@ -35,10 +35,16 @@ Patch8: https://github.com/fail2ban/fail2ban/commit/309c8dddd7adc2de140ed5a72088 BuildArch: noarch +%if 0%{?rhel} && 0%{?rhel} < 8 +BuildRequires: python2-devel +# For testcases +BuildRequires: python-inotify +%else BuildRequires: python3-devel BuildRequires: /usr/bin/2to3 # For testcases BuildRequires: python3-inotify +%endif BuildRequires: sqlite BuildRequires: systemd BuildRequires: selinux-policy-devel @@ -79,14 +85,20 @@ SELinux policies for Fail2Ban. %package server Summary: Core server component for Fail2Ban +%if 0%{?rhel} && 0%{?rhel} < 8 +Requires: python2-systemd +%else Requires: python3-systemd +%endif Requires(post): systemd Requires(preun): systemd Requires(postun): systemd Requires: ipset Requires: iptables +%if 0%{?fedora} Requires: (%{name}-selinux if selinux-policy-%{selinuxtype}) +%endif %description server This package contains the core server components for Fail2Ban with minimal @@ -104,10 +116,14 @@ Requires: %{name}-server = %{version}-%{release} Requires: %{name}-shorewall = %{version}-%{release} # Currently this breaks jails that don't log to the journal #Requires: %{name}-systemd = %{version}-%{release} -# No python3 support for gamin -#Requires: gamin-python Requires: perl-interpreter -Requires: python3-inotify +%if 0%{?rhel} && 0%{?rhel} < 8 +Requires: python-inotify +# No python3 support for gamin so epel only +Requires: gamin-python +%else +Requires: python2-inotify +%endif Requires: /usr/bin/whois %description all @@ -186,29 +202,32 @@ by default. # Use Fedora paths sed -i -e 's/^before = paths-.*/before = paths-fedora.conf/' config/jail.conf +%if 0%{?fedora} || 0%{?rhel} >= 8 2to3 --write --nobackups . find -type f -exec sed -i -e '1s,^#!/usr/bin/python *,#!/usr/bin/python%{python3_version},' {} + +%endif # SELinux sources cp -p %SOURCE1 %SOURCE2 %SOURCE3 . -# In Fedora 32 and EL 8 nftables is the default firewall and does not accept ":" for port ranges. -# https://bugzilla.redhat.com/show_bug.cgi?id=1850164 -%if 0%{?fedora} >= 32 || 0%{?rhel} >= 8 -sed -i "s/port = 0:65535/port = 0-65535/" config/jail.conf -%endif - - %build +%if 0%{?rhel} && 0%{?rhel} < 8 +%py2_build +%else %py3_build +%endif make -f %SOURCE4 %install -%py3_install - +%if 0%{?rhel} && 0%{?rhel} < 8 +%py2_install # Make symbolic link relative +ln -fs python2 %{buildroot}%{_bindir}/fail2ban-python +%else +%py3_install ln -fs python3 %{buildroot}%{_bindir}/fail2ban-python +%endif mkdir -p %{buildroot}%{_unitdir} cp -p build/fail2ban.service %{buildroot}%{_unitdir}/ @@ -261,7 +280,11 @@ install -m 0644 %{modulename}.pp.bz2 %{buildroot}%{_datadir}/selinux/packages/%{ %check +%if 0%{?rhel} && 0%{?rhel} < 8 +%python2 bin/fail2ban-testcases --verbosity=2 --no-network +%else %python3 bin/fail2ban-testcases --verbosity=2 --no-network +%endif %pre selinux @@ -302,8 +325,13 @@ fi %{_bindir}/fail2ban-python %{_bindir}/fail2ban-regex %{_bindir}/fail2ban-server +%if 0%{?rhel} && 0%{?rhel} < 8 +%{python2_sitelib}/* +%exclude %{python2_sitelib}/fail2ban/tests +%else %{python3_sitelib}/* %exclude %{python3_sitelib}/fail2ban/tests +%endif %{_unitdir}/fail2ban.service %{_mandir}/man1/fail2ban.1* %{_mandir}/man1/fail2ban-client.1* @@ -338,7 +366,11 @@ fi %files tests %{_bindir}/fail2ban-testcases %{_mandir}/man1/fail2ban-testcases.1* +%if 0%{?rhel} && 0%{?rhel} < 8 +%{python2_sitelib}/fail2ban/tests +%else %{python3_sitelib}/fail2ban/tests +%endif %files mail %config(noreplace) %{_sysconfdir}/fail2ban/action.d/complain.conf