#!/bin/sh
#
# Copyright 04/21/99 Sun Microsystems, Inc.  All rights reserved.
#
# @(#)prepatch	1.6 99/04/21 Sun Microsystems, Inc.
#

#
# If the MIS is installed on this machine, then stop it before applying
# the patch.
#

if /usr/bin/pkginfo -q SUNWemmis; then
    installdir=`/usr/bin/pkgparam SUNWemmis BASEDIR`

    #
    # Make sure the runtime environment exists, otherwise the postpatch
    # script will fail.
    #

    if [ ! -r $installdir/SUNWemrdb/etc/onconfig.em ] ; then
	echo "You must run em_services -reload before installing this patch."
	exit 1
    fi

    $installdir/SUNWconn/em/bin/em_services -force -stop

    #
    # Bug 4128019: save the nervecenter templates that we'll be updating in case
    # the customer has modified them.  Note that this isn't every template;
    # not every template exhibited this bug and not every template is shipped.
    #

    standard_templates="auto_manage_template.tmpl \
			auto_manage_template_clear.tmpl \
			conditions.all \
   		        mibII_if_collision_detection.tmpl \
   		        mibII_if_icmp_triptime.tmpl \
   		        mibII_if_nonunicast_increasing.tmpl \
	     		mibII_ifStatus.tmpl \
	     		rpc_diskinfo_disk_partitons_full.tmpl \
   		        rpc_diskinfo_watch_all_partitions.tmpl \
   		        sample_subscribe_event_clear.tmpl \
   		        sunMIB_process_watch.tmpl"

    misc_templates="generic.conditions \
		    generic_table.tmpl \
		    myif.tmpl"

    echo "Saving standard Nerve Center templates in $installdir/SUNWconn/em/install/nc_templates.orig..."
    mkdir -p $installdir/SUNWconn/em/install/nc_templates.orig
    for f in $standard_templates ; do
	cp $installdir/SUNWconn/em/install/nc_templates/$f \
	   $installdir/SUNWconn/em/install/nc_templates.orig
    done

    echo "Saving miscellaneous Nerve Center templates in $installdir/SUNWconn/em/etc/misc_templates.orig..."
    mkdir -p $installdir/SUNWconn/em/etc/misc_templates.orig
    for f in $misc_templates ; do
	cp $installdir/SUNWconn/em/etc/misc_templates/$f \
	   $installdir/SUNWconn/em/etc/misc_templates.orig
    done
fi

#
# Bug 4096728: make sure that any customizations made in S98cmipmpa stay.
#

if /usr/bin/pkginfo -q SUNWemcpa; then
    default_host=`/usr/bin/grep '^EM_MIS_DEFAULT_HOST' /etc/rc2.d/S98cmipmpa |
		  /usr/bin/sed -e 's/.*:-//' -e 's/}"$//'`
    mis_port=`/usr/bin/grep '^EM_MIS_DEFAULT_PORT' /etc/rc2.d/S98cmipmpa |
	      /usr/bin/sed -e 's/.*:-//' -e 's/}"$//'`
    mpa_port=`/usr/bin/grep '^EM_CMIP_MPA_DEFAULT_PORT' /etc/rc2.d/S98cmipmpa |
	      /usr/bin/sed -e 's/.*:-//' -e 's/}"$//'`
   
    if [ "$default_host" != "localhost" -o \
	 "$mis_port" -ne 5555 -o \
	 "$mpa_port" -ne 5557 ] ; then
	/usr/bin/rm -rf /tmp/*106000-02			# paranoid
	/usr/bin/echo $default_host > /tmp/host.106000-02
	/usr/bin/echo $mis_port > /tmp/mis_port.106000-02
	/usr/bin/echo $mpa_port > /tmp/mpa_port.106000-02
    fi
fi

if /usr/bin/pkginfo -q SUNWemapp; then
    if [ -r $installdir/SUNWconn/em/config/discover.conf ] ; then
        /usr/bin/rm -f /tmp/discover.conf.bak
        /usr/bin/cp -p $installdir/SUNWconn/em/config/discover.conf \
                    /tmp/discover.conf.bak
    fi
fi

exit 0
