#!/bin/bash

ManufactureType=`ipmitool fru list 0|grep  "Product Name"|cut -d ":" -f 2|sed "s/.//"`
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=$3
	[[ -n $IPMI_pw  ]] || exit 1

#	IPMI_pw=`curl -H "Content-Type:application/json" -X POST --data  "{\"data\":  [\"${IPMI_IP}\"],\"type\": \"IPMI\"}" http://udcm.ucloudadmin.com/api/ipmi/v1/getpwd/ | jq "." | grep 'IPMIPassword' | awk '{print $NF}' | sed  's/^"//g' | sed 's/",$//g' | sed 's/"$//g'`
fi
if [ "${IPMI_pw}" == "" ]; then
        IPMI_pw="ucloud.cn"
fi

if [[ $ManufactureType =~ "RH2288 V3" ]];then
  L_BIOS_VER=`dmidecode -s bios-version|sed '/^#/d'`
  if [[ "${L_BIOS_VER}" == "5.13" ]];then
  bash urest -H ${IPMI_IP} -U root -P ${IPMI_pw} config -M import -F /tmp/fw_update/HUAWEI/SETBIOS/RH2288V3.xml
else
	exit 0
  fi
#elif [[ $ManufactureType =~ "2288H V5" ]] || [[ $ManufactureType =~ "5288 V5" ]];then
 # bash urest -H ${IPMI_IP} -U root -P ${IPMI_pw} config -M import -F /tmp/fw_update/HUAWEI/SETBIOS/2288H_V5.xml
elif [[ $ManufactureType =~ "1288H V5" ]];then
  bash urest -H ${IPMI_IP} -U root -P ${IPMI_pw} config -M import -F /tmp/fw_update/HUAWEI/SETBIOS/1288H_V5.xml
else
  ipmitool -I lanplus -H ${IPMI_IP} -U root -P ${IPMI_pw} raw 0x30 0x93 0xdb 0x07 0x00 0x0F 0x02 0x01 0 0 1 0
  exit 0
fi
