#!/bin/sh
# Handle /dev,/proc etc
#
. /boot.conf
test "$LOG_START" && echo "<*> Executing '$0 $*'"

test "$LOG_STAGE" && echo "* Mounting proc on /proc"
mount -n -t proc none /proc \
|| echo "! mount proc failure"

if test "$MOUNT_SYS"; then
    test "$LOG_STAGE" && echo "* Mounting sysfs on /sys"
    mount -n -t sysfs none /sys \
    || echo "! mount sysfs failure"
fi

if test "$MOUNT_DEVFS"; then
    test "$LOG_STAGE" && echo "* Mounting devfs on /dev"
    mount -n -t devfs none /dev \
    || echo "! mount devfs failure"
fi

if test "$NEED_DEVFSD"; then
    test "$LOG_STAGE" && echo "* Starting devfsd"
    env - devfsd /dev </dev/null >/dev/null 2>&1 \
    || echo "! devfsd startup failure"
fi

if test "$USE_UDEV"; then
    test "$LOG_STAGE" && echo "* Mounting ramfs on /dev and starting udevd"
    # Just in case initrd left one running...
    killall udevd
    umount -nl /dev
    mount -t ramfs none /dev
    # Needed for "udevd &" to successfully redirect stdin
    mknod /dev/null c 1 3
    # set UDEV_LOG="debug" in the env to activate
    # debug messages to syslog (requires udevd built with DEBUG=true)
    #env - UDEV_LOG="debug" udevd </dev/null >/dev/null 2>&1 &
    env - udevd >/dev/null 2>&1 &
    sleep 1
    udevstart
fi

exit 0
