Summary: Intel IPMI Driver - IMB module
Name: ipmidrvr
Version: 3.1
Release: 1
Source: $INSTALDIR
Group: Binaries
Vendor: Intel Corporation
License: GPL
%define KVer 2.6.0
%ifarch x86_pentium3
AutoReqProv: No
%endif
%ifarch x86_pentium4
AutoReqProv: No
%endif
%description
The Intel IPMI driver uses the /dev/imb device interface and this ipmidrvr
package loads the imb driver module to support that.
This driver is fully compatible with Intel ISC and ISM management software.

%prep
mkdir -p /usr/local/ism
mkdir -p /usr/local/ism/driver

%install
cd $INSTALDIR

install -m 644 -o 0 -g 0 ../../imb/imb.ko /usr/local/ism/driver/imb.ko
install -m 500 -o 0 -g 0 ../../install/iscinstall/getboard/getboard /usr/local/ism/driver/getboard
install -m 500 -o 0 -g 0 ../common/imbrem /usr/local/ism/driver/imbrem
install -m 500 -o 0 -g 0 ../common/imbload /usr/local/ism/driver/imbload

%files
/usr/local/ism/driver/imb.ko
/usr/local/ism/driver/getboard
/usr/local/ism/driver/imbrem
/usr/local/ism/driver/imbload

%clean
rm -rf /usr/local/ism/driver
rmdir --ignore-fail-on-non-empty /usr/local/ism


%post
#This is the post installation step that is run after the files are copied
#to the target system. Only then can we check if this is a valid system to
#install the driver on or not.

#environment variables

BOARD_TYPE=`/usr/local/ism/driver/getboard 2P08PD L440GX SKA40 8K4W0 8H4W0 AH8L020 S450NX SBT2 STL2 SJP2 SCB2 SDS2 SSH4 SHG2 SWV2 SBR2 SE7210TP10 S7501HG SE7520JR23 S5000PHB S5000 T5000`

if [ ${BOARD_TYPE} = unknown ]
then
    echo "This install does not recognize this motherboard."
    echo "You can contact your platform vendor to verify IPMI support."
#    cp /usr/local/ism/driver/imbrem /etc/rc.d/init.d
#    /sbin/chkconfig --add imbrem
fi

# moddir=/lib/modules/`uname -r`/kernel/drivers/char
moddir=/lib/modules/%KVer/kernel/drivers/char
if [ -d $moddir ]
then
   cp -f /usr/local/ism/driver/imb.ko $moddir/imb.ko 
fi

# arg1 = 1 if rpm -i (first time), arg1 = 2 if rpm -U
if [ "$1" = "1" ]
then
  # doing rpm -i, first time

  if [ "${BOARD_TYPE}" = "SCB2" ]
  then
        # ISC needs getboard, so make a link
        iscdir=/usr/local/isc
        mkdir -p ${iscdir}
        cd ${iscdir}
        ln -s /usr/local/ism/driver driver
  fi

  # set up the driver to auto-load
  loadimb=/usr/local/ism/driver/imbload
  if [ -d /etc/rc.d/init.d ]
  then
      cd /etc/rc.d/init.d
      cp $loadimb  .
  else
      cd /etc/init.d
      cp $loadimb  .
  fi
  which chkconfig >/dev/null 2>&1
  if [ $? -eq 0 ]
  then 
     chkconfig --add imbload
  else 
    # do not have chkconfig, set up manually
    if [ -d /etc/rc.d/init.d ]
    then
        # RedHat init.d structure
        cd /etc/rc.d/init.d
        cd ../rc3.d
        ln -s ../init.d/imbload S09imb 2>/dev/null
        cd ../rc5.d
        ln -s ../init.d/imbload S09imb 2>/dev/null
        cd ../rc0.d
        ln -s ../init.d/imbload K75imb 2>/dev/null
        cd ../rc1.d
        ln -s ../init.d/imbload K75imb 2>/dev/null
        cd ../rc6.d
        ln -s ../init.d/imbload K75imb 2>/dev/null
    else
        # SuSE init.d structure
        cd /etc/init.d
        cd rc3.d
        ln -s ../imbload S09imb 2>/dev/null
        cd ../rc5.d
        ln -s ../imbload S09imb 2>/dev/null
        cd ../rc0.d
        ln -s ../imbload K75imb 2>/dev/null
        cd ../rc1.d
        ln -s ../imbload K75imb 2>/dev/null
        cd ../rc6.d
        ln -s ../imbload K75imb 2>/dev/null
    fi
  fi

  $loadimb start
fi
    echo "Intel IPMI Driver installation is complete."

%preun
#This is the pre uninstall section.

which lsmod >/dev/null 2>&1
if [ $? -eq 0 ]
then
   SBINPATH=
else
   SBINPATH=/sbin/
fi

#remove driver function to remove imb driver
        if [ "`${SBINPATH}lsmod | grep imb`" != "" ]
        then
           ${SBINPATH}rmmod imb

           if [ -c /dev/imb ]
           then
              rm -f /dev/imb
           fi
        fi

%postun
#After the uninstall is complete, we want to clean up left over directories.
#Usually the ISM package is uninstalled by this time, but sometimes the
#driver is removed and re-installed with ISM installed but not loaded.

# arg1 = 1 if rpm -U, arg1 = 0 if rpm -e
if [ "$1" = "0" ]
then
  # doing rpm -e postun, so clean up anything left over

  moddir=/lib/modules/%KVer/kernel/drivers/char
  if [ -d $moddir ]
  then
     rm -f $moddir/imb.ko 2>/dev/null
  fi

  which chkconfig >/dev/null 2>&1
  if [ $? -eq 0 ]
  then 
     chkconfig --del imbload
  else 
    # do not have chkconfig, remove manually
    if [ -d /etc/rc.d/init.d ]
    then
        rm -f /etc/rc.d/rc3.d/S09imb
        rm -f /etc/rc.d/rc5.d/S09imb
        rm -f /etc/rc.d/rc0.d/K75imb
        rm -f /etc/rc.d/rc1.d/K75imb
        rm -f /etc/rc.d/rc6.d/K75imb
    else
        rm -f /etc/init.d/rc3.d/S09imb
        rm -f /etc/init.d/rc5.d/S09imb
        rm -f /etc/init.d/rc0.d/K75imb
        rm -f /etc/init.d/rc1.d/K75imb
        rm -f /etc/init.d/rc6.d/K75imb
        rm -f /etc/rc.d/rc3.d/S09imb
        rm -f /etc/rc.d/rc5.d/S09imb
    fi
  fi

  # imbrem is only used for aborted install
  if [ -f /etc/rc.d/init.d/imbrem ]
  then
     chkconfig --del imbrem  2>/dev/null
     rm -f /etc/rc.d/init.d/imbrem
  fi

  rm -rf /usr/local/ism/driver
  echo
  echo "Please reboot the system for IPMI Driver Uninstall to complete." 
  echo
else
  echo "IPMI Driver Uninstall complete." 
fi

%changelog
* Fri Jul 25 2008 Andrew Cress <arcress@users.sourceforge.net>
  rpm -U tweaks for ipmidrvr v28
