# -*- mode: shell-script; -*-
# rc0 - runlevel 0 compatibility
#
# This task runs the old sysv-rc runlevel 0 ("halt/poweroff") scripts with
# the decision as to whether to halt or power off the system left up to the
# script (and thus /etc/default/poweroff).

# runlevel 0 means shutting down.
start on runlevel 0

stop on runlevel [!0]

console output
script
    set $(runlevel || true)
    if [ "$2" != "0" ] && [ "$2" != "6" ]; then
        set $(runlevel --set 0 || true)
    fi

    if [ "$1" != "unknown" ]; then
        PREVLEVEL=$1
        RUNLEVEL=$2
        export PREVLEVEL RUNLEVEL
    fi

    exec /etc/init.d/rc 0
end script
