#!/bin/bash
ipmitool -I lanplus -H 192.168.11.11 -U admin -P admin user set password 2 123456789
BMCIP=192.168.11.11
CMD="-I lanplus -H $BMCIP -U admin -P 123456789"
PStat=`ipmitool $CMD power status | awk '{print $NF}'`
echo "Check Jbod power on  ..."
until [ "$PStat" == "on" ];do 
  PStat=`ipmitool $CMD power status | awk '{print $NF}'`
done
sleep 4
echo -n "Checking link to server ... "
J=0
until [ "$J" ==  "1" ];do
  J=`ping $BMCIP -c 4|grep -c " 0% pack"` && echo -e $BMCIP link "\e[0;37;42m OK \e[0m"
done
sleep 3

#log=`ipmitool $CMD fru print 0 | grep "Board Serial" | awk '{print $NF}'`
#Logfile="./log/BMC-${log}.log"
#exec > >(tee -a "$Logfile") 2>&1
#exec 3>&1 1>>"$Logfile" 2>&1

echo "update BMC FW, Make sure power on"
if ./Yafuflash -nw -ip 192.168.11.11 -u admin -p 123456789 -mse 1 -force-boot 4202JBD002203.ima; then
   echo "update is successful"
else
   echo "update error" 
fi
sleep 4
echo -n "Checking link to server ... "
J=0
until [ "$J" ==  "1" ];do
  J=`ping $BMCIP -c 4|grep -c " 0% pack"` && echo -e $BMCIP link "\e[0;37;42m OK \e[0m"
done
sleep 3
echo "set password to 123456789" 
ipmitool -I lanplus -H 192.168.11.11 -U admin -P admin user set password 2 123456789
echo "check bmc fw is 22"
ipmitool -I lanplus -H 192.168.11.11 -U admin -P 123456789 mc info
