Blame SOURCES/selinux-autorelabel

9bbebd
#!/bin/bash
9bbebd
#
9bbebd
# Do automatic relabelling
9bbebd
#
9bbebd
9bbebd
# . /etc/init.d/functions
9bbebd
9bbebd
# If the user has this (or similar) UEFI boot order:
9bbebd
#
9bbebd
#             Windows | grub | Linux
9bbebd
#
9bbebd
# And decides to boot into grub/Linux, then the reboot at the end of autorelabel
9bbebd
# would cause the system to boot into Windows again, if the autorelabel was run.
9bbebd
#
9bbebd
# This function restores the UEFI boot order, so the user will boot into the
9bbebd
# previously set (and expected) partition.
9bbebd
efi_set_boot_next() {
9bbebd
    # NOTE: The [ -x /usr/sbin/efibootmgr ] test is not sufficent -- it could
9bbebd
    #       succeed even on system which is not EFI-enabled...
9bbebd
    if ! efibootmgr > /dev/null 2>&1; then
9bbebd
        return
9bbebd
    fi
9bbebd
9bbebd
    # NOTE: It it possible that some other services might be setting the
9bbebd
    #       'BootNext' item for any reasons, and we shouldn't override it if so.
9bbebd
    if ! efibootmgr | grep --quiet -e 'BootNext'; then
9bbebd
        CURRENT_BOOT="$(efibootmgr | grep -e 'BootCurrent' | sed -re 's/(^.+:[[:space:]]*)([[:xdigit:]]+)/\2/')"
9bbebd
        efibootmgr -n "${CURRENT_BOOT}" > /dev/null 2>&1
9bbebd
    fi
9bbebd
}
9bbebd
9bbebd
relabel_selinux() {
9bbebd
    # if /sbin/init is not labeled correctly this process is running in the
9bbebd
    # wrong context, so a reboot will be required after relabel
9bbebd
    AUTORELABEL=
9bbebd
    . /etc/selinux/config
9bbebd
    echo "0" > /sys/fs/selinux/enforce
9bbebd
    [ -x /bin/plymouth ] && plymouth --quit
9bbebd
9bbebd
    if [ "$AUTORELABEL" = "0" ]; then
9bbebd
	echo
9bbebd
	echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required. "
9bbebd
	echo $"*** /etc/selinux/config indicates you want to manually fix labeling"
9bbebd
	echo $"*** problems. Dropping you to a shell; the system will reboot"
9bbebd
	echo $"*** when you leave the shell."
9bbebd
	sulogin
9bbebd
9bbebd
    else
9bbebd
	echo
9bbebd
	echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required."
9bbebd
	echo $"*** Relabeling could take a very long time, depending on file"
9bbebd
	echo $"*** system size and speed of hard drives."
9bbebd
9bbebd
	FORCE=`cat /.autorelabel`
9bbebd
        [ -x "/usr/sbin/quotaoff" ] && /usr/sbin/quotaoff -aug
9bbebd
	/sbin/fixfiles $FORCE restore
9bbebd
    fi
9bbebd
9bbebd
    rm -f  /.autorelabel
9bbebd
    /usr/lib/dracut/dracut-initramfs-restore
9bbebd
    efi_set_boot_next
9bbebd
    if [ -x /usr/bin/grub2-editenv ]; then
9bbebd
        grub2-editenv - incr boot_indeterminate >/dev/null 2>&1
9bbebd
    fi
9bbebd
    sync
9bbebd
    systemctl --force reboot
9bbebd
}
9bbebd
9bbebd
# Check to see if a full relabel is needed
9bbebd
if [ "$READONLY" != "yes" ]; then
9bbebd
    restorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\// { print $2 }' /etc/fstab) >/dev/null 2>&1
9bbebd
    relabel_selinux
9bbebd
fi