#!/bin/sh

#check RHEL OS
if [ -f /etc/redhat-release ]; then
	modprobe sg
fi

errorcode=0

lsmod | grep ipmi_ssif > /dev/null
ssif=$?
if [ "$ssif" != "1" ]; then
	rmmod ipmi_ssif
fi

#check architecture
CMD=`uname -m | cut -c 1-6`
if [ "$CMD" = "x86_64" ]; then
   cd Linux_x86_64
   echo ""
   echo Linux x86_64 Environment
      if [ -d "/sys/module/ipmi_si/parameters" ]; then
        #echo "remove,kcs,i/o,0xca2,rsp=1,rsi=1,rsh=0,irq=0,ipmb=0 " 
        >/sys/module/ipmi_si/parameters/hotmod   
        chmod 777 Yafuflash
        ./Yafuflash $@
	errorcode=$?
   	if [ "$errorcode" != "0" ]
   	then
   	  echo -e " Yafuflash error code : $errorcode , stop update"
   	  exit 0
	fi
        #echo "add,kcs,i/o,0xca2,rsp=1,rsi=1,rsh=0,irq=0,ipmb=0 " 
        >/sys/module/ipmi_si/parameters/hotmod
      else
        chmod 777 Yafuflash
        ./Yafuflash $@
	errorcode=$?
   	if [ "$errorcode" != "0" ]
   	then
   	  echo -e " Yafuflash error code : $errorcode , stop update"
   	  exit 0
	fi
      fi   
else
   cd Linux_x86_32
   echo ""
   echo Linux x86 Environment
      if [ -d "/sys/module/ipmi_si/parameters" ]; then
        #echo "remove,kcs,i/o,0xca2,rsp=1,rsi=1,rsh=0,irq=0,ipmb=0 " 
        >/sys/module/ipmi_si/parameters/hotmod   
        chmod 777 Yafuflash
        ./Yafuflash $@
	errorcode=$?
   	if [ "$errorcode" != "0" ]
   	then
   	  echo -e " Yafuflash error code : $errorcode , stop update"
   	  exit 0
	fi
        #echo "add,kcs,i/o,0xca2,rsp=1,rsi=1,rsh=0,irq=0,ipmb=0 " 
        >/sys/module/ipmi_si/parameters/hotmod
      else
        chmod 777 Yafuflash
        ./Yafuflash $@
	errorcode=$?
   	if [ "$errorcode" != "0" ]
   	then
   	  echo -e " Yafuflash error code : $errorcode , stop update"
   	  exit 0
	fi
      fi   
fi

if [ "$ssif" != "1" ]; then
	modprobe ipmi_ssif
fi
