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