#!/bin/sh

#usage
if [ $# -ne 1 ]; then
    echo "-------------------------------Inspur BMC flash Utility v1.0------------------------------------"
    echo "Usage: ./inspur_socflash.sh [ImageFile]"
    echo "Notes: This utility will update dual(both active and standby)images and preserve configurations."
    echo "------------------------------------------------------------------------------------------------"
    exit 255
fi

ImageFile=$1
CurDir=`pwd`
SOCFLASH=socflash_x64

#check architecture
CMD=`uname -m | cut -c 1-6`
if [ "$CMD" = "x86_64" ]; then
   chmod 777 socflash_x64
   SOCFLASH=socflash_x64
else
   chmod 777 socflash
   SOCFLASH=socflash
fi

echo "-----------------------------------Begin to update 1st image-----------------------------------------"
$CurDir/$SOCFLASH if=$ImageFile cs=0

remaintime=300
while true
do
    echo "Please wait for 1st image to take effect..." $remaintime
    echo -ne "\033[1A"
    sleep 1
    echo "                                                                    "
    echo -ne "\033[1A"
    let remaintime=remaintime-1
    if [ $remaintime -eq 0 ];then
        break
    fi
done
echo "-------------------------------------Update 1st image done-------------------------------------------"

echo "-----------------------------------Begin to update 2nd image-----------------------------------------"
$CurDir/$SOCFLASH if=$ImageFile cs=1
echo "-------------------------------------Update 2nd image done-------------------------------------------"

exit 0
