#!/bin/sh
#ident "@(#)postinstall	1.6 02/03/19 SMI"

# Locate the default JavaHelp runtime jar file installed on the
# system via the JavaHelp runtime pkg.  If we find it, link to it

JHRT_PKG=SUNWjhrt
JHJAR=/usr/sadm/lib/smc/lib/preload/jh.jar

pkginfo -R /${PKG_INSTALL_ROOT} ${JHRT_PKG} >/dev/null 2>&1
if [ $? -eq 0 ]; then

    # Pkg exists, look for full path to where jhall.jar is installed.
    # Must find the regular file, not any symlinks to it.
    #
    out=`env LANG=C LC_ALL=C pkgchk -l -R /${PKG_INSTALL_ROOT} SUNWjhrt | grep "jhall.jar" | grep Pathname \
	| awk '{print $2}'`
    for i in ${out}
    do
	if [ ! -h "${i}" ]; then
	    jhalljar=${i}
	    break;
	fi
    done

    # If found, then delete the existing bundled jar (if it exists), and
    # replace it with a symbol link to the default system jar file.
    #
    if [ -n "${jhalljar}" ]; then

	# Delete the bundled version, and remove the pkg registration 
	# entry for it
	if [ -f ${PKG_INSTALL_ROOT}${JHJAR} ]; then
	    removef ${PKGINST} ${JHJAR} > /dev/null
	    rm -f ${PKG_INSTALL_ROOT}${JHJAR}
	    removef -f ${PKGINST}
	fi

	# Need path to where jhall.jar is installed, but relative to
	# where JHJAR is located on the client.
	if [ "${PKG_INSTALL_ROOT}" != "/" ]; then
	    jhalljar=`echo ${jhalljar} | sed -e "s@^${PKG_INSTALL_ROOT}@@"`
	fi
	link2jhalljar=../../../../../..${jhalljar}

	# Link to the default version on the system, and create a
	# pkg registration entry for it
	ln -s ${link2jhalljar} ${PKG_INSTALL_ROOT}${JHJAR}
	installf -c none ${PKGINST} ${JHJAR}=${link2jhalljar} s
	installf -f ${PKGINST}
    fi
fi

exit 0
