#!/bin/bash
#
# (C) Copyright 2002-2005 Hewlett-Packard Development Company, L.P.
#
# init file for hp Rack agent
#
# processname: cmarackd
NAME="Rack Infrastructure Info Srv"
PNAME="cpqriisd"
PFLAGS="-F"

# Routine to check for 100series server
is_supported_100_series() {
    if [ -z "$SUPPORTED_100_SERIES" ]; then
        SUPPORTED_100_SERIES=1
        if [ -z "$(which dmidecode)" ]; then
            cmaerr "Error: Could not find dmidecode utility, unable to identify system"
            return $SUPPORTED_100_SERIES
        fi
        PRODNAME=`dmidecode | grep "Product Name" | cut -d" " -f4 | head -n1`
        GENERATION=`dmidecode | grep "Product Name" | cut -d" " -f5 | head -n1`
        #Remove the Server Type Tag from Product Name
        PRODNUM=`echo $PRODNAME | sed s/[a-zA-Z]//g`
        if [ "$PRODNUM" -ge 100 -a "$PRODNUM" -lt 200 ] ; then  # TRUE only if the server is 100 series
            if [ "$GENERATION" = "G5" -o "$GENERATION" \> "G5" ]; then  # TRUE only if the server is G5 or higher
                SUPPORTED_100_SERIES=0
            fi
        fi
    fi
    return $SUPPORTED_100_SERIES
}

if [ "x$CMAINCLUDE" = "x" ]; then
   if [ -d /opt/hp/hp-snmp-agents ]; then
        CMAINCLUDE=/opt/hp/hp-snmp-agents/server/etc/cmad
   else
        CMAINCLUDE=/opt/compaq/foundation/etc/cmad
   fi
fi

# Do not check for hpilo module on 100series servers
if ! is_supported_100_series ; then
        STARTADDON="checkformodule hpilo /etc/init.d/hp-ilo"
fi
STOPADDON=remove_shm

remove_shm()
{
   rc=0
   SHMID=$(/usr/bin/ipcs -m | grep 0x0000bbbd | cut -d ' ' -f 2)
   if [ "$SHMID" != "" ]; then 
      ipcrm shm $SHMID 2> /dev/null > /dev/null
   fi 
   return $rc
}

. $CMAINCLUDE
