94dc8ea
# Copyright (C) 2016  Petr Lautrbach
94dc8ea
#
94dc8ea
# This program is free software; you can redistribute it and/or
94dc8ea
# modify it under the terms of the GNU General Public License
94dc8ea
# as published by the Free Software Foundation; either version 2
94dc8ea
# of the License, or (at your option) any later version.
94dc8ea
#
94dc8ea
# This program is distributed in the hope that it will be useful,
94dc8ea
# but WITHOUT ANY WARRANTY; without even the implied warranty of
94dc8ea
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
94dc8ea
# GNU General Public License for more details.
94dc8ea
#
94dc8ea
# You should have received a copy of the GNU General Public License
94dc8ea
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
94dc8ea
94dc8ea
# RPM macros for packages installing SELinux modules
94dc8ea
94dc8ea
%_selinux_policy_version SELINUXPOLICYVERSION
94dc8ea
94dc8ea
%_file_context_file %{_sysconfdir}/selinux/${SELINUXTYPE}/contexts/files/file_contexts
94dc8ea
%_file_context_file_pre %{_localstatedir}/lib/rpm-state/file_contexts.pre
94dc8ea
94dc8ea
# %selinux_modules_install [-s <policytype>] module [module]...
94dc8ea
%selinux_modules_install("s:") \
94dc8ea
. /etc/selinux/config \
94dc8ea
_policytype=%{-s*} \
94dc8ea
if [ -z "${_policytype}" ]; then \
94dc8ea
  _policytype="targeted" \
94dc8ea
fi \
94dc8ea
%{_sbindir}/semodule -n -s ${_policytype} -X 200 -i %* \
94dc8ea
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
94dc8ea
  %{_sbindir}/load_policy \
94dc8ea
fi \
94dc8ea
%{nil}
94dc8ea
94dc8ea
# %selinux_modules_uninstall [-s <policytype>] module [module]...
94dc8ea
%selinux_modules_uninstall("s:") \
94dc8ea
. /etc/selinux/config \
94dc8ea
_policytype=%{-s*} \
94dc8ea
if [ -z "${_policytype}" ]; then \
94dc8ea
  _policytype="targeted" \
94dc8ea
fi \
94dc8ea
if [ $1 -eq 0 ]; then \
94dc8ea
  %{_sbindir}/semodule -n -X 200 -r %* &> /dev/null || : \
94dc8ea
  if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
94dc8ea
    %{_sbindir}/load_policy \
94dc8ea
  fi \
94dc8ea
fi \
94dc8ea
%{nil}
94dc8ea
94dc8ea
# %selinux_relabel_pre [-s <policytype>]
94dc8ea
%selinux_relabel_pre("s:") \
94dc8ea
. /etc/selinux/config \
94dc8ea
_policytype=%{-s*} \
94dc8ea
if [ -z "${_policytype}" ]; then \
94dc8ea
  _policytype="targeted" \
94dc8ea
fi \
94dc8ea
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
94dc8ea
  [ -f %{_file_context_file_pre} ] || cp -f %{_file_context_file} %{_file_context_file_pre} \
94dc8ea
fi \
94dc8ea
%{nil}
94dc8ea
94dc8ea
94dc8ea
# %selinux_relabel_post [-s <policytype>]
94dc8ea
%selinux_relabel_post("s:") \
94dc8ea
. /etc/selinux/config \
94dc8ea
_policytype=%{-s*} \
94dc8ea
if [ -z "${_policytype}" ]; then \
94dc8ea
  _policytype="targeted" \
94dc8ea
fi \
94dc8ea
if /usr/sbin/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
94dc8ea
   if [ -f %{_file_context_file_pre} ]; then \
94dc8ea
     %{_sbindir}/fixfiles -C %{_file_context_file_pre} restore \
94dc8ea
     rm -f %{_file_context_file_pre} \
94dc8ea
   fi \
94dc8ea
fi \
94dc8ea
%{nil}