#!/bin/sh
#
# bridge	Start bridge from some interfaces
#
# chkconfig: 345 11 88
# description: (re)start/stop bridge. WARNING: stop/restart/reload... will execute "service network restart"!!!
# config: /etc/sysconfig/bridge

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions
SourceIfNotEmpty /etc/sysconfig/bridge

BRCTL=/sbin/brctl
IFCONF=/sbin/ifconfig

start()
{
    $BRCTL addbr $BRNAME
    for iface in $IFACES; do
        $BRCTL addif $BRNAME $iface
    done
    for iface in $IFACES; do
        $IFCONF $iface 0.0.0.0
    done
    echo "$BRADDR"|grep -E "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" >/dev/null 2>&1 && $IFCONF $BRNAME $BRADDR
}

stop()
{
    /etc/rc.d/init.d/network stop
    for iface in $IFACES; do
        $BRCTL delif $BRNAME $iface
    done
    $IFCONF $BRNAME down
    $BRCTL delbr $BRNAME
    /etc/rc.d/init.d/network start
}

restart()
{
	stop
	start
}

reload()
{
    restart
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ $BRCTL show|grep -E "^br[0-9]+" >/dev/null 2>&1 ]; then
			stop
		fi
		;;
	condrestart)
		if [ $BRCTL show|grep -E "^br[0-9]+" >/dev/null 2>&1 ]; then
			restart
		fi
		;;
	condreload)
		if [ $BRCTL show|grep -E "^br[0-9]+" >/dev/null 2>&1 ]; then
			reload
		fi
		;;
	status)
		$BRCTL show
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
