#!/bin/bash
# Last Update: -JerryZhou 2002/2/7-
#

module="imb"
device="imb"
group="wheel"
mode="664"



#modelname="/usr/local/share/asmagent/wsmbdrv/smbiosinfo -m"
#if $modelname | grep -i -E "G310|G520|R710"   &>/dev/null; then
#        if uname -a | grep -i "SMP" &>/dev/null ; then
#                cp -f mbmc_smp.o imb.o
#        else
#                cp -f mbmc.o imb.o
#        fi
#else
#        cp -f imb_r.o imb.o
#fi


ipmi_if=`/usr/local/share/asmagent/wsmbdrv/smbiosinfo -i | cut -d':' -f3 | cut -d',' -f1 `

if [ $ipmi_if -eq 1 -o  $ipmi_if -eq 2 -o  $ipmi_if -eq 3 ] ; then

    cp -f imb_r.o imb.o

elif [ $ipmi_if -eq 4 ] ; then 

	if uname -a | grep -i "SMP" &>/dev/null ; then
		cp -f mbmc_smp.o imb.o
	else
		cp -f mbmc.o imb.o
	fi

fi


#ipmi_if="/usr/local/share/asmagent/wsmbdrv/smbiosinfo -i"
#1,2,3 , load imb_r.o
#4 , load mini bmc imb.o








# invoke insmod with all arguments we got
if grep $module /proc/devices; then
        echo $module" already installed"
        exit
else
  if uname -r | grep "2.4"; then
        # RH7.x
        /sbin/insmod -f ${module}.o  $* || exit 1
  else
    #if uname -r | grep "2.4.2"; then
        # RH71
        #/sbin/insmod -f $RH71smp_opt ${module}.o $* || exit 1
    if (uname -r | grep "2.2.16") || (uname -r |grep "2.2.17"); then
        # RH70
        /sbin/insmod -f $RH70smp_opt ${module}.o  $* || exit 1
    else
      if uname -r | grep "2.2.14"; then
        # RH62
        /sbin/insmod -f $RH62smp_opt ${module}.o $* || exit 1
      else
        # RH60
        /usr/local/share/asm/insmod -f $RH60smp_opt ${module}.o  $* || exit 1
      fi        # RH62
    fi          # RH70
  fi            # RH71
fi              # installed

major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}"`
#echo "major = "$major

# remove stale nodes and replace them, then give gid and perms
rm -f /dev/$device
mknod /dev/$device c $major 0
chgrp $group /dev/$device
chmod $mode  /dev/$device


