2013-05-14 02:47:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
. /tmp/post-install/variables.txt
|
|
|
|
|
2013-08-20 09:12:07 +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-14 02:47:44 +00:00
|
|
|
hostname $HOSTNAME
|
|
|
|
|
2013-10-16 15:44:06 +00:00
|
|
|
#write the config files, the device name may change after reboot
|
|
|
|
#so use the dhcp for all interface
|
2014-05-27 17:04:44 +00:00
|
|
|
#device_names=`ifconfig -a | grep -i hwaddr | grep -i 'Ethernet' | grep -v usb| awk '{print $1}'`
|
|
|
|
device_names=`ip link |grep "BROADCAST" |awk '{print $2}' | sed s/://`
|
2013-08-20 09:12:07 +00:00
|
|
|
str_cfg_file=''
|
|
|
|
if [ -d "/etc/sysconfig/network-scripts/" ];then
|
|
|
|
#redhat
|
2014-05-28 14:27:41 +00:00
|
|
|
if [ -f "/etc/hostname" ]; then #RH7
|
|
|
|
echo $HOSTNAME > /etc/hostname
|
2013-10-14 11:30:43 +00:00
|
|
|
else
|
2014-05-28 14:27:41 +00:00
|
|
|
grep -i HOSTNAME /etc/sysconfig/network
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /etc/sysconfig/network
|
|
|
|
else
|
|
|
|
echo "HOSTNAME=$HOSTNAME" >> /etc/sysconfig/network
|
|
|
|
fi
|
2013-10-14 11:30:43 +00:00
|
|
|
fi
|
2013-10-16 15:44:06 +00:00
|
|
|
for i in $device_names;do
|
|
|
|
str_cfg_file="/etc/sysconfig/network-scripts/ifcfg-$i"
|
|
|
|
echo "DEVICE=$i" > $str_cfg_file
|
|
|
|
echo "BOOTPROTO=dhcp" >> $str_cfg_file
|
|
|
|
echo "NM_CONTROLLED=yes" >> $str_cfg_file
|
|
|
|
echo "ONBOOT=yes" >> $str_cfg_file
|
|
|
|
done
|
2013-08-20 09:12:07 +00:00
|
|
|
elif [ -d "/etc/sysconfig/network/" ];then
|
|
|
|
#suse
|
2013-08-23 06:00:08 +00:00
|
|
|
echo "$HOSTNAME" > /etc/HOSTNAME
|
2013-10-16 15:44:06 +00:00
|
|
|
for i in $device_names;do
|
|
|
|
str_cfg_file="/etc/sysconfig/network/ifcfg-$i"
|
|
|
|
echo "DEVICE=$i" > $str_cfg_file
|
|
|
|
echo "BOOTPROTO=dhcp" >> $str_cfg_file
|
|
|
|
echo "STARTMODE=onboot" >> $str_cfg_file
|
|
|
|
echo "DHCLIENT_PRIMARY_DEVICE=yes" >> $str_cfg_file
|
|
|
|
done
|
2013-08-20 09:12:07 +00:00
|
|
|
else
|
|
|
|
#ubuntu
|
2013-08-27 03:55:11 +00:00
|
|
|
echo "Does not support ubuntu."
|
|
|
|
exit 1
|
2013-08-20 09:12:07 +00:00
|
|
|
fi
|
|
|
|
|