#!/bin/sh
#
# Copyright 01/14/00 Sun Microsystems, Inc.  All rights reserved.
#
# @(#)postpatch	1.10 00/01/14 Sun Microsystems, Inc.
#

#
# SUNWemmis patched var-install which itself is normally "fixed" at
# installation time for non-default installation directories.  Make
# sure that the newly patched version is similarly fixed.
#

if /usr/bin/pkginfo -q SUNWemmis; then
    installdir=`/usr/bin/pkgparam SUNWemmis BASEDIR`
    
    #
    # If EM was installed someplace else, update var-install to reflect the
    # new location.
    #

    if [ "$installdir" != "/opt" ] ; then
	/usr/bin/ed - $installdir/SUNWconn/em/bin/var-install <<- BASEDIREOF
		1,\$s!-/opt/SUNWconn/em!-$installdir/SUNWconn/em!g
		w
		q
		BASEDIREOF
    fi

    #
    # Now do the same thing for the runtime directory.
    #

    if [ ! -r $installdir/SUNWemrdb/etc/onconfig.em ] ; then

	#
	# Ideally, we would just use emenv.sh to get the location of the
	# runtime directory, but there's a bug in the FCS installation script
	# and emenv.sh never gets updated.  So, we will try to use onconfig.em.
	# Unfortunately, it only gets created when the user runs em_services
	# -reload.  If it's not there, then tell them they need to run that
	# first.  Exiting with a non-zero value here will cause installpatch
	# to back out the patch.
	#

	echo "You must run em_services -reload before installing this patch."
	exit 1
    fi

    runtimedir=`/usr/bin/grep ROOTPATH $installdir/SUNWemrdb/etc/onconfig.em |
	        /usr/bin/awk '{print $2}' | 
		/usr/bin/sed -e 's,/data/db/rootdbs1,,'`

    if [ "$runtimedir" != "/var/opt/SUNWconn/em" ] ; then
	/usr/bin/ed - $installdir/SUNWconn/em/bin/var-install <<- RUNTIMEDIREOF
		1,\$s!/var/opt/SUNWconn/em!$runtimedir!g
		w
		q
		RUNTIMEDIREOF
    fi

    # Initialize CMIB2GDMO compiler work files
    runtime=/var/$installdir/SUNWconn/em
    if [ ! -d $runtime ] ; then
       echo " "
       echo " Warning : EM_RUNTIME directory $runtime does not exist"
       echo " Using the default RUNTIME directory:/var/opt/SUNWconn/em"
       echo " You may need to copy EM_REFERENCED_MIB manually to resolve this"
       runtime=/var/opt/SUNWconn/em
    fi

    cd $runtimedir/data/MDR
    /usr/bin/sed -e "s,\$installdir/SUNWconn/em,$installdir/SUNWconn/em," < \
        $installdir/SUNWconn/em/etc/snmp_mibs/EM_REFERENCED_MIB > \
        $runtime/data/MDR/EM_REFERENCED_MIB
    /usr/bin/chmod 666 $runtime/data/MDR/EM_REFERENCED_MIB

fi

#
# Bug 4096728: Update S98cmipmpa with any customizations made.
#

if /usr/bin/pkginfo -q SUNWemcpa; then
    if [ -r /tmp/host.106000-02 -a \
	 -r /tmp/mis_port.106000-02 -a \
	 -r /tmp/mpa_port.106000-02 ] ; then
	default_host=`/usr/bin/cat /tmp/host.106000-02`
	mis_port=`/usr/bin/cat /tmp/mis_port.106000-02`
	mpa_port=`/usr/bin/cat /tmp/mpa_port.106000-02`

	/usr/bin/ed - /etc/rc2.d/S98cmipmpa > /dev/null <<- EOF
		1,\$s/localhost/$default_host/g
		1,\$s/5555/$mis_port/g
		1,\$s/5557/$mpa_port/g
		w
		q
		EOF

	/usr/bin/rm -f /tmp/*.106000-02
    fi
fi

if /usr/bin/pkginfo -q SUNWemapp; then
    if [ -r $installdir/SUNWconn/em/config/discover.conf -a \
         -r /tmp/discover.conf.bak ] ; then
        /usr/bin/mv $installdir/SUNWconn/em/config/discover.conf \
                    $installdir/SUNWconn/em/config/discover.conf.106000-07
        /usr/bin/mv /tmp/discover.conf.bak \
                    $installdir/SUNWconn/em/config/discover.conf
    fi
fi

exit 0
