#!/bin/sh
########################################################################
# Begin $rc_base/init.d/udev
#
# Description : Udev cold-plugging script
#
# Authors     : Zack Winkles, Alexander E. Patrakov
#
# Version     : 00.02
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
	start)
		boot_mesg "Populating /dev with device nodes..."
		if ! grep -q '[[:space:]]sysfs' /proc/mounts; then
			echo_failure
			boot_mesg -n "FAILURE:\n\nUnable to create" ${FAILURE}
			boot_mesg -n " devices without a SysFS filesystem"
			boot_mesg -n "\n\nAfter you press Enter, this system"
			boot_mesg -n " will be halted and powered off."
			boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
			boot_mesg "" ${NORMAL}
			read ENTER
			/etc/rc.d/init.d/halt stop
		fi
		if ! grep -q '[[:space:]]/dev' /proc/mounts; then
			echo_failure
			boot_mesg -n "FAILURE:\n\nKernel has no devtmpfs/mount" ${FAILURE}
			boot_mesg -n " support but this is needed for udev."
			boot_mesg -n "\n\nAfter you press Enter, this system"
			boot_mesg -n " will be halted and powered off."
			boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
			boot_mesg "" ${NORMAL}
			read ENTER
			/etc/rc.d/init.d/halt stop
		fi

		if ! grep -q '[[:space:]]/dev/shm' /proc/mounts; then
			mkdir -p /dev/shm
			mount -t tmpfs tmpfs /dev/shm
		fi

		if ! grep -q '[[:space:]]/dev/pts' /proc/mounts; then
			mkdir -p /dev/pts
			mount -t devpts devpts -o gid=5,mode=620 /dev/pts
		fi

		# Start the udev daemon to continually watch for, and act on,
		# uevents
		boot_mesg "Starting udev daemon..."
		loadproc udevd --daemon

		# Now traverse /sys in order to "coldplug" devices that have
		# already been discovered
		/bin/udevadm trigger --action=add

		# Now wait for udevd to process the uevents we triggered
		/bin/udevadm settle
		evaluate_retval

		;;

	restart)
		boot_mesg "Stopping udev daemon..."
		killproc udevd

		exec $0 start
		;;

	*)
		echo "Usage ${0} {start}"
		exit 1
		;;
esac

# End $rc_base/init.d/udev
