#!/bin/bash
# Author: Ryan Lewis
# God
# Date: Wed Mar 01, 2006
# hostname-change: looks up the mac address for a computer and
# changes the hostname appropreately.
LOCALMAC=`grep eth0 /var/log/dmesg | grep Ethernet | awk -F' ' '{print $10}'`
COSI1="00:11:25:f6:70:7a"
COSI2="00:11:25:f6:5d:7c"
COSI3="00:11:25:f6:5b:2e"
COSI4="00:11:25:f6:5d:c9"
COSI5="00:11:25:f6:15:22"
COSI6="00:11:25:f6:5c:13"
COSI7="00:11:25:f6:52:95"
COSI8="00:11:25:f6:67:9c"
COSI9="00:11:25:f6:70:8c"
COSI10="00:11:25:f6:2f:c1"
NUM="0"
function create_networking_file {
echo "NETWORKING=yes" > /etc/sysconfig/network
echo "HOSTNAME=cosi-lab-$NUM" >> /etc/sysconfig/network
}
function update_networking_scripts {
rm /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0
echo "BOOTPROTO=dhcp" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "HWADDR=$LOCALMAC" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DHCP_HOSTNAME=cosi-lab-$NUM" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0
}
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 \"cosi-lab-$NUM\";" > /etc/dhclient-eth0.conf
}
if [ $COSI1 == $LOCALMAC ]; then
echo "cosi-lab-1 detected"
NUM="1"
fi
if [ $COSI2 == $LOCALMAC ]; then
echo "cosi-lab-2 detected"
NUM="2"
fi
if [ $COSI3 == $LOCALMAC ]; then
echo "cosi-lab-3 detected"
NUM="3"
fi
if [ $COSI4 == $LOCALMAC ]; then
echo "co-lab-4 detected"
NUM="4"
fi
if [ $COSI5 == $LOCALMAC ]; then
echo "cosi-lab-5 detected"
NUM="5"
fi
if [ $COSI6 == $LOCALMAC ]; then
echo "cosi-lab-6 detected"
NUM="6"
fi
if [ $COSI7 == $LOCALMAC ]; then
echo "cosi-lab-7 detected"
NUM="7"
fi
if [ $COSI8 == $LOCALMAC ]; then
echo "cosi-lab-8 detected"
NUM="8"
fi
if [ $COSI9 == $LOCALMAC ]; then
echo "cosi-lab-9 detected"
NUM="9"
fi
if [ $COSI10 == $LOCALMAC ]; then
echo "cosi-lab-10 detected"
NUM="10"
fi
create_networking_file
update_networking_scripts
dhclient_update
update_etc_hosts
/etc/init.d/network restart