summary     	: hp Server Management Drivers and Agents 
name        	: hpasm 
version     	: 7.0.0
Release     	: custom 
group       	: System Environment/Kernel
source		: hpasm.tar.gz	
copyright   	: 2002 Compaq Information Technologies Group, L.P.
packager    	: Hewlett-Packard Company
vendor		: Hewlett-Packard Company
url         	: http://www.hp.com/linux
buildroot   	: /var/tmp/%{name}
autoreqprov	: no
prereq		: /bin/sh, /bin/bash
conflicts	: cpqasm, cmasvr, cmafdtn

%description
The hp ProLiant Health Device Driver package provides extended capabilities to ProLiant Servers.  These capabilities include monitoring of temperature thresholds, fan, processor and memory failures.  Should a parameter be out of normal operating conditions, the Linux operating system will be automatically shutdown.  This updated package also provides the capability of other device drivers to be able to log to the hp ProLiant Integrated Management Log (IML).  The HP Server Management Drivers and Agents package is the interface to the Advanced Server Management (ASM) ASIC.  This driver will work with both the ProLiant ASM (0x0E11A0F0) and the ProLiant iLO Advance Server Management (0x0E11B203) ASICs.  The hp ProLiant Event Logging Device Driver provides an interface so other drivers (such as the hp ProLiant storage array device drivers) can log events to the hp ProLiant Integrated Management Log (IML).

hp Server and Foundation Agents for Linux provide a full spectrum of management data. 
This package includes the Server Standard Equipment and Health Agent for hp Servers. 
It also contains the hp Web Agent.
This information is available using the hp Insight Manager Console, any Internet browser, or other management applications 
using SNMP.

%prep
%setup -n hpasm 

%build

%pre

#Upgrade - stop everything
if [ "$1" = "2" ]; then
   if [ -x /opt/compaq/hpasm/etc/hpasm ]; then
	 #silentstop takes everything down (even other dependent services NOT contained in package)
	 # Do the silent stop feature first
	 sh /opt/compaq/hpasm/etc/hpasm silentstop 
	 if [ $? -ne 0 ]; then
	 	# If this did not work, go for the regular stop 
	 	sh /opt/compaq/hpasm/etc/hpasm stop 
	 fi
	 # No unconfigure necessary, since we will reconfigure anyway
   fi

   if [ -f /etc/casmd.conf ]; then
      mv /etc/casmd.conf /etc/casmd.conf.ORIG
   fi

   if [ -f /etc/cevtdl.conf ]; then
      mv /etc/cevtdl.conf /etc/cevtdl.conf.ORIG
   fi

   if [ -f /etc/cevtdm.conf ]; then
      mv /etc/cevtdm.conf /etc/cevtdm.conf.ORIG
   fi
fi

# Make some directories
if [ ! -d /var/spool/compaq/foundation/registry ]; then
   mkdir -p /var/spool/compaq/foundation/registry
   chmod 700 /var/spool/compaq
   chmod 700 /var/spool/compaq/foundation
   chmod 700 /var/spool/compaq/foundation/registry
fi
if [ ! -d /var/spool/compaq/server/registry ]; then
   mkdir -p /var/spool/compaq/server/registry
   chmod 700 /var/spool/compaq
   chmod 700 /var/spool/compaq/server
   chmod 700 /var/spool/compaq/server/registry
fi


#Legacy Maintenance

#Really old health driver
HEALTH_LOADED=`lsmod |fgrep cpqhealth`
STRIKE=${#HEALTH_LOADED}
[ -f /etc/rc.d/init.d/cpqhealth ] && STRIKE=`expr $STRIKE + 1`
[ -f /opt/compaq/cpqhealth/cpqasm/up/cpqasm.o ] && STRIKE=`expr $STRIKE + 1`
if [ $STRIKE -ne 0 ]; then
	echo "This legacy release of cpqhealth cannot be upgraded."
	echo "Please remove the installed 'cpqhealth' RPM before upgrading"
	echo "to this release. Use 'rpm -e cpqhealth' to remove."
	exit 1
fi
#Health driver version 3.x.x
VERSION_FILE=/opt/compaq/cpqhealth/cpqasm/PKG_VERSION 
if [ -f /opt/compaq/cpqhealth/cpqasm/PKG_VERSION ]; then
	HEALTH_MAJOR=`cut -b 1 $VERSION_FILE` 
	if [ $HEALTH_MAJOR -lt 6 ]; then
		echo "This release of cpqhealth cannot be upgraded."
		echo "Please remove the installed 'cpqhealth' RPM before upgrading"
		echo "to this release. Use 'rpm -e cpqhealth' to remove."
		exit 1
	fi
fi
#Old Foundation
if [ -f /etc/init.d/cmafdtn ]; then
	echo "This release of cmafdtn cannot be upgraded."
	echo "Please remove the installed 'cmafdtn' RPM before upgrading"
	echo "to this release. Use 'rpm -e cmafdtn' to remove."
	echo "You may also want to remove the cmaX enabled snmp stack and"
	echo "reinstall the standard snmp package from your Linux distribution."
	exit 1
fi
#Old Server 
if [ -f /etc/init.d/cmasvr ]; then
	echo "This release of cmasvr cannot be upgraded."
	echo "Please remove the installed 'cmasvr' RPM before upgrading"
	echo "to this release. Use 'rpm -e cmasvr' to remove."
	echo "You may also want to remove the cmaX enabled snmp stack and"
	echo "reinstall the standard snmp package from your Linux distribution."
	exit 1
fi


#
# We need to clean up from previously installed versions which
# did not delete all instances of the driver
#

for OS_VER in `ls -d /lib/modules/*`; do
	#Now wipe all occurences of cpqhealth and cpqrom in the current directory.
	if [ -f $OS_VER/misc/cpqhealth.o ]; then
		rm -f $OS_VER/misc/cpqhealth.o
	fi
	if [ -f $OS_VER/misc/cpqrom.o ]; then
		rm -f $OS_VER/misc/cpqrom.o
	fi
	if [ -f $OS_VER/kernel/drivers/char/cpqhealth.o ]; then
		rm -f $OS_VER/kernel/drivers/char/cpqhealth.o
	fi
	if [ -f $OS_VER/kernel/drivers/char/cpqrom.o ]; then
		rm -f $OS_VER/kernel/drivers/char/cpqrom.o
	fi
done;

CPQASM=`lsmod |fgrep cpqasm`
if [ ${#CPQASM} -ne 0 ]; then
   echo "WARNING!  Not able to stop the cpqasm device driver!"
   exit 1
fi


#
# RPM Upgrade may be in process.  We need to clean up a bit
#
if [ -f /sbin/cpqimlview ]; then
	echo "Starting hpasm package Upgrade. . ."
	rm -f /lib/modules/Compaq/drivers/up/cpqasm.o
	rm -f /lib/modules/Compaq/drivers/smp/cpqasm.o
	rm -f /lib/modules/Compaq/drivers/ent/cpqasm.o
	rm -f /opt/compaq/cpqhealth/cpqasm/casmw_linux.o
	rm -f /sbin/cpqimlview
	rm -f /sbin/cpqimlview.tcl
	rm -f /sbin/imlbe
	rm -f /sbin/hpimlview
	rm -f /usr/share/pixmaps/compred.xbm
	rm -f /usr/share/pixmaps/hplogo.xbm
	rm -f /usr/share/pixmaps/m_blue.gif
	rm -f /usr/share/pixmaps/m_fail.gif
	rm -f /usr/share/pixmaps/m_green.gif
	rm -f /usr/share/pixmaps/m_red.gif
	rm -f /usr/share/pixmaps/m_yellow.gif
	for NODE in \
	casm casr cecc ccsm cmca cside cevt cpci cdt cpqw crom cwell cpqevt
	do
		rm -f /dev/$NODE
		rm -f /dev/cpqhealth/$NODE
	done
	rm -f /lib/modules/Compaq/drivers/up/cpqevt.o
	rm -f /lib/modules/Compaq/drivers/smp/cpqevt.o
	rm -f /lib/modules/Compaq/drivers/ent/cpqevt.o
	rm -f /opt/compaq/cpqhealth/cpqevt/cpqevtw_linux.o


#
# For RPM upgrades, we delete all driver binaries to insure
# we rebuild correctly on errata kernels.
#
	DRIVERS=`find /opt/compaq/cpqhealth/cpqasm/* -name cpqasm.o`

	for THIS_DRIVER in $DRIVERS
	do
		if [ -f $THIS_DRIVER ]
		then
			rm $THIS_DRIVER
		fi
	done

	DRIVERS=`find /opt/compaq/cpqhealth/cpqevt/* -name cpqevt.o`

	for THIS_DRIVER in $DRIVERS
	do
		if [ -f $THIS_DRIVER ]
		then
			rm $THIS_DRIVER
		fi
	done

	DRIVERS=`find /opt/compaq/cpqhealth/cmhp/* -name cmhp.o`

	for THIS_DRIVER in $DRIVERS
	do
		if [ -f $THIS_DRIVER ]
		then
			rm $THIS_DRIVER
		fi
	done


fi


%install
if [ $RPM_BUILD_ROOT != "/" ]; then
	rm -rf $RPM_BUILD_ROOT
fi

#new way of determining kernel version (indep. of Suse / Redhate
OS_VERSION_UP=`strings cpqasm/casm.d/cpqasm_up.o | grep kernel_version | cut -d '=' -f 2`
OS_VERSION_MP=`strings cpqasm/casm.d/cpqasm_smp.o | grep kernel_version | cut -d '=' -f 2`
if [ -f cpqasm/casm.d/cpqasm_ent.o ]; then
	OS_VERSION_ENT=`strings cpqasm/casm.d/cpqasm_ent.o | grep kernel_version | cut -d '=' -f 2`
fi
if [ -f cpqasm/casm.d/cpqasm_bm.o ]; then
	OS_VERSION_ENT=`strings cpqasm/casm.d/cpqasm_bm.o | grep kernel_version | cut -d '=' -f 2`
fi

#
# Create the Directory Structure in the build area
#
mkdir -p $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqasm
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqasm/$OS_VERSION_UP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqasm/$OS_VERSION_MP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqasm/$OS_VERSION_ENT
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqevt
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqevt/$OS_VERSION_UP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqevt/$OS_VERSION_MP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cpqevt/$OS_VERSION_ENT
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cmhp
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cmhp/$OS_VERSION_UP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cmhp/$OS_VERSION_MP
mkdir -p $RPM_BUILD_ROOT/opt/compaq/cpqhealth/cmhp/$OS_VERSION_ENT
mkdir -p $RPM_BUILD_ROOT/usr/share/man/man8
mkdir -p $RPM_BUILD_ROOT/usr/share/man/man4
mkdir -p $RPM_BUILD_ROOT/usr/share/pixmaps
mkdir -p $RPM_BUILD_ROOT/sbin
mkdir -p $RPM_BUILD_ROOT/etc/init.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc0.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc1.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc2.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc3.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc4.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc5.d/
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/rc6.d/

#Everything over
cp -a * $RPM_BUILD_ROOT/.

#This is to prevent stripping of executable
#strip makes the health driver crash.
%define __os_install_post %{nil}

%post
sync
#
# We might be upgrading which in that case, we really do
# not want to do this.
#
if [ $1 -eq 2 ]; then
	echo "Completing hpasm package Upgrade. . ."
	#silentstop takes everything down (even other dependent services NOT contained in package)
	sh /opt/compaq/hpasm/etc/hpasm silentstop

   if [ -f /etc/casmd.conf.ORIG ]; then
      if [ -f /etc/casmd.conf ]; then
         mv /etc/casmd.conf /etc/casmd.conf.NEW
      fi
      cp /etc/casmd.conf.ORIG /etc/casmd.conf
   fi

   if [ -f /etc/cevtdl.conf.ORIG ]; then
      if [ -f /etc/cevtdl.conf ]; then
         mv /etc/cevtdl.conf /etc/cevtdl.conf.NEW
      fi
      cp /etc/cevtdl.conf.ORIG /etc/cevtdl.conf
   fi

   if [ -f /etc/cevtdm.conf.ORIG ]; then
      if [ -f /etc/cevtdm.conf ]; then
         mv /etc/cevtdm.conf /etc/cevtdm.conf.NEW
      fi
      cp /etc/cevtdm.conf.ORIG /etc/cevtdm.conf
   fi

fi

#
# Display EULA for Source Modules
#
echo "Please read the Licence Agreement for this software at"
echo -e "\n"
echo "         /opt/compaq/hpasm/hpasm.license"
echo -e "\n"
echo "By Not removing this package, you are accepting the terms"
echo "of the \"License for HP Value Added Software\"."

#This gives us a chance to override EVs etc.
if [ -f /etc/hpasmrc ]; then
	source /etc/hpasmrc
fi

# Soft link the script to /sbin
ln -sf /opt/compaq/hpasm/etc/hpasm /sbin/hpasm


STARTUP=""
CMASILENT="`echo $CMASILENT | tr [a-z] [A-Z]`"
CMAFDTNSILENT="`echo $CMAFDTNSILENT | tr [a-z] [A-Z]`"
if [ "$CMASILENT" = "YES" -o "$CMAFDTNSILENT" = "YES" ]; then
	STARTUP=`uname -r | egrep "$CMAKERNELVERSION"`
fi

RC=0
if [ ! -z "$STARTUP" ]; then
	sh /opt/compaq/hpasm/etc/hpasm postinstall 
	RC=$?
else
	echo "=============================================================================="
	echo "NOTE: In order to activate the software contained in this package, you must"
	echo "      type 'hpasm activate' as 'root' user." 
	echo "=============================================================================="
fi


if [ $RC -eq 0 ]; then
	echo "The hpasm RPM has installed successfully."
	touch  /var/lock/subsys/hpasm
else
 	echo "The hpasm RPM installation failed!"
	echo "See /opt/compaq/cpqhealth/cpqhealth_boot.log for Health Driver details."
	echo "See /var/spool/compaq/cma.log for Agent details."
fi


%preun
sync
#
# We might be upgrading which in that case, we really do
# not want to do this.
#
if [ $1 -ne 0 ]; then
   [ -f /etc/hpasmrc ] && rm -f /etc/hpasmrc
   exit 0
fi

#disable
sh /opt/compaq/hpasm/etc/hpasm preuninstall 

#remove soft link
rm -f /sbin/hpasm

%postun

#
# We might be upgrading which in that case, we really do
# not want to do this.
#
if [ $1 -ne 0 ]; then
#   echo "Post hpasm package upgrade. . ."
   exit 0
fi

	INSTALLLOG=/var/spool/compaq/cma.log

#server post uninstall
	echo "`date`: cmasvr: Entering Post Uninstallation ..." >> $INSTALLLOG
	rm -rf /var/spool/compaq/server
	rm -rf /opt/compaq/server 2>/dev/null
	if [ -d /etc/init.d ]; then
	  rm -f /etc/init.d/cmasvr
	elif [ -d /etc/rc.d/init.d ]; then
	  rm -f /etc/rc.d/init.d/cmasvr
	fi

# foundation postuninstall

	echo "`date`: cmafdtn: Entering Post Uninstallation ..." >> $INSTALLLOG 
	rm -rf /var/spool/compaq/foundation
	rm -rf /opt/compaq/foundation 2>/dev/null
	if [ -d /etc/init.d ]; then
	  rm -f /etc/init.d/cmafdtn
	elif [ -d /etc/rc.d/init.d ]; then
	  rm -f /etc/rc.d/init.d/cmafdtn
	fi

# webagent install
	rm -rf /opt/compaq/webagent

# cpqasm_postuninstall

	rm -rf /opt/compaq/cpqhealth
	rm -f  /var/lock/subsys/cpqasm
   rm -f /etc/casmd.conf*
   rm -f /etc/cevtdl.conf*
   rm -f /etc/cevtdm.conf*

# hpasm_postuninstall

	rm -rf /opt/compaq/hpasm
	rm -f  /var/lock/subsys/hpasm

# Global cleanup; be careful not to blow away any subdirectory.
	rm -f /opt/compaq/* 2> /dev/null
	rmdir /opt/compaq 2> /dev/null
	rmdir /opt 2> /dev/null
	echo "The hpasm package has been removed from this system"

%clean
rm -fR $RPM_BUILD_ROOT
