#!/bin/sh
#
# kudzu		This scripts runs the kudzu hardware probe.
#
# chkconfig: 345 05 95
# description: 	This runs the hardware probe, and optionally configures \
#		changed hardware.

# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=$?

case "$1" in
 start)
	echo -n "Checking for new hardware"

        # Have a 30 second timeout.
 	/usr/sbin/kudzu -t 30
	RETVAL=$?
	if [ "$RETVAL" -eq 0 ]; then
  	   action "" /bin/true
	else
	   action "" /bin/false
           if [ "$RETVAL" -eq 5 ]; then
	       echo "Hardware configuration timed out."
	       echo "Run '/usr/sbin/kudzu' from the command line to re-detect."
	       initlog -n kudzu -s "Hardware configuration timed out."
	       initlog -n kudzu -s "Run '/usr/sbin/kudzu' from the command line to re-detect."
	   fi
	fi
	# We don't want to run this on random runlevel changes.
	touch /var/lock/subsys/kudzu
	# However, if they did configure X and want runlevel 5, let's
	# switch to it...
	if [ -f /tmp/ranXconfig ]; then
	    grep -q "^id:5:initdefault:" /etc/inittab && telinit 5
	fi
	;;
 stop)
 	rm -f /var/lock/subsys/kudzu
 	;;
 *)
 	echo "Usage: kudzu {start|stop}"
	exit 1
	;;
esac

exit $RETVAL
