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