#!/bin/sh
#
# eqnx:		Loads and unloads the Equinox SST driver module
#
# chkconfig: 2345 80 20
# description:  This init scripts enables and disables support \
#		for the Equinox SST Multiport Serial Adapters
#

# Variable setup.
MODULE=eqnx
MODULE_KERNEL_PATH="kernel/drivers/char"
MODULE_TITLE="Equinox SST"
KERNEL_VERSION=`uname -r`
MODULE_BASE_PATH="/lib/modules"

# Sanity checks.
if [ ! -f $MODULE_BASE_PATH/$KERNEL_VERSION/$MODULE_KERNEL_PATH/$MODULE.o ];
    then
	echo "Could not locate $MODULE.o in " \
	    "$MODULE_BASE_PATH/$KERNEL_VERSION/$MODULE_KERNEL_PATH" 
	exit 0
fi

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

RETVAL=0

start() {
    echo -n "Loading $MODULE_TITLE module... "
    if ( grep ^$MODULE /proc/modules > /dev/null ) ; then
	action "$MODULE module already loaded" /bin/false; exit
    else
	action "" modprobe $MODULE 
	action "Updating eqnx database... " /usr/bin/ssmkn 
    fi
}

stop() {
   echo -n "Stopping $MODULE_TITLE module... "
   if ( grep ^$MODULE /proc/modules > /dev/null ); then
   	USED=(`grep ^$MODULE /proc/modules`)
	if [ ${USED[2]} -eq 0 ]; then
	    action "" rmmod $MODULE
	else
	    action "$MODULE module is in use." /bin/false
	    echo "Please exit all applictions using the $MODULE_TITLE module."
	    exit 0
	fi
   else
	echo "$MODULE module not loaded"
   fi
}

status() {
    if ( grep ^$MODULE /proc/modules > /dev/null ); then
	echo "$MODULE_TITLE module is loaded"
    else
	echo "$MODULE_TITLE module is not loaded"
    fi
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
        status
        ;;
    restart)
	stop
	start
	;;
    reload)
	stop
	start
	;;
    *)
	echo $"Usage: $0 {start|stop|status|reload|restart}"
	;;
esac
exit $RETVAL
