#!/bin/bash

function fun_br_setting {
	br_conf="/usr/local/bin/network_initialization.sh"
	echo "br_conf--${br_conf}"

	#service network restart
	echo '#!/bin/sh' > ${br_conf}
	echo "---------------------------------------------------"
	IFNAMES=
	let ind=0
	##DEVICE=( `ip r | grep kernel |  awk '{ print $3;}'` )
	readarray -t DEVICE < <(ip r | grep scope | awk '{ print $3; }')
	for ifdev in  ${DEVICE[@]}
	do
		IFNAMES="${IFNAMES} ${ifdev}"
		macaddr=$(ip address show ${ifdev}| grep link/ether | cut -d' ' -f 6|sed 's| ||g')
		echo '' >> ${br_conf}
		echo "ip link add name br${ind} type bridge" >> ${br_conf}
		echo "ip link set br${ind}  address ${macaddr}" >> ${br_conf}
		echo "ip link set ${ifdev} master br${ind}" >> ${br_conf}
		echo '' >> ${br_conf}
		echo "ip link set br${ind} up" >> ${br_conf}
		echo "ip link set ${ifdev} up" >> ${br_conf}
		echo "ip address flush dev ${ifdev}" >> ${br_conf}
		echo '' >> ${br_conf}
		echo "dhclient br${ind}" >> ${br_conf}
		let ind=ind+1
	done
	chmod +x ${br_conf}
}
echo "---------------------------------------------------"

