#!/bin/bash
_mac1=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $1}'`
_mac2=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $2}'`
_mac3=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $3}'`
_mac4=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $4}'`
_mac5=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $5}'`
_mac6=`ipmitool lan print 1|grep "^MAC Address" |awk '{print $NF}'  |awk -F":" '{print $6}'`
V5_file=`ls JGS_OEM_UCloud_V1.62.ima`
V6_file=`ls F10_JGS_I620G30_P01_BMC_U01_V380.ima`
chmod +x socflash_x64
CV=`ipmitool fru |grep "Chassis Part Number" |awk '{print $NF}'`
BMC_Ver=`ipmitool mc info |grep "Firmware Revision" |awk '{print $NF}'`
SN=`dmidecode -s system-serial-number |sed 's/\s*//g'`
if [[ "$CV =~ V5" ]];then
	ipmitool fru edit 0 field p 3 "Skylake"
	if [[ -z `grep $SN non_upd_sn_list` ]] && [[ "${BMC_Ver}" != "3.80" ]];then
		echo y |./socflash_x64 if=${V6_file}
		sleep 120
	else
		if [[ "${BMC_Ver}" != "1.62" ]];then
			echo "$SN is one of thirty I620-G30 servers that only be updated to BMC 1.62"
			echo y |./socflash_x64 if=${V5_file}
			sleep 120
		fi
	fi
elif [[ "$CV =~ V6" ]];then
	if [[ "${BMC_Ver}" != "3.80" ]];then
		ipmitool fru edit 0 field p 3 "Cascadelake"
		echo y |./socflash_x64 if=${V6_file}
        	sleep 120
	fi
fi
ipmitool raw 0x0c 0x01 0x01 0xc2 0x00
ipmitool raw 0x0c 0x01 0x01 0x05 0x${_mac1} 0x${_mac2} 0x${_mac3} 0x${_mac4} 0x${_mac5} 0x${_mac6}
sleep 30
ipmitool lan set 1 ipsrc dhcp
sleep 3
ipmitool user set name 2 root
sleep 30
ipmitool user set password 2 ucloud.cn
