#! /bin/bash
#
# bridge       Bring up/down bridge interface
#
# chkconfig: 2345 21 90
# description: Activates/Deactivates bridge interfaces configured to \
#              start at boot time.
# probe: true

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

if [ ! -f /etc/sysconfig/network ]; then
    exit 0
fi

. /etc/sysconfig/network

if [ -f /etc/sysconfig/pcmcia ]; then
	. /etc/sysconfig/pcmcia
fi


# Check that networking is up.
[ "${BRIDGE}" = "no" ] && exit 0

case "$1" in
  start)
        /sbin/brctl addbr br0
        for i in `echo ${BRIDGEIF} | tr , \\\n`; do
          while [ `/sbin/brctl addif br0 $i` ]; do
		sleep 1
	  done
        done
        for i in `echo ${BRIDGEIF} | tr , \\\n`; do
          /sbin/ifconfig $i 0.0.0.0
        done
	sleep 5
        ;;
  stop)
	/sbin/ifdown br0
        for i in `echo ${BRIDGEIF} | tr , \\\n`; do
          /sbin/brctl delif br0 $i
	done
        /sbin/brctl delbr br0
        ;;
  restart)
        cd $CWD
	$0 stop
	$0 start
	;;
  status)
	/sbin/brctl show
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0
