Petr Lautrbach 28f9992
#!/bin/bash
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"
Petr Lautrbach 0d980e2
    AUTORELABEL="1"
Petr Lautrbach 0d980e2
    source /etc/selinux/config
Petr Lautrbach 0d980e2
    if [ "$AUTORELABEL" = "0" ]; then
Petr Lautrbach 0d980e2
        mkdir -p "$earlydir/selinux-autorelabel.service.d"
Petr Lautrbach 0d980e2
        cat > "$earlydir/selinux-autorelabel.service.d/tty.conf" <
Petr Lautrbach 0d980e2
[Service]
Petr Lautrbach 0d980e2
StandardInput=tty
Petr Lautrbach 0d980e2
EOF
Petr Lautrbach 0d980e2
    fi
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