2014-04-26 22:29:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-05-12 12:08:31 +00:00
|
|
|
# SI post-install script to configure network settings after SI has installed the OS
|
|
|
|
# SI post-install scripts run in a chroot environment of the final OS image
|
2014-04-26 22:29:01 +00:00
|
|
|
|
|
|
|
. /tmp/post-install/variables.txt
|
|
|
|
|
2014-05-12 12:08:31 +00:00
|
|
|
bondingopts='mode=4 miimon=100 downdelay=0 updelay=0 lacp_rate=fast xmit_hash_policy=1'
|
|
|
|
|
2014-04-26 22:29:01 +00:00
|
|
|
# determine if we should be using a static ip or dhcp
|
|
|
|
staticIP () {
|
|
|
|
# Eventually we should use the SI variable IP_ASSIGNMENT_METHOD below to determine this.
|
|
|
|
# But this requires a patch in both xcat/sysclone (to set si_getimage -ip-assignment method)
|
|
|
|
# and SI (to set IP_ASSIGNMENT_METHOD as a result of that). Until both of those patches
|
|
|
|
# are in the main releases, assume that if we have set the IPADDR kernel parm for the boot
|
|
|
|
# kernel to use static ip, that the final OS should use static ip too.
|
|
|
|
# Note: the IPADDR environment variable will be set by SI, even if it got it thru dhcp, so
|
|
|
|
# that is not a reliable way to decide.
|
|
|
|
str=`cat /proc/cmdline`
|
|
|
|
#str='netmask=255.255.255.192 IPADDR=10.54.51.11 GATEWAY=10.54.51.1 dns=10.54.51.2 hostname=sap64-4 DEVICE=eth0'
|
|
|
|
for parm in $str; do
|
|
|
|
key=`echo $parm|awk -F= '{print $1}'`
|
|
|
|
value=`echo $parm|awk -F= '{print $2}'`
|
|
|
|
if [[ $key == "IPADDR" || $key == "ipaddr" ]]; then
|
|
|
|
return 0 # yes, we should use static ip
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ -n $IP_ASSIGNMENT_METHOD && ${IP_ASSIGNMENT_METHOD,,} == "static" ]]; then
|
|
|
|
return 0 # this means yes/true
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
#delete the udev rule in the image
|
|
|
|
rule_file=`ls /etc/udev/rules.d/*net_persistent_names.rules 2>/dev/null`
|
|
|
|
if [ -n "$rule_file" ];then
|
|
|
|
rm -f $rule_file
|
|
|
|
fi
|
|
|
|
|
|
|
|
hostname $HOSTNAME
|
2014-05-12 12:08:31 +00:00
|
|
|
bond=bond0
|
2014-05-24 09:46:14 +00:00
|
|
|
if [[ $DEVICE == "eth0" ]]; then
|
|
|
|
$DEVICE2=eth2
|
|
|
|
fi
|
2014-04-26 22:29:01 +00:00
|
|
|
|
|
|
|
device_names=`ifconfig -a | grep -i hwaddr | grep -i 'Ethernet' | grep -v usb| awk '{print $1}'`
|
|
|
|
str_cfg_file=''
|
|
|
|
if [ -d "/etc/sysconfig/network-scripts/" ];then
|
|
|
|
#redhat
|
2014-05-12 12:08:31 +00:00
|
|
|
dir="/etc/sysconfig/network-scripts"
|
2014-04-26 22:29:01 +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
|
|
|
|
if staticIP; then
|
2014-05-12 12:08:31 +00:00
|
|
|
# delete all nic cfg files left over from the golden node
|
|
|
|
for i in $device_names;do
|
|
|
|
rm -f "$dir/ifcfg-$i"
|
|
|
|
done
|
|
|
|
|
2014-04-26 22:29:01 +00:00
|
|
|
# set static ip from variables in variables.txt
|
2014-05-12 12:08:31 +00:00
|
|
|
# write ifcfg-bond0. For now we assume the installnic should be part of bond0,
|
|
|
|
# because in SL i think that is always the case.
|
|
|
|
i="$bond"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "DEVICE=$i" > $str_cfg_file
|
2014-05-12 12:08:31 +00:00
|
|
|
echo "BOOTPROTO=none" >> $str_cfg_file
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "ONBOOT=yes" >> $str_cfg_file
|
2014-05-12 12:08:31 +00:00
|
|
|
echo "USERCTL=no" >> $str_cfg_file
|
|
|
|
echo 'BONDING_OPTS="'$bondingopts'"' >> $str_cfg_file
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "IPADDR=$IPADDR" >> $str_cfg_file
|
|
|
|
echo "NETMASK=$NETMASK" >> $str_cfg_file
|
|
|
|
echo "NETWORK=$NETWORK" >> $str_cfg_file
|
|
|
|
echo "BROADCAST=$BROADCAST" >> $str_cfg_file
|
|
|
|
#todo: add gateway config? Not sure, because the boot kernels gateway might not be the final OS gateway
|
2014-05-12 12:08:31 +00:00
|
|
|
|
|
|
|
# write ifcfg-eth0
|
|
|
|
i="$DEVICE"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
|
|
|
echo "DEVICE=$i" > $str_cfg_file
|
|
|
|
echo "BOOTPROTO=none" >> $str_cfg_file
|
|
|
|
echo "MASTER=$bond" >> $str_cfg_file
|
|
|
|
echo "ONBOOT=yes" >> $str_cfg_file
|
|
|
|
echo "SLAVE=yes" >> $str_cfg_file
|
|
|
|
echo "USERCTL=no" >> $str_cfg_file
|
|
|
|
|
2014-05-24 09:46:14 +00:00
|
|
|
if [[ $DEVICE2 != "" ]]; then
|
|
|
|
# write ifcfg-eth0
|
|
|
|
i="$DEVICE2"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
|
|
|
echo "DEVICE=$i" > $str_cfg_file
|
|
|
|
echo "BOOTPROTO=none" >> $str_cfg_file
|
|
|
|
echo "MASTER=$bond" >> $str_cfg_file
|
|
|
|
echo "ONBOOT=yes" >> $str_cfg_file
|
|
|
|
echo "SLAVE=yes" >> $str_cfg_file
|
|
|
|
echo "USERCTL=no" >> $str_cfg_file
|
|
|
|
fi
|
|
|
|
|
2014-05-12 12:08:31 +00:00
|
|
|
# write modprobe alias config
|
|
|
|
str_cfg_file="/etc/modprobe.d/$bond.conf"
|
|
|
|
echo "alias $bond bonding" > $str_cfg_file
|
2014-05-24 09:46:14 +00:00
|
|
|
|
|
|
|
#todo: figure out how to set the default gateway in rhel
|
2014-04-26 22:29:01 +00:00
|
|
|
else
|
|
|
|
# use dhcp for all nics
|
|
|
|
for i in $device_names;do
|
2014-05-12 12:08:31 +00:00
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
2014-04-26 22:29:01 +00:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
elif [ -d "/etc/sysconfig/network/" ];then
|
|
|
|
#suse
|
2014-05-12 12:08:31 +00:00
|
|
|
dir="/etc/sysconfig/network"
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "$HOSTNAME" > /etc/HOSTNAME
|
|
|
|
if staticIP; then
|
2014-05-12 12:08:31 +00:00
|
|
|
# delete all nic cfg files left over from the golden node
|
|
|
|
for i in $device_names;do
|
|
|
|
rm -f "$dir/ifcfg-$i"
|
|
|
|
done
|
|
|
|
|
2014-04-26 22:29:01 +00:00
|
|
|
# set static ip from variables in variables.txt
|
2014-05-12 12:08:31 +00:00
|
|
|
# write ifcfg-bond0. For now we assume the installnic should be part of bond0,
|
|
|
|
# because in SL i think that is always the case.
|
|
|
|
i="$bond"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
|
|
|
echo "BOOTPROTO=static" > $str_cfg_file
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "STARTMODE=onboot" >> $str_cfg_file
|
2014-05-12 12:08:31 +00:00
|
|
|
echo "BONDING_MASTER=yes" >> $str_cfg_file
|
|
|
|
echo "BONDING_MODULE_OPTS='$bondingopts'" >> $str_cfg_file
|
|
|
|
echo "NAME='Bonded Interface'" >> $str_cfg_file
|
2014-04-26 22:29:01 +00:00
|
|
|
echo "IPADDR=$IPADDR" >> $str_cfg_file
|
|
|
|
echo "NETMASK=$NETMASK" >> $str_cfg_file
|
|
|
|
echo "NETWORK=$NETWORK" >> $str_cfg_file
|
|
|
|
echo "BROADCAST=$BROADCAST" >> $str_cfg_file
|
2014-05-12 12:08:31 +00:00
|
|
|
echo "USERCONTROL=no" >> $str_cfg_file
|
|
|
|
echo "BONDING_SLAVE_0=$DEVICE" >> $str_cfg_file
|
2014-05-24 09:46:14 +00:00
|
|
|
if [[ $DEVICE2 != "" ]]; then
|
|
|
|
echo "BONDING_SLAVE_1=$DEVICE2" >> $str_cfg_file
|
|
|
|
fi
|
2014-05-12 12:08:31 +00:00
|
|
|
|
|
|
|
# write ifcfg-eth0
|
|
|
|
i="$DEVICE"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
|
|
|
echo "BOOTPROTO=none" > $str_cfg_file
|
|
|
|
echo "STARTMODE=hotplug" >> $str_cfg_file
|
|
|
|
|
2014-05-24 09:46:14 +00:00
|
|
|
if [[ $DEVICE2 != "" ]]; then
|
|
|
|
# write ifcfg-eth2
|
|
|
|
i="$DEVICE2"
|
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
|
|
|
echo "BOOTPROTO=none" > $str_cfg_file
|
|
|
|
echo "STARTMODE=hotplug" >> $str_cfg_file
|
|
|
|
fi
|
|
|
|
|
2014-05-12 12:08:31 +00:00
|
|
|
# write modprobe alias config
|
|
|
|
str_cfg_file="/etc/modprobe.d/$bond.conf"
|
|
|
|
echo "alias $bond bonding" > $str_cfg_file
|
|
|
|
|
2014-05-24 09:46:14 +00:00
|
|
|
# set the default gateway (at this point this is the private nic gateway, to handle provision across vlans)
|
|
|
|
file=/etc/sysconfig/network/routes
|
|
|
|
if grep -q -E '^default ' $file; then
|
|
|
|
# replace the default route that is already in there
|
|
|
|
sed -i 's/^default .*$/default '$GATEWAY' - -/' $file
|
|
|
|
else
|
|
|
|
# no default route yet, append to file
|
|
|
|
echo "default $GATEWAY - -" >>$file
|
|
|
|
fi
|
|
|
|
|
2014-05-12 12:08:31 +00:00
|
|
|
# this was the original config of the eth0 nic (without bonding)
|
|
|
|
#echo "DEVICE=$i" > $str_cfg_file
|
|
|
|
#echo "BOOTPROTO=static" >> $str_cfg_file
|
|
|
|
#echo "STARTMODE=onboot" >> $str_cfg_file
|
|
|
|
#echo "IPADDR=$IPADDR" >> $str_cfg_file
|
|
|
|
#echo "NETMASK=$NETMASK" >> $str_cfg_file
|
|
|
|
#echo "NETWORK=$NETWORK" >> $str_cfg_file
|
|
|
|
#echo "BROADCAST=$BROADCAST" >> $str_cfg_file
|
2014-04-26 22:29:01 +00:00
|
|
|
#todo: add gateway config? Not sure, because the boot kernels gateway might not be the final OS gateway
|
|
|
|
else
|
|
|
|
# use dhcp for all nics
|
|
|
|
for i in $device_names;do
|
2014-05-12 12:08:31 +00:00
|
|
|
str_cfg_file="$dir/ifcfg-$i"
|
2014-04-26 22:29:01 +00:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#ubuntu
|
|
|
|
echo "Does not support ubuntu."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|