#!/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

echo "$IPMI_IP bmc fw update"
bash urest -H ${IPMI_IP} -U root -P ${IPMI_pw} upgradefw -F 2288H_V5_2288C_V5_5288_V5-iBMC-V506.hpm
