1. #!/bin/bash
  2.  
  3. ARG="/sys/bus/pci/devices/0000:`lspci | grep 3Com | awk '{ print $1 }'`/net:eth1/address"
  4. LOCALMAC=`cat $ARG`
  5.  
  6. ITL=("00:04:76:35:0a:72"
  7. "00:04:76:35:0f:bf"
  8. "00:50:04:35:35:8c"
  9. "00:04:76:35:11:0f"
  10. "00:04:76:35:10:62"
  11. "00:04:76:35:10:94"
  12. "00:04:76:35:0f:6a"
  13. "00:04:76:35:04:20"
  14. "00:04:76:35:11:15"
  15. "00:04:76:35:11:08"
  16. "00:04:76:35:11:0e"
  17. "00:04:76:35:11:13"
  18. "00:04:76:35:0f:b1"
  19. "00:04:76:35:0f:bd"
  20. "00:04:76:35:10:aa"
  21. "00:04:76:35:11:78"
  22. "00:04:76:35:02:1c"
  23. "00:04:76:35:0f:bc"
  24. "00:04:76:35:15:74"
  25. "00:04:76:35:0d:7f"
  26. "00:04:76:35:11:14"
  27. "00:04:76:35:0f:fc"
  28. "00:04:76:35:0a:71"
  29. "00:04:76:b8:30:80"
  30. "00:04:76:35:0f:97"
  31. "00:04:76:35:0a:70"
  32. "00:04:76:35:0a:73"
  33. "00:04:76:35:0f:69")
  34. NUM="0"
  35.  
  36. function create_networking_file {
  37.          echo "NETWORKING=yes" > /etc/sysconfig/network
  38.          echo "HOSTNAME=itl-lab-$NUM" >> /etc/sysconfig/network
  39. }
  40. function update_networking_scripts {
  41.          rm /etc/sysconfig/network-scripts/ifcfg-eth1
  42.          echo "DEVICE=eth1" > /etc/sysconfig/network-scripts/ifcfg-eth1
  43.          echo "BOOTPROTO=dhcp" >> /etc/sysconfig/network-scripts/ifcfg-eth1
  44.          echo "HWADDR=$LOCALMAC" >> /etc/sysconfig/network-scripts/ifcfg-eth1
  45.          echo "DHCP_HOSTNAME=itl-lab-$NUM" >> /etc/sysconfig/network-scripts/ifcfg-eth1
  46.          echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth1
  47. }
  48. function update_etc_hosts {
  49.          echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
  50.          echo "`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` `hostname`" >> /etc/hosts
  51. }
  52. function dhclient_update {
  53.          echo "send host-name \"itl-lab-$NUM\";" > /etc/dhclient-eth1.conf
  54. }
  55.  
  56. echo $LOCALMAC
  57. index=0
  58. while [ $index -lt 29 ]
  59. do
  60.   if [ ${ITL[$index]} == $LOCALMAC ]; then
  61.      echo "itl-lab-$index detected"
  62.      NUM=$index
  63.   fi
  64.  
  65.   let "index = $index + 1"
  66. done
  67.  
  68. let "NUM = $NUM + 1"
  69. create_networking_file
  70. update_networking_scripts
  71. dhclient_update
  72. update_etc_hosts
  73.  
  74. /etc/init.d/network restart