2013-05-13 07:54:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
. /tmp/post-install/variables.txt
|
|
|
|
|
2013-08-20 09:09:46 +00:00
|
|
|
#delete the udev rule in the image
|
|
|
|
rule_file=`ls /etc/udev/rules.d/*net_persistent_names.rules`
|
|
|
|
if [ -n "$rule_file" ];then
|
|
|
|
rm -f $rule_file
|
|
|
|
fi
|
|
|
|
|
2013-05-13 07:54:44 +00:00
|
|
|
hostname $HOSTNAME
|
|
|
|
|
2013-10-14 10:46:53 +00:00
|
|
|
device_name=''
|
|
|
|
str_mac=''
|
|
|
|
for str_temp in `cat /proc/cmdline`;do
|
|
|
|
echo $str_temp | grep -i 'BOOTIF'
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
str_mac=`echo $str_temp | awk -F= '{print $2}' | sed -r 's/^01-//' | tr '-' ':' | tr 'a-z' 'A-Z'`
|
|
|
|
device_name=`ifconfig -a | grep -i $str_mac | awk '{print $1}' | head -n 1`
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$device_name" ];then
|
|
|
|
device_name=$DEVICE
|
|
|
|
str_mac=`ifconfig $device_name|grep -i HWaddr|awk '{print $5}'`
|
|
|
|
fi
|
2013-08-20 09:09:46 +00:00
|
|
|
str_cfg_file=''
|
|
|
|
if [ -d "/etc/sysconfig/network-scripts/" ];then
|
|
|
|
#redhat
|
2013-10-14 10:46:53 +00:00
|
|
|
rm -f /etc/sysconfig/network-scripts/ifcfg-*
|
|
|
|
str_cfg_file="/etc/sysconfig/network-scripts/ifcfg-$device_name"
|
2013-08-23 05:58:53 +00:00
|
|
|
sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /etc/sysconfig/network
|
2013-10-14 10:46:53 +00:00
|
|
|
echo "DEVICE=\"$device_name\"" > $str_cfg_file
|
|
|
|
echo "BOOTPROTO=\"dhcp\"" >> $str_cfg_file
|
|
|
|
echo "NM_CONTROLLED=\"yes\"" >> $str_cfg_file
|
|
|
|
echo "HWADDR=$str_mac" >> $str_cfg_file
|
|
|
|
echo "ONBOOT=\"yes\"" >> $str_cfg_file
|
2013-08-20 09:09:46 +00:00
|
|
|
elif [ -d "/etc/sysconfig/network/" ];then
|
|
|
|
#suse
|
2013-10-14 10:46:53 +00:00
|
|
|
rm -f /etc/sysconfig/network/ifcfg-*
|
|
|
|
str_cfg_file="/etc/sysconfig/network/ifcfg-$device_name"
|
2013-08-23 05:58:53 +00:00
|
|
|
echo "$HOSTNAME" > /etc/HOSTNAME
|
2013-10-14 10:46:53 +00:00
|
|
|
echo "DEVICE=\"$device_name\"" > $str_cfg_file
|
|
|
|
echo "HWADDR=$str_mac" >> $str_cfg_file
|
|
|
|
echo "BOOTPROTO=dhcp" >> $str_cfg_file
|
|
|
|
echo "STARTMODE=onboot" >> $str_cfg_file
|
|
|
|
echo "DHCLIENT_PRIMARY_DEVICE=yes" >> $str_cfg_file
|
2013-08-20 09:09:46 +00:00
|
|
|
else
|
|
|
|
#ubuntu
|
2013-08-27 03:16:47 +00:00
|
|
|
echo "Does not support ubuntu."
|
|
|
|
exit 1
|
2013-08-20 09:09:46 +00:00
|
|
|
fi
|
|
|
|
|