#!/bin/bash
# Script to run ifled in the background.
# ifled will probably die without stop script.
# Taken from dutch version of ifled by Myckel Habets myckel@daxis.nl
# Modified to work on Mandrake/RedHat by Max Heijndijk <cchq@wanadoo.nl>

# /etc/rc.d/init.d/ifled
# chkconfig: 2345 95 05
# description: Monitor network traffic with the keyboard LED's.

if [ -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
else
    exit 0
fi

[ -f /etc/sysconfig/ifled ] && . /etc/sysconfig/ifled

case "$1" in

  start) if [ ! -z "$IF1" ] && /sbin/ifconfig | grep -q "$IF1" ; then
	    action "Starting InterfaceLED (\"$IF1\" on NumLock):" \
	    /usr/bin/ifled console "$IF1" -f -c ann
	 fi

	 if [ ! -z "$IF2" ] && /sbin/ifconfig | grep -q "$IF2" ; then
	    action "Starting InterfaceLED (\"$IF2\" on CapsLock):" \
	    /usr/bin/ifled console "$IF2" -f -c nan
	 fi

	 if [ ! -z "$IF3" ] && /sbin/ifconfig | grep -q "$IF3" ; then
	    action "Starting InterfaceLED (\"$IF3\" on ScrollLock):" \
	    /usr/bin/ifled console "$IF3" -f -c nna
	 fi
	
	 touch /var/lock/subsys/ifled
	 ;;

  stop)  action "Stopping InterfaceLED:" \
	 echo && killall ifled
	 reset

	 rm -f /var/lock/subsys/ifled
         ;;

  *)	 echo "Usage: /etc/rc.d/init.d/ifled {start|stop}" >&2
	 exit 1
	 ;;
esac

exit 0
