# Init script for friendly recovery

start on recovery

console owner
task

emits recovery
emits startup
emits mounted

pre-start script
    if plymouth --ping; then
        plymouth hide-splash || true
    fi

    # Try to set the hostname and initialize the console
    start hostname || true
    start console-setup || true
    start setvtrgb || true

    # Make sure /run contains the required directories for the
    # recovery menu options
    mkdir -p /run/lock /run/shm || true

    # Emit the mounted event to trigger resolvconf and mounted-run
    initctl emit mounted MOUNTPOINT=/run || true

    # Finally start udev
    start udev || true
    udevadm trigger --action=add || true
    udevadm settle || true

    # And turn off kernel messages (to avoid corrupting the menu)
    dmesg --console-off || true
end script

script
    # Only start friendly-recovery when booting in recovery mode
    if ! grep -q "recovery" /proc/cmdline; then
        exit 0
    fi

    if [ -x /lib/recovery-mode/recovery-menu ]; then
        exec /lib/recovery-mode/recovery-menu
    else
        exec /sbin/sulogin
    fi
end script

post-stop script
    if plymouth --ping; then
        plymouth show-splash
    fi
    initctl emit startup
end script

