#!/bin/sh
#
# Copyright(c) 2000-2003 Broadcom Corporation, all rights reserved
#
# Name:     basp - Broadcom Advanced Server Program init script
#           This script is part of Broadcom Advanced Server Program (BASP)
#           driver for Linux.
#
# Author:   Frankie Fan
#
# Updated:  April 12, 2002
#

# Tags 
# chkconfig: 2345 11 89
# description: Activates/Deactivates team configurations for load-balancing, \
#              failover and VLAN.

PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "$1" in
    start)
        ;;
    stop)
        ;;
    *)
        echo Broadcom Advanced Server Program \(BASP\) init script
        echo Copyright \(c\) 2000-2003 Broadcom Corporation
        echo usage: basp \[start\|stop\]
        exit 1
        ;;
esac

#
# support_action is defined for following distributions
#	0	generic
#	1	RedHat
#	2	Suse
#
# load the functions
if [ -d /usr/src/redhat -a -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
    support_action=1
elif [ -f /etc/rc.status ]; then
    . /etc/rc.status
    support_action=2
else
    support_action=0
fi


#
# function stub
#
myaction() 
{
    if [ $support_action -eq 1 ]; then
        MYACTION=$1
        shift
        action "$MYACTION" $*
    elif [ $support_action -eq 2 ]; then
        MYMSG=$1
	shift
	$*
	rc=$?
        echo -n $MYMSG
        rc_status -v
    else
        echo -n $1
        shift
	$*
	rc=$?
        if [ $rc -eq 0 ]; then
            echo "  [  OK  ]"
        else
            echo "  [FAILED]"
        fi
    fi
    return $rc
}


#
# pre-start the team
#
pre_start()
{
    if [ $support_action -eq 2 ]; then
        myaction "Bringing up physical network interfaces:" ./baspif $1 prestart
    fi
}


# load the driver
modprobe basp

# change to our script directory
[ -d /etc/basp ] || exit 1
CWD=`pwd`
cd /etc/basp

# see if there is any team
ls team-* >/dev/null 2>/dev/null
if [ $? -eq 0 ] ; then
    for this_team in team-* ; do
        name=`echo $this_team | sed 's/^team-//g'`
        case "$1" in
            start)
                pre_start $this_team
                myaction "Adding BASP team $name:" ./baspteam $this_team add
                if [ $? -eq 0 ]; then
                    myaction "Starting BASP team $name:" ./baspif $this_team start
                fi
                touch /var/lock/subsys/basp
                ;;

            stop)
                myaction "Stopping BASP team $name:" ./baspif $this_team stop
                if [ $? -eq 0 ]; then
                    myaction "Removing BASP team $name:" ./baspteam $this_team del
                fi
                rm -f /var/lock/subsys/basp
                ;;
        esac
    done
fi

# go back to where we're started
cd $CWD


