Name: setroubleshoot
Version: 3.3.20
Release: 3
Summary: SELinux Trouble Shooting Tool
License: GPLv2+
URL: https://pagure.io/setroubleshoot

Source0: https://releases.pagure.org/setroubleshoot/%{name}-%{version}.tar.gz
Source1: %{name}.tmpfiles

BuildRequires: gcc libcap-ng-devel intltool gettext python3 python3-devel git
BuildRequires: desktop-file-utils dbus-glib-devel gtk2-devel libnotify-devel audit-libs-devel libselinux-devel polkit-devel
BuildRequires: python3-libselinux python3-pydbus python3-gobject gtk3-devel xdg-utils

Requires: %{name}-server = %{version}-%{release} 
Requires: gtk3, libnotify libreport python3-libreport python3-gobject python3-pydbus xdg-utils
Requires(post): desktop-file-utils
Requires(post): dbus
Requires(postun): desktop-file-utils
Requires(postun): dbus

%description
SELinux Trouble Shooting Tool

%package server
Summary: SELinux troubleshoot server

Requires: %{name}-plugins >= 3.3.8
Requires: audit >= 2.8.5
Requires: python3-audit
Requires: python3-libxml2
Requires: python3-rpm
Requires: python3-libselinux
Requires: policycoreutils-python-utils
BuildRequires: intltool gettext python3
BuildRequires: python3-devel
Requires: python3-slip python3-systemd
Requires: python3-gobject >= 3.11
Requires: dbus
Requires: python3-dbus
Requires: polkit
Requires(pre): /usr/sbin/useradd /usr/sbin/groupadd

%description server
Provides tools to help diagnose SELinux problems. When AVC messages
are generated an alert can be generated that will give information
about the problem and help track its resolution. Alerts can be configured
to user preference. The same tools can be run on existing log files.

%package legacy
Summary: SELinux troubleshoot legacy applet

Requires: gtk2
Requires: %{name} = %{version}-%{release}

%description legacy
SELinux troubleshoot legacy applet

%package_help

%prep
%autosetup -n %{name}-%{version} -S git

%build
%global _python_bytecompile_extra 0
%configure PYTHON=%{__python3} --enable-seappletlegacy=yes --with-auditpluginsdir=/etc/audit/plugins.d
%make_build V=1

%install
%make_install PREFIX=%{_prefix}
desktop-file-install --vendor="" --dir=%{buildroot}%{_datadir}/applications %{buildroot}/%{_datadir}/applications/%{name}.desktop
mkdir -p %{buildroot}%{_localstatedir}/lib/%{name}
mkdir -p %{buildroot}%{_rundir}/setroubleshoot
touch %{buildroot}%{_localstatedir}/lib/%{name}/setroubleshoot_database.xml
touch %{buildroot}%{_localstatedir}/lib/%{name}/email_alert_recipients
# create /run/setroubleshoot on boot
install -m644 -D %{SOURCE1} $RPM_BUILD_ROOT%{_tmpfilesdir}/%{name}.conf

%find_lang %{name}

%post
dbus-send --system /com/redhat/setroubleshootd com.redhat.SEtroubleshootdIface.restart string:'rpm install' >/dev/null 2>&1 || :
%systemd_post auditd.service

%postun
%systemd_postun_with_restart auditd.service

%pre server
getent passwd setroubleshoot >/dev/null || useradd -r -U -s /sbin/nologin -d %{_localstatedir}/lib/%{name} setroubleshoot

%post server
%systemd_post auditd.service

%postun server
%systemd_postun_with_restart auditd.service
%triggerun server -- %{name}-server < 3.2.24-4
chown -R setroubleshoot:setroubleshoot %{_localstatedir}/lib/%{name}

%files
%license COPYING
%{_bindir}/seapplet
%config(noreplace) %{_sysconfdir}/xdg/autostart/*
%{_datadir}/%{name}/gui
%{_datadir}/applications/*.desktop
%{_datadir}/appdata/*.appdata.xml
%{_datadir}/dbus-1/services/sealert.service
%{_datadir}/icons/hicolor/*/*/*
%dir %attr(0755,root,root) %{python3_sitelib}/%{name}
%{python3_sitelib}/%{name}/browser.py
%{python3_sitelib}/%{name}/gui_utils.py
%{python3_sitelib}/%{name}/__pycache__/browser.cpython*
%{python3_sitelib}/%{name}/__pycache__/gui_utils.cpython*

%files server -f %{name}.lang
%{_bindir}/sealert
%{_sbindir}/sedispatch
%{_sbindir}/setroubleshootd
%{python3_sitelib}/setroubleshoot*.egg-info
%dir %attr(0755,root,root) %{_sysconfdir}/%{name}
%dir %{python3_sitelib}/%{name}
%dir %{python3_sitelib}/%{name}/__pycache__
%{python3_sitelib}/%{name}/*.py
%exclude %{python3_sitelib}/%{name}/browser.py
%exclude %{python3_sitelib}/%{name}/gui_utils.py
%{python3_sitelib}/%{name}/__pycache__/*.cpython*
%exclude %{python3_sitelib}/%{name}/__pycache__/browser.cpython*
%exclude %{python3_sitelib}/%{name}/__pycache__/gui_utils.cpython*
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/SetroubleshootFixit.py
%{_datadir}/%{name}/updater.py
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/org.fedoraproject.Setroubleshootd.conf
%attr(0700,setroubleshoot,setroubleshoot) %dir %{_localstatedir}/lib/%{name}
%ghost %attr(0600,setroubleshoot,setroubleshoot) %{_localstatedir}/lib/%{name}/setroubleshoot_database.xml
%ghost %attr(0644,setroubleshoot,setroubleshoot) %{_localstatedir}/lib/%{name}/email_alert_recipients
%config /etc/audit/plugins.d/sedispatch.conf
%{_datadir}/dbus-1/system-services/org.fedoraproject.Setroubleshootd.service
%{_datadir}/polkit-1/actions/org.fedoraproject.setroubleshootfixit.policy
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/org.fedoraproject.SetroubleshootFixit.conf
%{_datadir}/dbus-1/system-services/org.fedoraproject.SetroubleshootFixit.service
%attr(0644,root,root) %{_tmpfilesdir}/%{name}.conf
%attr(0711,setroubleshoot,setroubleshoot) %dir %{_rundir}/setroubleshoot
%doc AUTHORS COPYING ChangeLog DBUS.md NEWS README TODO

%files legacy
%{_bindir}/seappletlegacy

%files help
%{_docdir}/%{name}*
%{_mandir}/man8/sealert.8.gz
%{_mandir}/man8/sedispatch.8.gz
%{_mandir}/man8/setroubleshootd.8.gz
%{_mandir}/man1/seapplet.1.gz

%changelog
* Thu Aug 20 2020 wangchen <wangchen137@huawei.com> - 3.3.20-3
- fix the failure of building for audit downgrade

* Thu Oct 10 2019 openEuler Buildteam <buildteam@openeuler.org> - 3.3.20-2
- add COPYING to license directory

* Tue Aug 27 2019 openEuler Buildteam <buildteam@openeuler.org> - 3.3.20-1
- Package init
