#!/bin/sh
#
# devfsd		This script handles the devfs startup, so that
#			permissions are set correctly and device symlinks
#			are available.
#

[ -x /sbin/devfsd ] || exit 0

NAME="devsfd"
DESC="Device file system management daemon"
DAEMON="/sbin/devfsd"
SSDARGS=""

# defaults, change them in /etc/default/devfsd, not here
MOUNTPOINT=/dev
MOUNT=no

[ -f /etc/default/devfsd ] && . /etc/default/devfsd

DEVFSDARGS="$MOUNTPOINT"

if [ "$MOUNT" != "no" ]; then
	if [ "$1" != "stop"  ] && [ ! -e $MOUNTPOINT/.devfsd ]; then
		echo "Mounting devfs on $MOUNTPOINT"
		mount -t devfs devfs $MOUNTPOINT
	fi
fi

# only start if there seems to be a devfs
if [ ! -e $MOUNTPOINT/.devfsd ] && [ "$1" != "stop" ]; then
    echo devfsd: No devfs on $MOUNTPOINT, not starting. >&2
    exit 0
fi

[ -d /proc/1 ] || mount -n /proc

PATH=/bin:/sbin
export PATH

case "$1" in
  start)
	/sbin/devfsd_make_links
#	echo -n "Starting $DESC: "
	start-stop-daemon --start --oknodo $SSDARGS \
	    --exec $DAEMON -- $DEVFSDARGS
#	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --oknodo $SSDARGS \
	    --exec $DAEMON
	echo "$NAME."
	;;
  reload|force-reload)
	/sbin/devfsd_make_links
	echo -n "Reloading $DESC: "
	start-stop-daemon --stop --oknodo --signal 1 $SSDARGS \
	    --exec $DAEMON
	;;
  restart)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --oknodo $SSDARGS \
	    --exec $DAEMON
	echo "stopped"
	sleep 1
	/sbin/devfsd_make_links
	start-stop-daemon --start $SSDARGS \
	    --exec $DAEMON -- $DEVFSDARGS
#	echo "$NAME."
	;;
  *)
	echo "Usage: /etc/init.d/devfsd {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
