Blame SOURCES/selinux-autorelabel

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