From: Konrad Rzeszutek Wilk Date: Tue, 24 Jan 2012 04:30:15 +0000 (-0500) Subject: network-startup: make the bridge and interfaces config setup into functions. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d42432f97b1a698eead3004ad20174b315ac92fe;p=xentesttools%2Fbootstrap.git network-startup: make the bridge and interfaces config setup into functions. Signed-off-by: Konrad Rzeszutek Wilk --- diff --git a/root_image/etc/init.d/primary_network b/root_image/etc/init.d/primary_network index 8f2a057..f3b1694 100755 --- a/root_image/etc/init.d/primary_network +++ b/root_image/etc/init.d/primary_network @@ -1,38 +1,48 @@ #!/bin/bash -mkdir -p /etc/sysconfig -echo "NETWORKING=yes" > /etc/sysconfig/network +function create_bridge() { + + local name=$1 + FILE=/etc/sysconfig/network-scripts/ifcfg-$name + echo "DEVICE=$name" > $FILE + echo "TYPE=Bridge" >> $FILE + echo "BOOTPROTO=dhcp" >> $FILE + echo "ONBOOT=yes" >> $FILE -FILE=/etc/sysconfig/network-scripts/ifcfg-switch -echo "DEVICE=switch" > $FILE -echo "TYPE=Bridge" >> $FILE -echo "BOOTPROTO=dhcp" >> $FILE -echo "ONBOOT=yes" >> $FILE +} +function create_bridge_if() { -# Create the /etc/sysconfig/network-scripts/ifcfg-$ -NIC=eth0 -FILE=/etc/sysconfig/network-scripts/ifcfg-$NIC -echo "DEVICE=$NIC" > $FILE -echo "ONBOOT=yes" >> $FILE -echo "BRIDGE=switch" >> $FILE + local name=$1 + create_bridge $name -COUNT=0 -NICS=`ls -1 /sys/class/net/ | grep -v lo | grep -v sit` -# The rest -for NIC in $NICS -do - if [ "$NIC" == "eth0" ]; then - continue; - fi + # Create the /etc/sysconfig/network-scripts/ifcfg-$ + NIC=eth0 FILE=/etc/sysconfig/network-scripts/ifcfg-$NIC echo "DEVICE=$NIC" > $FILE echo "ONBOOT=yes" >> $FILE - echo "BOOTPROTO=dhcp" >> $FILE - COUNT=$(($COUNT+1)) - # We only want at max two DHCP interfaces. - if [ $COUNT -ge 1 ]; then - break; - fi -done + echo "BRIDGE=$name" >> $FILE + + COUNT=0 + NICS=`ls -1 /sys/class/net/ | grep -v lo | grep -v sit` + # The rest + for NIC in $NICS + do + if [ "$NIC" == "eth0" ]; then + continue; + fi + FILE=/etc/sysconfig/network-scripts/ifcfg-$NIC + echo "DEVICE=$NIC" > $FILE + echo "ONBOOT=yes" >> $FILE + echo "BOOTPROTO=dhcp" >> $FILE + COUNT=$(($COUNT+1)) + # We only want at max two DHCP interfaces. + if [ $COUNT -ge 1 ]; then + break; + fi + done +} +mkdir -p /etc/sysconfig +echo "NETWORKING=yes" > /etc/sysconfig/network +create_bridge_if switch /etc/init.d/network start