summary     	: hp System Health Application and Insight Management Agents Package
name        	: hpasm 
Version     	: 7.3.0
Release		: custom
group       	: System Environment/Kernel
source		: hpasm.tar.gz	
license   	: 2006 Hewlett-Packard Development Company, 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, hpasm <= 7.1.0, cmanic <= 7.1.0, cmastor <= 7.1.0, cpqhealth

%description
The hp System Health Application and Insight Management Agent 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.  The hp Advanced Server Management Application(hpasmd) is the interface to the Advanced Server Management (ASM) ASIC.  This application will work with both the ProLiant ASM (0x0E11A0F1) and the ProLiant iLO Advance Server Management (0x0E11B203) ASICs.  The hpasmd also provides an interface so other software can log events to the hp ProLiant Integrated Management Log (IML).

hp Server, Storage 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
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
#Debian does not have this directory predefined.
if [ ! -d /var/lock/subsys ]; then
   mkdir -p /var/lock/subsys
   chmod 700 /var/lock/subsys
fi

# group add hpsmh - this is for cleansweep
if [ ! -z `egrep "^hpsmh" /etc/group | grep -v ":79:"` ]; then
	groupdel hpsmh > /dev/null 2> /dev/null
fi
if [ -z `egrep "^hpsmh" /etc/group` ]; then
	groupadd -g 79 hpsmh > /dev/null 2> /dev/null
fi
#user add hpsmh - for cleansweep
if [ ! -z `egrep "^hpsmh" /etc/passwd| grep -v ":79:"` ]; then
	userdel hpsmh > /dev/null 2> /dev/null
fi
if [ -z `egrep "^hpsmh" /etc/passwd` ]; then
	useradd -u 79 -g 79 -s /sbin/nologin -M -r -d /opt/hp/hpsmh hpsmh > /dev/null 2> /dev/null
fi

#Legacy Maintenance

#Old hpasm or cpqhealth
if [ -d /opt/compaq/cpqhealth ]; then
   echo "This release of hpasm cannot be installed because it"
   echo "will conflict with a package already installed."
   echo "Please remove the current hpasm or cpqhealth that"
   echo "is installed before upgrading to this release."
   echo "Use 'rpm -e' to remove the old package."
   exit 1
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

#Old Storage 
if [ -f /etc/init.d/cmastor ]; then
	echo "This release of cmastor cannot be upgraded."
	echo "Please remove the installed 'cmastor' RPM before upgrading"
	echo "to this release. Use 'rpm -e cmastor' 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

#TODO: Old Nic agents

#
# 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.
        rm -f $OS_VER/misc/cpqhealth.o
        rm -f $OS_VER/misc/cpqrom.o
        rm -f $OS_VER/kernel/drivers/char/cpqhealth.o
        rm -f $OS_VER/kernel/drivers/char/cpqrom.o
done;

CPQASM=`/sbin/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
        rm -rf /opt/compaq/cpqhealth
fi


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

#export some variables
export RPM_BUILD_ROOT
export RPM_MAKE_ROOT=.
export RPM_NAME=%{name} 

mkdir -p $RPM_BUILD_ROOT/hpasm

#Everything over
cp -a * $RPM_BUILD_ROOT/.





%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
fi

#
# Display EULA for Source Modules
#
echo "Please read the Licence Agreement for this software at"
echo 
echo "         /opt/compaq/hpasm/hpasm.license"
echo 
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
#construct distro.txt
DISTRO="Unknown"
RELEASE="Unknown"
PRODUCT="Unknown"
if [ -f /etc/SuSE-release ]; then
   DISTRO="SuSE"
   RELEASE=`cat /etc/SuSE-release | grep VERSION | cut -d' ' -f3`
   PRODUCT=`head -n1 /etc/SuSE-release | tr ' ' '\n' | grep -e 'Enterprise' -e 'SLES'`
   if [ "$PRODUCT" = "Enterprise" ]; then 
      PRODUCT="$PRODUCT Server"
   fi
elif [ -f /etc/vmware-release ]; then
      DISTRO="VMware"
      PRODUCT="ESX Server"
      RELEASE=`cat /etc/vmware-release | cut -d' ' -f4`
elif [ -f /etc/redhat-release ]; then
   DISTRO="Red Hat"
   RELEASE=`head -n1 /etc/redhat-release | tr ' ' '\n' | egrep -A 1 '[Rr]elease' | tail -n 1` 
   PRODUCT=`head -n1 /etc/redhat-release | tr ' ' '\n' | grep -e 'Enterprise' -e 'Advanced' -e 'Work'`
   if [ "$PRODUCT" = "Enterprise" -o "$PRODUCT" = "Advanced" ]; then 
      PRODUCT="$PRODUCT Server"
   elif [ "$PRODUCT" = "Work" ]; then 
      PRODUCT="Workstation Edition"
   else
      PRODUCT="Professional"
   fi
elif [ -f /etc/debian_version ]; then
   DISTRO="Debian"
   RELEASE=`cat /etc/debian_version`
   PRODUCT=""
elif [ -f /etc/UnitedLinux-release ]; then
   DISTRO="UnitedLinux"
   RELEASE=`cat /etc/UnitedLinux-release | grep VERSION | cut -d' ' -f3`
   PRODUCT=""
elif [ -d /etc/vmware ]; then
   # this could be a VMware Box
   DISTRO="VMware"
   RELEASE=`cat /etc/issue | grep -e '^VMware' | tr ' ' '\n' | grep -e '^[0-9]'`
   PRODUCT="ESX Server"
fi

echo "$DISTRO:$PRODUCT:$RELEASE" >/opt/compaq/hpasm/distro.txt


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 "      You may subsequently reset your agent configuration by typing"
	echo "      '/etc/init.d/hpasm configure' or '/etc/init.d/hpasm reconfigure'." 
	echo "=============================================================================="
fi

#build a manifest of files/subdirs that were present in the directories we created
#find /opt/compaq/webagent >> /opt/compaq/hpasm/addon/direntries.txt


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 -a $1 != "remove" ]; 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

#we need to remove temporary files/subdirs that were created
#during the operation of hpasm. This is accomplished
#by marking the "original" files/dirs read-only, but all
#other files/dirs read-write (for other).
#find /opt/compaq/cpqhealth | xargs -l1 chmod o+rw
#find /opt/compaq/webagent | xargs -l1 chmod o+rw
#cat /opt/compaq/hpasm/addon/direntries.txt | xargs -l1 chmod o-w 2> /dev/null > /dev/null
#find /opt/compaq/cpqhealth -perm -002 | xargs -l1 rm -rf 
#find /opt/compaq/webagent -perm -002 | xargs -l1 rm -rf 

#delete the directory manifest
#rm -f /opt/compaq/hpasm/addon/direntries.txt 2> /dev/null > /dev/null

%postun

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

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

#storage post uninstall

	INARG=$1
	INSTALLLOG=/var/spool/compaq/cma.log
	INSTMSG="cmastor removal"
	REGBASE=/var/spool/compaq/storage
	REGDIR=/var/spool/compaq/storage/registry
	echo "`date`: $INSTMSG: Entering Post Uninstallation ..." >> $INSTALLLOG 
	if [ "$INARG" = "0" ]; then
		rmdir /opt/compaq/storage/bin 2>/dev/null
		rmdir /opt/compaq/storage/etc 2>/dev/null
		rmdir /opt/compaq/storage/src 2>/dev/null
		rmdir /opt/compaq/storage 2>/dev/null
		rmdir /opt/compaq 2>/dev/null
		rmdir /opt 2>/dev/null
		rm -fr $REGBASE
		if [ -d /etc/init.d ]; then
			rm -f /etc/init.d/cmastor
		elif [ -d /etc/rc.d/init.d ]; then
			rm -f /etc/rc.d/init.d/cmastor
		fi
	fi
	echo "`date`: $INSTMSG: Post Uninstallation succeeded!" >> $INSTALLLOG 


#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

# hpasmd postuninstall
       rm -rf /opt/compaq/hpasmd
       rm -f  /var/lock/subsys/cpqasm

# 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


%files 
#The file list will come from hpasm-manifest.txt
