#! /bin/sh

#
# ******************************************************************************
# Copyright (c) 2009, Intel Corporation.
# This System Configuration Utility is furnished under license and may only be 
# used or copied in accordance with the terms of that license. No license, express 
#or implied, by estoppel or otherwise, to any intellectual property rights is 
#granted by this document. The Software is subject to change without notice, and 
#should not be construed as a commitment by Intel Corporation to market, 
#license, sell or support any product or technology. Unless otherwise provided for 
#in the license under which this Software is provided, the Software is provided AS 
#IS, with no warranties of any kind, express or implied. Except as expressly 
#permitted by the Software license, neither Intel Corporation nor its suppliers 
#assumes any responsibility or liability for any errors or inaccuracies that may 
#appear herein. Except as expressly permitted by the Software license, no part of
#the Software may be reproduced, stored in a retrieval system, transmitted in any 
#form, or distributed by any means without the express written consent of Intel 
#Corporation.
#******************************************************************************
#******************************************************************************
#


  INSTALL_PATH_PREFIX=$1


 if [ "$INSTALL_PATH_PREFIX" = "" ]
  then 
  INSTALL_PATH_PREFIX=/usr/local
  else
	mkdir -p $INSTALL_PATH_PREFIX
 fi

KER_VER=`uname -r | sed "s/-/./" | cut -d "." -f1-2`

if [ "2.6" = "$KER_VER" ]; then
 KERNEL_SOURCE=`rpm -qa | grep -e kernel-devel -e kernel-source | cut -d "-" -f1-2`
  if [ "kernel-devel" != "$KERNEL_SOURCE" -a "kernel-source" != "$KERNEL_SOURCE" ]
  then
    echo "installme: Unable to install the smi driver.
    echo : The kernel-source package was not detected on the system.
    echo : In order to make and install smi driver, the kernel-source package must be
    echo : installed. This package can be obtained from the operating system\'s
    echo : installation CD.
    echo "Exiting installation..."
    exit 1
  fi
fi

if [ "2.4" = "$KER_VER" ]; then
 KERNEL_SOURCE=`rpm -qa | grep kernel-source | cut -d "-" -f1-2`
  if [ "kernel-source" != "$KERNEL_SOURCE" ]
  then
    echo "installme: Unable to install the smi driver.
    echo : The kernel-source package was not detected on the system.
    echo : In order to make and install smi driver, the kernel-source package must be
    echo : installed. This package can be obtained from the operating system\'s
    echo : installation CD.
    echo "Exiting installation..."
    exit 1
  fi
fi

  KBASE=`uname -r|sed "s/-.*//" | cut -d "." -f1-2`
  echo "Kernel Version = $KBASE"
  if [ "2.6" = "$KBASE" ]
  then
     echo " "
  else
    if [ "2.4" = "$KBASE" ] 
    then 
	echo " "
    else 
     echo "installme: The smi-driver will not be installed, because the driver for the currently  running version of linux, is not available."
     exit 0
    fi
  fi

  echo "installme: This script installs smi driver RPM package."
  echo " "
  
############### smi_drv uninstallation ##################

    echo "installme: *2* Uninstalling BIOS Kernel Module RPM package..."

    SMIRPM_INSTALLED=`rpm -qa | grep "\<smi\>" | cut -d "-" -f1`
    if [ "smi" = "$SMIRPM_INSTALLED" ]; then
      echo "installme: A BIOS Kernel Module RPM package is currently installed. Removing existing BIOS driver..."
      rpm -e smi #--noscripts
    fi

############### smi_drv installation ##################
    echo " " 
    echo "installme: *3* installing BIOS Kernel Module RPM package..."
    rpm -Uvh smi-2.0.2-1.i386.rpm #--prefix=$INSTALL_PATH_PREFIX
    SMIRET=$?
    if [ $SMIRET -ne 0 ]; then
      echo "installme: *ERROR* Failed to install the BIOS Kernel Module RPM package. "
      echo "installme: *WARNING* The BIOS Kernel Module driver must be installed to use the Syscfg Utility."
      echo "installme: Continuing with installation..."
    else
   	   export SMIRPM_INSTALLED=true
  ### Tracker - 28502 Begin
      echo -e "\n***SMI Driver Succesfully Installed***\n"
  ### Tracker - 28502 End
    fi

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

