#!/bin/sh
#
# Startup script for NumLock
#
# description: Locks NumLock key at init runlevel change
# chkconfig: 345 85 15

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

LOCKFILE=/var/lock/subsys/numlock

start()
{
	echo -n "Starting numlock: "
	echo_success
	for tty in /dev/tty[1-8]; do
		setleds -D +num < $tty
	done
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	return $RETVAL
}

stop()
{
	echo -n "Disabling numlocks on ttys: "
	echo_success
	for tty in /dev/tty[1-8]; do
		setleds -D -num < $tty
	done
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
    		if [ -e "$LOCKFILE" ]; then
		    echo "numlock is enabled"
		else
		    echo "numlock is disabled"
		fi
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
