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