#!/bin/bash

IPMI_IP=`ipmitool  lan print 1 | grep "IP Address  "| awk '{print $NF}'`
if [ "${IPMI_IP}" != "0.0.0.0" ]; then
	SN=$(dmidecode -s system-serial-number |grep -v ^#  | sed s/[[:space:]]//g)
	IPMI_pw=$(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 $IPMI_pw  ]] || exit 1

fi
if [ "${IPMI_pw}" == "" ]; then
        IPMI_pw="ucloud.cn"
fi

ipmitool -I lanplus -H ${IPMI_IP} -U root -P ${IPMI_pw} raw 0x30 0x93 0xdb 0x07 0x00 0x0F 0x02 0x01 0 0 1 1

echo "$IPMI_IP bios fw update"
bash urest -H ${IPMI_IP} -U root -P ${IPMI_pw} upgradefw -F biosimage.hpm
sleep 10
