#!/bin/sh

# record data into fru.sh
chmod 777 FRUSH
./FRUSH 
 	ipmi_ip=`ipmitool lan print 1|grep "IP Address"|grep -v Source|awk 'NF=NF-0{print $NF}'`
	netmask=`ipmitool lan print 1|grep "Subnet Mask"|awk 'NF=NF-0{print $NF}'`
 	gateway=`ipmitool lan print 1|grep "Default Gateway IP"|awk 'NF=NF-0{print $NF}'`

# update firmware
chmod 777 socflash.sh

echo "run the data \n"
./socflash.sh if=S165K213.ima skip=0x50000 offset=0x50000 count=0x1FB0000 cs=0 flashtype=2 option=g

echo "Start to run fru.sh, pleae wait"
sleep 20
# fru.sh to reload the data
chmod 777 fru.sh
./fru.sh

# double check if the first fru.sh fail to upgrage
./fru.sh
  	sleep 60
        ipmitool lan set 1 ipsrc static
        sleep 3
        ipmitool lan set 1 ipaddr ${ipmi_ip}
        sleep 3
        ipmitool lan set 1 netmask ${netmask}
        sleep 3
        ipmitool lan set 1 defgw ipaddr ${gateway}
        sleep 3
        ipmitool user set name 2 root
        sleep 30

passwd='ucloud.cn'
        sleep 10
     	ipmitool user set password 2 ${passwd}
     	if [ $? -ne 0 ];then
     	echo "Ipmitool Local Command Not Work."
     	return 1
         fi

