#! /bin/sh
  PLTFRM=$1

  if [ "$PLTFRM" = "" ]
  then 
  echo "Wrong usage of installme.Please Provide  Platform Information "
  exit 1
  else
  if [ $PLTFRM -lt 0 ] && [ $PLTFRM -gt 7 ]
  then
   echo " Platform is not supported. Exiting the installation  "
   exit 1
  fi
   fi 
 
  LOGFILE=/var/log/OFUInstall.Log
  

  echo "installme: This script installs the RPM packages needed for One-Boot Flash Update Utility."
  echo ": The flashupdt package contains the One-Boot Flash Update Utility and libraries."
  echo ": All these components are required in order to use the One-Boot Flash Update Utility."

    echo " " 
  ################ end of smi_drv installation ####################

  echo " "
  echo "Installing the One-Boot Flash Update Utility ..." >> $LOGFILE

  echo "installme: *1* Installing flashupdt RPM package..."
  echo "Installing flashupdt RPM package..." >> $LOGFILE
  OFU_INSTALLED=`rpm -qa | grep flashupdt | cut -d "-" -f1`
  if [ "flashupdt" = "$OFU_INSTALLED" ]
  then
    echo "installme: A flashupdt RPM package is currently installed. Removing flashupdt..."
    echo "A flashupdt RPM package is currently installed. Removing flashupdt..." >> $LOGFILE

    rpm -e flashupdt
    
  fi

# // The variable OFU_INSTALLME is used in the flashupdt RPM install script.
  export OFU_INSTALLME=true
  if [ -e /etc/SuSE-release ]
  then
  rpm -Uvh flashupdt-1.9.70-4.i586.rpm
  else
  rpm -Uvh flashupdt-1.9.70-4.i386.rpm
  fi  
  OFURET=$?
  export -n OFU_INSTALLME=
  if [ $OFURET -ne 0 ]
  then
    echo "installme: *ERROR* Installation of the flashupdt RPM package failed."
    
    echo "*ERROR* Installation of the flashupdt RPM package failed." >> $LOGFILE
    echo "Exiting installation..."
    exit $OFURET
  else
  if [ $PLTFRM -ne 3 ]
  then
  rm -f /usr/local/flashupdt/AFU*
  rm -f /usr/local/flashupdt/afu*
  rm -f /usr/local/flashupdt/ami*
  fi
  if [ $PLTFRM -gt  1 ] && [ $PLTFRM -lt  6 ] 
  then
  #rm -f /usr/local/flashupdt/lib/libfwd*
  rm -rf /usr/local/flashupdt/enus/fwdupdate
  fi
  if [ $PLTFRM -eq  3 ] || [ $PLTFRM -eq  4 ]
  then 
  #rm -f /usr/local/flashupdt/lib/libbud*
  #rm -f /usr/local/flashupdt/lib/libbios*
  rm -rf /usr/local/flashupdt/enus/biosupdate
  fi
  if [ $PLTFRM -eq  4 ] || [ $PLTFRM -eq  5 ]
  then 
  #rm -f /usr/local/flashupdt/lib/libfru*
  rm -rf /usr/local/flashupdt/enus/frudata
  fi
  if [ $PLTFRM -eq  5 ] 
  then 
  #rm -f /usr/local/flashupdt/lib/libsdr*
  rm -rf /usr/local/flashupdt/enus/sdrdata
  #rm -f /usr/local/flashupdt/lib/libfw*
  rm -rf /usr/local/flashupdt/enus/fwupdate
  fi
  fi
  
  
  if [ $PLTFRM -eq  3 ]
  then
  AFURPM_SUSE=afu-1.40-1.i586.rpm
  AFURPM_RHEL=afu-1.40-1.i386.rpm
  echo " "
  echo "installme: *2* Installing BIOS driver RPM package..."
  echo "installing BIOS driver RPM package..." >> $LOGFILE
 if [ -e /etc/SuSE-release ]; then
  if [ ! -f ./$AFURPM_SUSE ]; then
    echo "installme: *WARNING* The bios driver RPM will not be installed, because the driver package $AFURPM_SUSE, is not available on this CD."
    echo "installme: *WARNING* The bios driver RPM will not be installed, because the driver package $AFURPM_SUSE, is not available on this CD." >> $LOGFILE


    if [ -e /usr/local/afu/amifldrv_mod.o ]; then
      echo "A version of the BIOS driver is already installed."
      echo "A version of the BIOS driver is already installed." >> $LOGFILE

    fi

    echo "installme: Continuing with installation..."
  else
    AFU_INSTALLED=`rpm -qa | grep afu | cut -d "-" -f1`
    if [ "afu" = "$AFU_INSTALLED" ]
    then
      echo "installme: Removing existing BIOS driver RPM package .."
      echo "installme: Removing existing BIOS driver RPM package .." >> $LOGFILE

      rpm -e --nodeps afu --noscripts
    fi
    echo "installme: Installing BIOS driver RPM package: $AFURPM_SUSE"
    echo "installme: Installing BIOS driver RPM package: $AFURPM_SUSE"  >> $LOGFILE

    rpm -Uvh --nodeps $AFURPM_SUSE
    OFURET=$?
    if [ $OFURET -ne 0 ]; then
      echo "installme: *ERROR* Failed to install the BIOS driver RPM package. "
      echo "installme: *ERROR* Failed to install the BIOS driver RPM package. " >> $LOGFILE

      echo "installme: *WARNING* The BIOS driver must be installed to use the One-Boot Flash Update Utility."
      exit 1
    fi
  fi
else
  if [ ! -f ./$AFURPM_RHEL ]; then
    echo "installme: *WARNING* The BIOS driver RPM will not be installed, because the driver package $AFURPM_RHEL, is not available on this CD."
    echo "installme: *WARNING* The BIOS driver RPM will not be installed, because the driver package $AFURPM_RHEL, is not available on this CD." >> $LOGFILE


    if [ -e /usr/local/afu/amifldrv_mod.o ]; then
      echo "A version of the BIOS driver is already installed."
      echo "A version of the BIOS driver is already installed." >> $LOGFILE

    fi

    echo "installme: Continuing with installation..."
  else
    AFU_INSTALLED=`rpm -qa | grep afu | cut -d "-" -f1`
    if [ "afu" = "$AFU_INSTALLED" ]
    then
      echo "installme: Removing existing BIOS driver RPM package..."
      echo "installme: Removing existing BIOS driver RPM package .." >> $LOGFILE

      rpm -e --nodeps afu --noscripts
    fi
    echo "installme: Installing BIOS driver RPM package: $AFURPM_RHEL"
    echo "installme: Installing BIOS driver RPM package: $AFURPM_RHEL"  >> $LOGFILE

    rpm -Uvh --nodeps $AFURPM_RHEL
    OFURET=$?
    if [ $OFURET -ne 0 ]; then
      echo "installme: *ERROR* Failed to install the BIOS driver RPM package. "
      echo "installme: *ERROR* Failed to install the BIOS driver RPM package. " >> $LOGFILE

      echo "installme: *WARNING* The BIOS  driver must be installed to use the One-Boot Flash Update Utility."
      exit 1
      fi
  fi
fi

    
fi
  if [ -f /usr/local/flashupdt/flashupdt ]
  then
	echo "Copying the documents." >> $LOGFILE
    cp ../doc/*.* /usr/local/flashupdt
    cp ../setup_linux /usr/local/flashupdt
	cp curl /usr/local/flashupdt
	cp chaff2l.sh /usr/local/flashupdt
  fi


  if [ -f /usr/local/flashupdt/flashupdt ]  
  then
    chcon -t texrel_shlib_t /usr/local/flashupdt/lib/* 1>&2 2>/dev/null
    echo "***** Installation of the One-Boot Flash Update Utility completed successfully. *****"
    echo "***** Installation of the One-Boot Flash Update Utility completed successfully. *****" >> $LOGFILE
    echo
    echo The One-Boot Flash Update Utility is located in the /usr/local/flashupdt directory.
    echo From that directory, run \"./flashupdt -h\" for information on how to use the utility.
    echo
    exit 0
  else
    echo " "
    echo "installme: *WARNING* One or more required components are not properly installed:"
    echo "One or more required components for OFU are not properly installed:" >> $LOGFILE
    if [ ! -f /usr/local/flashupdt/flashupdt ]; then
      echo "installme: -The file /usr/local/flashupdt/flashupdt is not present. This file is required in order to use the One-Boot Flash Update Utility and is normally installed as part of the RPM package installation."
    fi
      exit 1
  fi
