#!/bin/bash

ipmi_ip=$(ipmitool lan print |grep "IP Address  " |awk -F ": " '{print$2}')
SN=$(dmidecode -s system-serial-number |grep -v ^#  | sed s/[[:space:]]//g)
passwd=$(curl -s -H "Content-Type:application/json" -X POST --data  '{"data":  ["'${SN}'"],"type": "SN"}' http://udcm.ucloudadmin.com/api/ipmi/v1/getpwd/ | jq -r '.[]|.IPMIPassword')
[[ -n $passwd  ]] || exit 1
netmask=$(ipmitool lan print |grep "Subnet Mask" |awk -F ": " '{print$2}')
gateway=$(ipmitool lan print |grep "Default Gateway IP" |awk -F ": " '{print$2}')
AN=`cat /tmp/os_init/cmdb.info |grep  AN|cut -d : -f 2`

BMCupdate(){

echo y | bash inspur_socflash.sh 70800.ima
}

IPMISetting() {
	echo "*** Config IPMI related settings ***"
	if [ $(ipmitool lan print |grep "IP Address Source" |awk -F ": " '{print$2}' |awk -F " " '{print$1}') = "Static" ];then
		echo "IPMI has been set completely"
	elif [ $(ipmitool lan print |grep "Default Gateway IP" |awk -F ": " '{print$2}') = "0.0.0.0" ];then
	        ipmitool lan set 1 ipsrc static
        	ipmitool lan set 1 ipaddr $ipmi_ip
        	ipmitool lan set 1 netmask $netmask
        	ipmitool lan set 1 defgw ipaddr $gateway
	else
		ipmitool lan set 1 ipsrc static
		ipmitool lan set 1 ipaddr $ipmi_ip
	fi
}

USERsetting(){

	ipmitool user set name 1 root 
	ipmitool user set $passwd
}
FRU(){
	ipmitool fru edit 0 field p 5 $AN
}
BMCupdate
IPMISetting
USERsetting
FRU
