#!/bin/bash
ARG="/sys/bus/pci/devices/0000:`lspci | grep 3Com | awk '{ print $1 }'`/net:eth1/address"
LOCALMAC=`cat $ARG`
ITL=("00:04:76:35:0a:72"
"00:04:76:35:0f:bf"
"00:50:04:35:35:8c"
"00:04:76:35:11:0f"
"00:04:76:35:10:62"
"00:04:76:35:10:94"
"00:04:76:35:0f:6a"
"00:04:76:35:04:20"
"00:04:76:35:11:15"
"00:04:76:35:11:08"
"00:04:76:35:11:0e"
"00:04:76:35:11:13"
"00:04:76:35:0f:b1"
"00:04:76:35:0f:bd"
"00:04:76:35:10:aa"
"00:04:76:35:11:78"
"00:04:76:35:02:1c"
"00:04:76:35:0f:bc"
"00:04:76:35:15:74"
"00:04:76:35:0d:7f"
"00:04:76:35:11:14"
"00:04:76:35:0f:fc"
"00:04:76:35:0a:71"
"00:04:76:b8:30:80"
"00:04:76:35:0f:97"
"00:04:76:35:0a:70"
"00:04:76:35:0a:73"
"00:04:76:35:0f:69")
NUM="0"
function create_networking_file {
echo "NETWORKING=yes" > /etc/sysconfig/network
echo "HOSTNAME=itl-lab-$NUM" >> /etc/sysconfig/network
}
function update_networking_scripts {
rm /etc/sysconfig/network-scripts/ifcfg-eth1
echo "DEVICE=eth1" > /etc/sysconfig/network-scripts/ifcfg-eth1
echo "BOOTPROTO=dhcp" >> /etc/sysconfig/network-scripts/ifcfg-eth1
echo "HWADDR=$LOCALMAC" >> /etc/sysconfig/network-scripts/ifcfg-eth1
echo "DHCP_HOSTNAME=itl-lab-$NUM" >> /etc/sysconfig/network-scripts/ifcfg-eth1
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth1
}
function update_etc_hosts {
echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
echo "`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` `hostname`" >> /etc/hosts
}
function dhclient_update {
echo "send host-name \"itl-lab-$NUM\";" > /etc/dhclient-eth1.conf
}
echo $LOCALMAC
index=0
while [ $index -lt 29 ]
do
if [ ${ITL[$index]} == $LOCALMAC ]; then
echo "itl-lab-$index detected"
NUM=$index
fi
let "index = $index + 1"
done
let "NUM = $NUM + 1"
create_networking_file
update_networking_scripts
dhclient_update
update_etc_hosts
/etc/init.d/network restart