#!/bin/sh

PREREQ="udev"

prereqs() {
    echo "$PREREQ"
}

case "$1" in
    prereqs)
        prereqs
        exit 0
    ;;
esac

[ "$IP" != off -a "$IP" != none -a -x /sbin/dropbear ] || exit 0


run_dropbear() {
    # always run configure_networking() before dropbear(8); on NFS
    # mounts this has been done already
    [ "$boot" = nfs ] || configure_networking

    log_begin_msg "Starting dropbear"
    # using exec and keeping dropbear in the foreground enables the
    # init-bottom script to kill the remaining ipconfig processes if
    # someone unlocks the rootfs from the console while the network is
    # being configured
    exec /sbin/dropbear ${DROPBEAR_OPTIONS:-$PKGOPTION_dropbear_OPTION} -Fs
}

. /conf/initramfs.conf
. /scripts/functions

# On NFS mounts, wait until the network is configured.  On local mounts,
# configure the network in the background (in run_dropbear()) so someone
# with console access can enter the passphrase immediately.  (With the
# default ip=dhcp, configure_networking hangs for 5mins or so when the
# network is unavailable, for instance.)
[ "$boot" != nfs ] || configure_networking

run_dropbear &
echo $! >/run/dropbear.pid
