Blob Blame History Raw
# Copyright (C) 2016  Petr Lautrbach
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# RPM macros for packages installing SELinux modules

%_selinux_policy_version SELINUXPOLICYVERSION

%_file_context_file %{_sysconfdir}/selinux/${SELINUXTYPE}/contexts/files/file_contexts
%_file_context_file_pre %{_localstatedir}/lib/rpm-state/file_contexts.pre

# %selinux_modules_install [-s <policytype>] module [module]...
%selinux_modules_install("s:") \
. /etc/selinux/config \
_policytype=%{-s*} \
if [ -z "${_policytype}" ]; then \
  _policytype="targeted" \
fi \
%{_sbindir}/semodule -n -s ${_policytype} -X 200 -i %* \
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
  %{_sbindir}/load_policy \
fi \
%{nil}

# %selinux_modules_uninstall [-s <policytype>] module [module]...
%selinux_modules_uninstall("s:") \
. /etc/selinux/config \
_policytype=%{-s*} \
if [ -z "${_policytype}" ]; then \
  _policytype="targeted" \
fi \
if [ $1 -eq 0 ]; then \
  %{_sbindir}/semodule -n -X 200 -r %* &> /dev/null || : \
  if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
    %{_sbindir}/load_policy \
  fi \
fi \
%{nil}

# %selinux_relabel_pre [-s <policytype>]
%selinux_relabel_pre("s:") \
. /etc/selinux/config \
_policytype=%{-s*} \
if [ -z "${_policytype}" ]; then \
  _policytype="targeted" \
fi \
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
  [ -f %{_file_context_file_pre} ] || cp -f %{_file_context_file} %{_file_context_file_pre} \
fi \
%{nil}


# %selinux_relabel_post [-s <policytype>]
%selinux_relabel_post("s:") \
. /etc/selinux/config \
_policytype=%{-s*} \
if [ -z "${_policytype}" ]; then \
  _policytype="targeted" \
fi \
if /usr/sbin/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
   if [ -f %{_file_context_file_pre} ]; then \
     %{_sbindir}/fixfiles -C %{_file_context_file_pre} restore \
     rm -f %{_file_context_file_pre} \
   fi \
fi \
%{nil}