#!/bin/bash

IPMI_IP=`ipmitool  lan print 1 | grep "IP Address  "| awk '{print $NF}'`
if [ "${IPMI_IP}" != "0.0.0.0" ]; then
        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

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

if [[ -n $IPMI_IP ]] && [[ $IPMI_IP != '0.0.0.0' ]];then
  \cp -f hwServers.xml.template hwServers.xml
  sed -i "s/IPMIADDRESS/$IPMI_IP/g" hwServers.xml
  sed -i "s/IPMIPASSWORD/$IPMI_pw/g" hwServers.xml
  chmod +x uMate_CLI.sh
  bash uMate_CLI.sh FWUpgrade -f "RH2288_V3-BIOS-V513.zip" -s hwServers.xml -n
sleep10
  bash uMate_CLI.sh FWUpgrade -f "RH2288_V3_-Mainboard(BC1HGSB01)-CPLD-V112.zip" -s hwServers.xml -n
fi

