#!/bin/bash

ipmi_ip=$(ipmitool lan print 1|grep 'IP Address  '|awk '{print $NF}')
netmask=$(ipmitool lan print 1|grep 'Subnet Mask  '|awk '{print $NF}')
defgw=$(ipmitool lan print 1|grep 'Default Gateway IP  '|awk '{print $NF}')
passwd=$1

function BMCUpdating() {
	echo y|./Yafuflash -kcs /tmp/fw_update/PUERSAI/ESC8000A-E11/BMC/E8111297.ima
}

function IPMISetting() {
        local Address_type=$(ipmitool lan print |grep "IP Address Source" |awk -F ": " '{print$2}' |awk -F " " '{print$1}')
        local Now_ipmi_ip=$(ipmitool lan print |grep "IP Address  " |awk -F ": " '{print$2}')
        
        echo "*** Config IPMI related settings ***"
        
        if [[ $Address_type == "Static" ]] && [[ $Now_ipmi_ip == $ipmi_ip  ]];then
                echo "IPMI don't require configuration"
        else
                ipmitool lan set 1 ipsrc static
                ipmitool lan set 1 ipaddr $ipmi_ip
                ipmitool lan set 1 netmask $netmask
                ipmitool lan set 1 defgw ipaddr $defgw
		ipmitool user set name 2 'root'
		ipmitool user set password 2 "$passwd"
        fi
}



BMCUpdating
IPMISetting

