#!/bin/bash
#Description: H3C R4900 G6 ULTRA BIOS Fw Update

currentDir=`pwd`
resultLog="`pwd`/result.log"

source "${currentDir}/bios.conf"

function getIpmiIPAndPasswd() {
        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_password=$(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_password ]] || exit 1
        fi
        if [ "${ipmi_password}" == "" ]; then
                ipmi_password="ucloud.cn"
        fi
}

function biosVersionCheckAndUpdate() {
        biosVersion=`dmidecode -t bios| grep "Version"|awk '{print $NF}'`
        if [ "${biosVersion}" != "${biosTargetVersion}" ]; then
                bash curl.sh -I ${ipmi_ip} -U root -P ${ipmi_password} -F ${biosFile} -R 1 -K 0 -B 0
#       else
#               echo "No need to update BIOS"
        fi
}

getIpmiIPAndPasswd

biosVersionCheckAndUpdate


