#!/usr/bin/bash
# 
# Bring up/down hiroce
#
# chkconfig: 2345 05 95
# description: Activates/Deactivates hiroce Driver to \
#              start at boot time.
#

modprobe=/sbin/modprobe

load_module()
{
    local module=$1
    filename=`modinfo $module 2>/dev/null | grep filename | awk '{print $NF}'`

    if [ ! -n "$filename" ]; then
        echo "Module $module does not exist"
        return 1
    fi

    ${modprobe} $module >/dev/null 2>&1
}

rm_mod()
{
    local mod=$1
    shift

    unload_log=`/sbin/rmmod $mod 2>&1`
    if [ $? -ne 0 ]; then
        echo $"Unloading $mod"
        if [ ! -z "${unload_log}" ]; then
            echo $unload_log
        fi
        # get_debug_info
        [ ! -z $2 ] && echo $2
        exit 1
    fi
}

start()
{
    local RC=0
    
    load_module hiroce
    my_rc=$?
    if [ $my_rc -ne 0 ]; then
            echo $"Loading hiroce driver: "
    fi
    RC=$[ $RC + $my_rc ]
}

stop()
{
    rm_mod hiroce
}

case $1 in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        status)
                status
                ;;
        *)
                echo
                echo "Usage: `basename $0` {start|stop|restart|status}"
                echo
                exit 1
                ;;
esac

RC=$?
exit $RC
