Name:      firewalld
Version:   0.6.6
Release:   4
Summary:   A firewall daemon with D-Bus interface providing a dynamic firewall
License:   GPLv2+
URL:       http://www.firewalld.org
Source0:   https://github.com/firewalld/firewalld/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
#backport from gnome
Patch0:     firewalld-0.2.6-MDNS-default.patch
#backport from Eric Garver <e@erig.me>
Patch1:     0001-fedora-patch-to-default-to-iptables-backend.patch

BuildArch:     noarch
BuildRequires: autoconf automake desktop-file-utils gettext intltool glib2 glib2-devel systemd-units docbook-style-xsl
BuildRequires: libxslt iptables ebtables ipset nftables python3-devel


Requires:  iptables ebtables ipset systemd hicolor-icon-theme python3-gobject NetworkManager-libnm dbus-x11 gtk3
Requires:  nftables >= 0.9.0 python3-firewall  = %{version}-%{release} %{name}-doc

Obsoletes: firewalld-selinux < 0.4.4.2-2
Conflicts: selinux-policy < 3.14.1-28
Conflicts: cockpit-ws < 173-2

Provides:  variant_config(Server)
Provides:  variant_config(Workstation)

Obsoletes: firewalld-config-standard <= 0.3.15
Obsoletes: firewalld-config-cloud <= 0.3.15
Obsoletes: firewalld-config-server <= 0.3.15
Obsoletes: firewalld-config-workstation <= 0.3.15

Provides:  firewalld-filesystem = %{version}-%{release} firewall-config = %{version}-%{release}
Obsoletes: firewalld-filesystem < %{version}-%{release} firewall-config < %{version}-%{release}

%description
firewalld is a firewall service daemon that provides a dynamic customizable
firewall with a D-Bus interface.

%package doc
Summary: Documentation for firewalld
%description doc
Documentation for firewalld.


%package -n python3-firewall
Summary: Python3 bindings for firewalld

%{?python_provide:%python_provide python3-firewall}

Obsoletes: python-firewall < 0.5.2-2 
Obsoletes: python2-firewall < 0.5.2-2
Requires: python3-dbus python3-slip-dbus python3-decorator python3-gobject-base

%description -n python3-firewall
Python3 bindings for firewalld.




%prep
%autosetup -n %{name}-%{version} -p1
./autogen.sh



%build
%configure --enable-sysconfig --enable-rpmmacros PYTHON=%{__python3}

%make_build

%install
%make_install

desktop-file-install --delete-original \
  --dir %{buildroot}%{_sysconfdir}/xdg/autostart \
  %{buildroot}%{_sysconfdir}/xdg/autostart/firewall-applet.desktop
desktop-file-install --delete-original \
  --dir %{buildroot}%{_datadir}/applications \
  %{buildroot}%{_datadir}/applications/firewall-config.desktop


mv %{buildroot}%{_sysconfdir}/firewalld/firewalld.conf \
    %{buildroot}%{_sysconfdir}/firewalld/firewalld-standard.conf


%find_lang %{name} --all-name

dd if=/dev/zero of=$RPM_BUILD_ROOT/%{_datadir}/firewalld/firewalld-tmp-mmap bs=4096 count=1

%check

%pre

%preun
%systemd_preun firewalld.service


%post
%systemd_post firewalld.service


%postun
%systemd_postun_with_restart firewalld.service

%posttrans
# If we don't yet have a symlink or existing file for firewalld.conf,
# create it. Note: this will intentionally reset the policykit policy
# at the same time, so they are in sync.

# Import /etc/os-release to get the variant definition
. /etc/os-release || :

if [ ! -e %{_sysconfdir}/firewalld/firewalld.conf ]; then
    case "$VARIANT_ID" in
        server)
            ln -sf firewalld-server.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ;;
        workstation)
            ln -sf firewalld-workstation.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ;;
        *)
            ln -sf firewalld-standard.conf %{_sysconfdir}/firewalld/firewalld.conf
            ;;
    esac
fi

if [ ! -e %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy ]; then
    case "$VARIANT_ID" in
        workstation)
            ln -sf org.fedoraproject.FirewallD1.desktop.policy.choice %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        *)
            # For all other editions, we'll use the Server polkit policy
            ln -sf org.fedoraproject.FirewallD1.server.policy.choice %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
    esac
fi


%files -f %{name}.lang
%doc COPYING README
%{_sbindir}/firewalld
%{_bindir}/firewall-config
%{_bindir}/firewall-cmd
%{_bindir}/firewall-offline-cmd
%{_datadir}/bash-completion/completions/firewall-cmd
%{_prefix}/lib/firewalld/*
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-standard.conf
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/helpers
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/icmptypes
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/ipsets
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/services
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/zones
%ghost %config(noreplace) %{_sysconfdir}/firewalld/firewalld.conf
%config(noreplace) %{_sysconfdir}/firewalld/lockdown-whitelist.xml
%defattr(0644,root,root)
%config(noreplace) %{_sysconfdir}/sysconfig/firewalld
%{_unitdir}/firewalld.service
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/FirewallD.conf
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy.choice
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy.choice
%ghost %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy
%{_sysconfdir}/modprobe.d/firewalld-sysctls.conf

%{_rpmconfigdir}/macros.d/macros.firewalld

#we don't need applet
%exclude %{_bindir}/firewall-applet
%exclude %{_sysconfdir}/xdg/autostart/firewall-applet.desktop
%exclude %dir %{_sysconfdir}/firewall
%exclude %{_sysconfdir}/firewall/applet.conf
%exclude %{_datadir}/icons/hicolor/*/apps/firewall-applet*.*
%exclude %{_mandir}/man1/firewall-applet*.1*

%defattr(0644,root,root)
%attr (0700,root,root) %{_datadir}/firewalld/firewalld-tmp-mmap
%{_datadir}/firewalld/*
%{_datadir}/applications/firewall-config.desktop
%{_datadir}/metainfo/firewall-config.appdata.xml
%{_datadir}/icons/hicolor/*/apps/firewall-config*.*
%{_datadir}/glib-2.0/schemas/org.fedoraproject.FirewallConfig.gschema.xml

%files  doc
%{_mandir}/man1/firewall*
%{_mandir}/man5/firewall*


%files -n python3-firewall
%defattr(-,root,root)
%{python3_sitelib}/firewall/*



%changelog
* Fri May 21 2021 xihaochen<xihaochen@huawei.com> - 0.9.6-4
- Type:requirement
- ID:NA
- SUG:NA
- DESC:drop Requires:kernel

* Wed Dec 23 2020 Anakin Zhang <benjamin93@163.com> - 0.9.6-3
- Type:requirement
- ID:NA
- SUG:NA
- DESC:create firewalld temporary file

* Wed Feb 24 2021 hanzhijun <hanzhijun1@huawei.com> - 0.6.6-3
- drop Requires: kernel

* Tue Nov 10 2020 quanhongfei <quanhongfei@huawei.com> - 0.6.6-2
- Type:requirement
- ID:NA
- SUG:NA
- DESC:add firewalld-doc dependency for firewalld

* Fri Aug 28 2020 gaihuiying <gaihuiying1@huawei.com> - 0.6.6-1
- Type:requirement
- ID:NA
- SUG:NA
- DESC:update firewalld version to 0.6.6

* Wed Jan 15 2020 zhangrui <zhangrui182@huawei.com> - 0.6.2-4
- create firewalld.conf file

* Sat Sep 28 2019 huzhiyu <huzhiyu1@huawei.com> - 0.6.2-3
- create firewalld.conf file

* Thu Sep 5 2019 hufeng <solar.hu@huawei.com> - 0.6.2.2
- Create firewalld spec.
