#!/bin/bash


function checkBMCActive()
{
    for((i=0;i<20;i++))
    do
        ipmitool mc info 2>&1 |grep "Provides Device SDRs " >/dev/null 2>&1
        if [ $? = 0 ] ;then
	    echo "i = $i bmc is active"
	    sleep 100
            return 0
        else
	    echo "i = $i bmc is inactive"
            sleep 20
        fi
    done

    return 1
}

while true
do
    echo y | ./socflash_x64 if=rom.ima
    sleep 720
    checkBMCActive
    if [ $? -ne 0 ]
    then
	echo "flash bmc1, bmc is inactive so exit"
        exit 202
    fi

    echo y | ./socflash_x64 if=rom.ima cs=1
    sleep 720
    checkBMCActive
    if [ $? -ne 0 ]
    then
	echo "flash bmc2, bmc is inactive so exit"
        exit 202
    fi
done
