9753a77
#!/bin/bash
9753a77
#
9753a77
# Do automatic relabelling
9753a77
#
9753a77
9753a77
# . /etc/init.d/functions
9753a77
9753a77
relabel_selinux() {
9753a77
    # if /sbin/init is not labeled correctly this process is running in the
9753a77
    # wrong context, so a reboot will be required after relabel
9753a77
    AUTORELABEL=
9753a77
    . /etc/selinux/config
9753a77
    echo "0" > /sys/fs/selinux/enforce
9753a77
    [ -x /bin/plymouth ] && plymouth --hide-splash
9753a77
9753a77
    if [ "$AUTORELABEL" = "0" ]; then
9753a77
	echo
9753a77
	echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required. "
9753a77
	echo $"*** /etc/selinux/config indicates you want to manually fix labeling"
9753a77
	echo $"*** problems. Dropping you to a shell; the system will reboot"
9753a77
	echo $"*** when you leave the shell."
9753a77
	sulogin
9753a77
9753a77
    else
9753a77
	echo
9753a77
	echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required."
9753a77
	echo $"*** Relabeling could take a very long time, depending on file"
9753a77
	echo $"*** system size and speed of hard drives."
9753a77
9753a77
	FORCE=`cat /.autorelabel`
9753a77
        [ -x "/usr/sbin/quotaoff" ] && /usr/sbin/quotaoff -aug
9753a77
	/sbin/fixfiles $FORCE restore > /dev/null 2>&1
9753a77
    fi
9753a77
    rm -f  /.autorelabel
9753a77
    /usr/lib/dracut/dracut-initramfs-restore
9753a77
    systemctl --force reboot
9753a77
}
9753a77
9753a77
# Check to see if a full relabel is needed
9753a77
if [ "$READONLY" != "yes" ]; then
9753a77
    restorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\// { print $2 }' /etc/fstab) >/dev/null 2>&1
9753a77
    relabel_selinux
9753a77
fi