183d121
#!/bin/sh
183d121
183d121
# This systemd.generator(7) detects if SELinux is running and if the
183d121
# user requested an autorelabel, and if so sets the default target to
183d121
# selinux-autorelabel.target, which will cause the filesystem to be
183d121
# relabelled and then the system will reboot again and boot into the
183d121
# real default target.
183d121
183d121
PATH=/usr/sbin:$PATH
183d121
unitdir=/usr/lib/systemd/system
183d121
183d121
# If invoked with no arguments (for testing) write to /tmp.
183d121
earlydir="/tmp"
183d121
if [ -n "$2" ]; then
183d121
    earlydir="$2"
183d121
fi
183d121
183d121
set_target ()
183d121
{
183d121
    ln -sf "$unitdir/selinux-autorelabel.target" "$earlydir/default.target"
183d121
}
183d121
183d121
if selinuxenabled; then
183d121
    if test -f /.autorelabel; then
183d121
        set_target
183d121
    elif grep -sqE "\bautorelabel\b" /proc/cmdline; then
183d121
        set_target
183d121
    fi
183d121
fi