#!/bin/bash

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/$log.log"
exec > >(tee -a "$Logfile") 2>&1

# 获取 sg_map -i 中包含 4U78Hub 的 sg 设备名
while true; do
   result=$(sg_map -i | grep '4U78Hub' | awk '{print $1}')

   if [ -n "$result" ]; then
      echo "Found device: $result"
      break
   else
      echo "No 4U78Hub device found,waiting....."
      sleep 5
   fi
done
echo "Update FW&MFG"
if sg_write_buffer $result --id=0x04 --bpw=4k --in=4U78_108_SE_0703.tar --mode=0x02 --offset=0 -t 600; then
   echo "update is successful"
else
   echo "update error"  
fi


sg_ses --page=0x93 /dev/$result
sleep 2
sg_ses --page=0x94 /dev/$result






