# This script creates the backout package for a patch package
#
# directory format options.
#
# @(#) postinstall 1.13 01/01/12 SMI
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
# All rights reserved
#

# Description:
#       Set the TYPE parameter for the remote file
#
# Parameters:
#       none
#
# Globals set:
#	TYPE

set_TYPE_parameter () {
	if [ ${PATCH_UNDO_ARCHIVE:?????} = "/dev" ]; then
		# handle device specific stuff
		TYPE="removable"
	else
		TYPE="filesystem"
	fi
}

#
# Description:
#       Build the remote file that points to the backout data
#
# Parameters:
#       $1:	the un/compressed undo archive
#
# Globals set:
#	UNDO, STATE

build_remote_file () {
	remote_path=$PKGSAV/$SUNW_PATCHID/remote
	set_TYPE_parameter
	STATE="active"

	if [ $1 = "undo" ]; then
		UNDO="undo"
	else
		UNDO="undo.Z"
	fi

	cat > $remote_path << EOF
# Backout data stored remotely
TYPE=$TYPE
FIND_AT=$ARCHIVE_DIR/$UNDO
STATE=$STATE
EOF
}

PATH=/usr/sadm/bin:$PATH

if [ "$PKG_INSTALL_ROOT" = "/" ]; then
	PKG_INSTALL_ROOT=""
fi

if [ -n "$PATCH_BUILD_DIR" -a -d "$PATCH_BUILD_DIR" ]; then
	BUILD_DIR="$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST"
else
	BUILD_DIR="$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST"
fi

if [ ! -n "$PATCH_UNDO_ARCHIVE" ]; then
	PATCH_UNDO_ARCHIVE="none"
fi

FILE_DIR=$BUILD_DIR/files
RELOC_DIR=$FILE_DIR/reloc
ROOT_DIR=$FILE_DIR/root
BO_Deletes=$FILE_DIR/deletes
THIS_DIR=`dirname $0`
PROTO_FILE=$BUILD_DIR/prototype
TEMP_REMOTE=$PKGSAV/$SUNW_PATCHID/temp

if [ "$PATCH_PROGRESSIVE" = "true" ]; then
        # remove the scripts that are left behind
        install_scripts=`dirname $0`
        rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall

	# If this is being used in an old-style patch, insert
	# the old-style script commands here.

	#XXXOld_CommandsXXX#

	exit 0
fi

#
# At this point we either have a deletes file or we don't. If we do,
# we create a prototype entry.
#
if [ -f $BO_Deletes ]; then
	echo "i deletes=$BO_Deletes" >> $BUILD_DIR/prototype
fi

#
# Now delete everything in the deletes list after transferring
# the file to the backout package and the entry to the prototype
# file. Remember that the pkgmap will get the CLIENT_BASEDIR path
# but we have to actually get at it using the BASEDIR path. Also
# remember that removef will import our PKG_INSTALL_ROOT
#
Our_Deletes=$THIS_DIR/deletes
if [ -f $Our_Deletes ]; then
	cd $BASEDIR

	cat $Our_Deletes | while read path; do
		Reg_File=0

		if valpath -l $path; then
			Client_Path="$CLIENT_BASEDIR/$path"
			Build_Path="$RELOC_DIR/$path"
			Proto_Path=$BASEDIR/$path
		else	# It's an absolute path
			Client_Path=$path
			Build_Path="$ROOT_DIR$path"
			Proto_Path=$PKG_INSTALL_ROOT$path
		fi

		# If BASEDIR/CLIENTBASEDIR = "/", then the previous prepends
		# an extra / i.e. //. The sed command later can't find a
		# Proto_Path with // and therefore will not substitute the
		# correct build_Path resulting in the backout pkg not being
		# created.

		if [ "$CLIENT_BASEDIR" = "/" ]; then
			Client_Path=`echo $Client_Path | sed 's|^\/\/|\/|'`
			Proto_Path=`echo $Proto_Path | sed 's|^\/\/|\/|'`
		fi
			
		# Note: If the file isn't really there, pkgproto
		# doesn't write anything but displays an error
		# so check for the file before processing.

		if [ -f "$Proto_Path" ]; then
			LINE=`pkgproto $Proto_Path=$path`
		else
			continue
		fi

		ftype=`echo $LINE | nawk '{ print $1 }'`
		if [ "$ftype" = "f" ]; then
			Reg_File=1
		fi

		if [ $Reg_File = 1 ]; then
			# Add source file to the prototype entry
			if [ "$Proto_Path" = "$path" ]; then
				LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|2"`
			else
				LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|"`
			fi

			DirName=`dirname $Build_Path`
			# make room in the build tree
			mkdir -p $DirName
			cp -p $Proto_Path $Build_Path
		fi

		# Insert it into the prototype file
		echo $LINE 1>>$PROTO_FILE 2>/dev/null

		# Remove the file only if it's OK'd by removef
		rm `removef $PKGINST $Client_Path` 1>/dev/null 2>&1
	done
	removef -f $PKGINST

	rm $Our_Deletes
fi

#
# Unless specifically denied, make the backout package.
#
if [ "$PATCH_NO_UNDO" != "true" ]; then
	cd $BUILD_DIR	# We have to build from here.

	if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
		STAGE_DIR="$PATCH_UNDO_ARCHIVE"
		ARCHIVE_DIR="$PATCH_UNDO_ARCHIVE/$SUNW_PATCHID/$PKGINST"
		mkdir -p $ARCHIVE_DIR
		mkdir -p $PKGSAV/$SUNW_PATCHID
	else
		if [ -d $PKGSAV/$SUNW_PATCHID ]; then
			rm -r $PKGSAV/$SUNW_PATCHID
		fi
		STAGE_DIR=$PKGSAV
		ARCHIVE_DIR=$PKGSAV/$SUNW_PATCHID
		mkdir $ARCHIVE_DIR
	fi

	pkgmk -o -d $STAGE_DIR 1>/dev/null 2>&1
	pkgtrans -s $STAGE_DIR $ARCHIVE_DIR/undo $PKG 1>/dev/null 2>&1
	compress $ARCHIVE_DIR/undo
	retcode=$?
	if [ "$retcode" != 0 ]; then
		echo "compress(1) returned error code $retcode"
		echo "The $PKGINST backout package will not be compressed."
		echo "Continuing to process backout package."
	fi
	if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
		if [ $retcode != 0 ]; then
			build_remote_file "undo"
		else
			build_remote_file "undo.Z"
		fi
	fi
	rm -r $STAGE_DIR/$PKG

	cd ..
	rm -r $BUILD_DIR
	# remove the scripts that are left behind
	install_scripts=`dirname $0`
	rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall
fi

#
# Since this apparently worked, we'll mark as obsoleted the prior
# versions of this patch - installpatch deals with explicit obsoletions.
#
cd ${PKG_INSTALL_ROOT:-/}
cd var/sadm/pkg

active_base=`echo $SUNW_PATCHID | nawk '
	{ print substr($0, 1, match($0, "-")-1) } '`

List=`ls -d $PKGINST/save/${active_base}* 2>/dev/null`
if [ $? -ne 0 ]; then
	List=""
fi

for savedir in $List; do
        patch=`basename $savedir` 
        if [ $patch = $SUNW_PATCHID ]; then
		break
	fi

        # If we get here then the previous patch gets deleted
	if [ -f $savedir/undo ]; then
		mv $savedir/undo $savedir/obsolete
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
	elif [ -f $savedir/undo.Z ]; then
		mv $savedir/undo.Z $savedir/obsolete.Z
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
        elif  [ -f $savedir/remote ]; then
                `grep . $PKGSAV/$patch/remote | sed 's|STATE=.*|STATE=obsolete|' > $TEMP_REMOTE` 
                rm -f $PKGSAV/$patch/remote 
                mv $TEMP_REMOTE $PKGSAV/$patch/remote  
                rm -f $TEMP_REMOTE 
                echo $SUNW_PATCHID >> $savedir/obsoleted_by
	elif  [ -f $savedir/obsolete -o -f $savedir/obsolete.Z ]; then
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
	fi
done

# If additional operations are required for this package, place
# those package-specific commands here.

#XXXSpecial_CommandsXXX#

# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)postinstall	1.45	06/03/27 SMI"
#

# Register SunPlex Manager with the Sun Management Center
# smreg supports jumpstart/-R by itself, so we don't have to run chroot

########################################################################
#
# Function: webconsole_setup
# Description:  This function only compiles the JSPs
#		based on the format relevant to Tomcat 4.0.5. For newer
#		versions, this method will return without doing anything.
#
########################################################################
webconsole_setup() {

    # Ensure a visible Tomcat pkg exists
    /usr/bin/pkginfo SUNWtcatu > /dev/null 2>&1
    if [ $? -ne 0 ]; then
	echo 'Skipping JSP Pre-Compilation.'
        return 1
    fi

    version=`env LANG=C LC_ALL=C /usr/bin/pkgparam SUNWtcatu VERSION | awk -F, '{print $1}' | awk -F. '{print $1 "." $2}'` ;
    if [ ${version} != "11.9" ]; then
	echo 'Not a supported Tomcat version for the JSP Pre-Compilation routine.'
	echo 'Skipping JSP Pre-Compilation.'
	return 1;
    fi;

    # Precompile the JSPs to speed up the console once the user logs in
    if [ ! -d "${TOMCAT_WORK_DIR}" ]; then
	/usr/bin/mkdir -p ${TOMCAT_WORK_DIR}
	# Make it writeable by the Tomcat process owner
	/usr/bin/chmod -R 755 ${PKG_INSTALL_ROOT}/var/opt/webconsole/work
	/usr/bin/chown -R noaccess ${PKG_INSTALL_ROOT}/var/opt/webconsole/work
    fi

    compile_JSPs "${TOMCAT_WORK_DIR}/SunPlexManager" "${LOCKHART_APP_DIR}/SunPlexManager"
    compile_JSPs "${TOMCAT_WORK_DIR}/console"	 "${LOCKHART_APP_DIR}/console"

}

########################################################################
#
# Function: compile_JSPs
# Description: Precompile the JSPs and put them in a Tomcat specific
#		work directory. 
#		In Tomcat 5.x, the  class naming has changed from
#		NAME$jsp.java to NAME_jsp.java. This function does not
#		support precompilation for Tomcat 5.x.
#	
# This function uses jasper compiler(jspc) compile the jsp files to 
# java files. Then renames the <name>.java files to <name>$jsp.java
# makes the file part of org.apache.jsp package. Then it compiles
# the java files in the tomcat work directory to its class files.
# The class path for compilation is generated from the application
# jar files in $APP_TO_COMPILE/WEB-INF/lib/
#
########################################################################
compile_JSPs() {
    TOMCAT_CLASS_DIR=$1
    APP_TO_COMPILE=$2

    /usr/bin/rm -Rf ${TOMCAT_CLASS_DIR}
    /usr/bin/mkdir -p ${TOMCAT_CLASS_DIR}

    ${CATALINA_HOME}/bin/jspc.sh -d ${TOMCAT_CLASS_DIR} -webapp ${APP_TO_COMPILE}

    SRC_DIR=${TOMCAT_CLASS_DIR}
    cd ${SRC_DIR}
    PACKAGE_STRING=package
    COMMENTED_PACKAGE_STRING=//package
    appclass_path=""
    for JAR in `ls ${APP_TO_COMPILE}/WEB-INF/lib/*.jar 2> /dev/null`; do
	appclass_path=${appclass_path}:${JAR}
    done


    for DIR in `/usr/bin/find $SRC_DIR -type d -name '*'`; do
	cd ${DIR}
	FILE=""
	for FILE in `/usr/bin/ls $DIR/*.java 2> /dev/null`; do
            oldclass=`basename $FILE | sed -e "s/.java//"`
            newclass=${oldclass}'$jsp'
            /usr/bin/sed "s%$PACKAGE_STRING%$COMMENTED_PACKAGE_STRING%g" $FILE > "$FILE"_tmp
       	    /usr/bin/mv "$FILE"_tmp $FILE

            /usr/bin/echo "package org.apache.jsp;" > ${newclass}.java ;
            /usr/bin/sed -e "/public class/s/${oldclass}/${newclass}/" -e "/public ${oldclass}/s/${oldclass}/${newclass}/" ${oldclass}.java >> ${newclass}.java
            /usr/bin/rm -Rf ${FILE}
	done

       if [ "$FILE" != "" ]; then
	   echo 'Compiling Java files in '${DIR}
           $JAVA_HOME/bin/javac -classpath ${CATALINA_BASE}/lib/cc.jar:${CATALINA_BASE}/lib/SMIWebCommon.jar:${CATALINA_HOME}/common/lib/servlet.jar:${CATALINA_HOME}/lib/jasper-runtime.jar:${CATALINA_HOME}/lib/com_iplanet_jato_jato.jar${appclass_path} *.java 2> /dev/null

           /usr/bin/rm -Rf *.java
	fi
    done

    # Must be writeable by the user identity of the server process.
    /usr/bin/chmod -R 755 ${TOMCAT_CLASS_DIR}
    /usr/bin/chown -R noaccess ${TOMCAT_CLASS_DIR}
    return 0
}

##############################
#
#  common_test_java_version
#
#       Locate an appropriate version of java
#
#       input:          nothing
#       output:         error message
#       returns:        0 if appropriate version or 1 if not
#                       JAVA_HOME set appropriately
#
#       action:
#
#       Search for executable java in $JAVA_HOME and
#       $PATH and 'well-known' packages and test
#       for acceptable version.
#
#       Exit with first satisfactory version or
#       with error message showing all non-satisfactory
#       versions encountered.
#
#       (This implementation adapted from Lockhart:
#       /usr/sbin/smcwebserver 2.2.1)
#
#       'dot-dot' not considered
#
#       java version "1.2.2" -> 1 and 2
#       java version "1.4.1_02a" -> 1 and 4
#
##############################
common_test_java_version()
{
    PROG=postinstall
    WHICH="/bin/ksh whence"
    # Map to a number we can do a numerical comparison on.
    weWant=`versionString2Num $MIN_JAVA_VER`
    weHave=
    versionsFound=""

    # JAVA_HOME environment variable overrides everything
    JAVA_LOC="${JAVA_HOME:+${JAVA_HOME}/bin/java}"

    # Followed by along PATH and the standard location.
    javaOnPath=`${WHICH} java 2>&1`
    if [ $? -eq 0 ]; then
        JAVA_LOC="$JAVA_LOC ${javaOnPath} ${DEFAULT_JAVA}"
    else
        JAVA_LOC="$JAVA_LOC ${DEFAULT_JAVA}"
    fi

    JAVA_HOME=""
    for i in ${JAVA_LOC}
    do
        prog=`resolve_link ${i}`
        if [ -x ${prog} ]; then
            # Get version, and map to a number we can do a
            # numerical comparison on.
            version=`${i} -version 2>&1 | head -1`
            version=`echo $version | awk '{print $3}' | sed -e "s/\"//g"`
            if [ -z "${versionsFound}" ]; then
                versionsFound=${version}
            else
                versionsFound="${versionsFound}, ${version}"
            fi

            weHave=`versionString2Num $version`
            if [ ${weHave} -ge ${weWant} ]; then
                JAVA_HOME=`dirname \`dirname ${prog}\``
                export JAVA_HOME
                break
            fi

        fi
    done

   # It is possible we didn't find one if it was installed in a non-default
    # location and the user neglected to set JAVA_HOME or include it along
    # PATH.  In this case, we try to derive it by querying the pkg database.
    #
    if [ ! -n "${JAVA_HOME}" ]; then
        jdk=SUNWj5rt
        /usr/bin/pkginfo $jdk >/dev/null 2>&1
        if [ "$?" -eq 0 ]; then
            # Get version, and map to a number we can do a
            # numerical comparison on.
            version=`env LANG=C LC_ALL=C /usr/bin/pkgparam $jdk SUNW_PRODVERS \
                | awk -F/ '{print $1}'`
            if [ -z "${versionsFound}" ]; then
                versionsFound=${version}
            else
                versionsFound="${versionsFound}, ${version}"
            fi
            weHave=`versionString2Num $version`

            if [ ${weHave} -ge ${weWant} ]; then
                j2basedir=`env LANG=C LC_ALL=C /usr/bin/pkgparam ${jdk} BASEDIR`
                JAVA_HOME=${j2basedir}/jdk/jdk${version}
                export JAVA_HOME
            fi
        fi
    fi
    if [ ! -n "${JAVA_HOME}" ]; then
        jdk=SUNWj3rt
        /usr/bin/pkginfo $jdk >/dev/null 2>&1
        if [ "$?" -eq 0 ]; then
            # Get version, and map to a number we can do a
            # numerical comparison on.
            version=`env LANG=C LC_ALL=C /usr/bin/pkgparam $jdk VERSION \
                | awk -F, '{print $1}'`
            if [ -z "${versionsFound}" ]; then
                versionsFound=${version}
            else
                versionsFound="${versionsFound}, ${version}"
            fi
            weHave=`versionString2Num $version`

            if [ ${weHave} -ge ${weWant} ]; then
                j2basedir=`env LANG=C LC_ALL=C /usr/bin/pkgparam ${jdk} BASEDIR`
                JAVA_HOME=${j2basedir}/j2se
                export JAVA_HOME
            fi
        fi
    fi

    if [ ! -n "${JAVA_HOME}" ]; then
        printf "%s: java version(s) found: %s. Must be %s or newer.\n" ${PROG} "${versionsFound}" ${MIN_JAVA_VER}
        return 1
    else
	#echo "JAVA_HOME is" $JAVA_HOME
        return 0
    fi

} # common_test_java_version

########################################################
#
# Function to resolve a link to it's target.
#
# (Lifted from Lockhart: /usr/sbin/smcwebserver 2.2.1)
#
########################################################
resolve_link() {

    prg=$1

    if [ -h "${prg}" ]; then

        # Must cd to where the symbolic link is located as a starting point
        # to follow the link.
        cd `dirname ${prg}`

        # Resolve link to conclusion
        while [ -h "${prg}" ]
        do
            prg=`ls -al ${prg} | awk '{print $NF}'`
            cd `dirname ${prg}`
        done

        # Resolve to full path, in case it's relative.

        prg=`pwd`/`basename ${prg}`
    fi

    echo $prg

} # resolve_link

########################################################
#
# Function to convert a java version string to an int
#       that may be compared to other ints
#
# (Lifted from Lockhart: /usr/sbin/smcwebserver 2.2.1)
#
########################################################
versionString2Num () {

    # Minor and micro default to 0 if not specified.

    major=`echo $1 | awk -F. '{print $1}'`
    minor=`echo $1 | awk -F. '{print $2}'`
    if [ ! -n "$minor" ]; then
        minor="0"
    fi
    micro=`echo $1 | awk -F. '{print $3}'`
    if [ ! -n "$micro" ]; then
        micro="0"
    fi

    # The micro version may further be extended to include a patch number.
    # This is typically of the form <micro>_NN, where NN is the 2-digit
    # patch number.  However it can also be of the form <micro>-XX, where
    # XX is some arbitrary non-digit sequence (eg., "rc").  This latter
    # form is typically used for internal-only release candidates or
    # development builds.
    #
    # For these internal builds, we drop the -XX and assume a patch number
    # of "00".  Otherwise, we extract that patch number.
    #
    patch="00"
    dash=`echo $micro | grep "-"`
    if [ $? -eq 0 ]; then
        # Must be internal build, so drop the trailing variant.
        micro=`echo $micro | awk -F- '{print $1}'`
    fi

    underscore=`echo $micro | grep "_"`
    if [ $? -eq 0 ]; then
        # Extract the seperate micro and patch numbers, ignoring anything
        # after the 2-digit patch.
        patch=`echo $micro | awk -F_ '{print substr($2, 1, 2)}'`
        micro=`echo $micro | awk -F_ '{print $1}'`
    fi

    echo "${major}${minor}${micro}${patch}"

} # versionString2Num

# minimum java version:
MIN_JAVA_MAJOR_VER=${MIN_JAVA_MAJOR_VER:-1}
MIN_JAVA_MINOR_VER=${MIN_JAVA_MINOR_VER:-4}
MIN_JAVA_VER=${MIN_JAVA_MAJOR_VER}.${MIN_JAVA_MINOR_VER}

JAVA_HOME=${JAVA_HOME:-/usr/java}

CONSOLE_DIR=${PKG_INSTALL_ROOT}/usr/cluster/lib
JDMK_JAR_LIB_DIR=${PKG_INSTALL_ROOT}/opt/SUNWjdmk/5.1/lib
CACAO_JAR_LIB_DIR=${PKG_INSTALL_ROOT}/opt/SUNWcacao/lib
CMASS_JAR_LIB_DIR=${PKG_INSTALL_ROOT}/usr/cluster/lib/cmass
SMREG=${PKG_INSTALL_ROOT}/usr/sbin/smreg

CATALINA_HOME_ROOT=`/usr/bin/pkginfo -r SUNWtcatu  2>/dev/null	`
CATALINA_HOME="${CATALINA_HOME_ROOT}/usr/apache/tomcat"
CATALINA_BASE_ROOT=`/usr/bin/pkginfo -r SUNWmcon  2>/dev/null  `
CATALINA_BASE="${CATALINA_BASE_ROOT}/usr/share/webconsole"

# The following two directory paths may change for future versions of Tomcat and Lockhart
# and these should be updated appropriatly
TOMCAT_WORK_DIR=${PKG_INSTALL_ROOT}/var/opt/webconsole/work/com_sun_web_console/localhost
LOCKHART_APP_DIR=${PKG_INSTALL_ROOT}/var/opt/webconsole/webapps

# The following is later set to "-q" if smreg supports it (LH 3.0 or later)
QOPT=

# get webconsole version
console_version=`env LANG=C LC_ALL=C /usr/bin/pkgparam SUNWmcon VERSION | awk -F, '{print $1}' | awk -F. '{print $1 "." $2}'` ;
console_major=`echo $console_version | awk -F. '{print $1}'`

# check for lockhart version 3 or greater
if [ "$console_major" -ge 3 ]; then
    QOPT=-q
fi

# Register the applications
if [ -s ${SMREG} ]; then

    # The exporting of PKG_INSTALL_ROOT is a workaround for a bug with smreg.
    if [ "$PKG_INSTALL_ROOT" = "" ]; then
	PKG_INSTALL_ROOT="" ${SMREG} ${QOPT} add -a ${CONSOLE_DIR}/SunPlexManager

	for i in ${JDMK_JAR_LIB_DIR}/*.jar; do 
	    PKG_INSTALL_ROOT="" ${SMREG} ${QOPT} add -l -n `basename $i` -s ALL $i
	done	

	for i in ${CACAO_JAR_LIB_DIR}/*.jar; do 
	    PKG_INSTALL_ROOT="" ${SMREG} ${QOPT} add -l -n `basename $i` -s com.sun.cluster.spm_2.0 $i
	done	

	for i in ${CMASS_JAR_LIB_DIR}/*.jar; do 
	    PKG_INSTALL_ROOT="" ${SMREG} ${QOPT} add -l -n `basename $i` -s com.sun.cluster.spm_2.0 $i
	done	

	# Lockhart requires more heap than default, put in a huge
	# maximum heap since heap usage levels out when everything loaded
	PKG_INSTALL_ROOT="" ${SMREG} ${QOPT} add -p java.options="-server -XX:+BackgroundCompilation -Xmx256m"
    else

	${SMREG} ${QOPT} add -a ${CONSOLE_DIR}/SunPlexManager

	for i in ${JDMK_JAR_LIB_DIR}/*.jar; do 
	    ${SMREG} ${QOPT} add -l -n `basename $i` -s ALL $i
	done	

	for i in ${CACAO_JAR_LIB_DIR}/*.jar; do 
	    ${SMREG} ${QOPT} add -l -n `basename $i` -s com.sun.cluster.spm_2.0 $i
	done	

	for i in ${CMASS_JAR_LIB_DIR}/*.jar; do 
	    ${SMREG} add -l -n `basename $i` -s com.sun.cluster.spm_2.0 $i
	done	

	# Lockhart requires more heap than default, put in a huge
	# maximum heap since heap usage levels out when everything loaded
	${SMREG} ${QOPT} add -p java.options="-server -XX:+BackgroundCompilation -Xmx256m"
    fi

    # If not jumpstarting, restart the agent and our server

    if [ "$PKG_INSTALL_ROOT" = "/" ] || [ "$PKG_INSTALL_ROOT" = "" ]
    then

	TERM=xterms; export TERM
	common_test_java_version >&2 

	webconsole_setup

	# make sure Lockhart restarts on reboot

	# If the console version is less than 3, or the OS version
	# is less than 10, then use the smcwebserver command.
	# Otherwise, use SMF to enable to service because LH 3.0+ uses
	# SMF to control the webconsole
	# RTI 6392584; developer ask us not to execute this code in the patch
	# context
	if [ "x$SUNW_PATCHID" = "x" ]; then
		OS_VER=`uname -r | awk -F. '{ print $2 }'`
		if [ "$OS_VER" -lt 10 ] || [ "$console_major" -lt 3 ]; then
			/usr/sbin/smcwebserver enable
		else
			/usr/sbin/svcadm enable system/webconsole:console
		fi
	fi

	# and restart it now
	/usr/sbin/smcwebserver restart

    fi
fi

# exit 0 so that the pkgadd will always succeed
exit 0
