#!/bin/sh

# Copyright (c) 1996-2002 Sun Microsystems, Inc.  All Rights Reserved. Sun
# considers its source code as an unpublished, proprietary trade secret, and
# it is available only under strict license provisions.  This copyright
# notice is placed here only to protect Sun in the event the source is
# deemed a published work.  Dissassembly, decompilation, or other means of
# reducing the object code to human readable form is prohibited by the
# license agreement under which this code is provided to the user or company
# in possession of this copy.
#
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government
# is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the
# Rights in Technical Data and Computer Software clause at DFARS 52.227-7013
# and in similar clauses in the FAR and NASA FAR Supplement.
#

# identify this package for uninstallation

#
# Unregister MOF changes
#

# Check if pm2 and pm2cfg exist in /var/sadm/wbem/logr/preReg directory.
# If they are found, they must be removed so that they don't get registered
# after the patch is removed.

if [ -d ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2 ];
then
    rm -r ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2
fi

if [ -d ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2cfg ];
then
    rm -r ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2cfg
fi

# Remove pm1cfg tag if it is still in preUnreg directory.
if [ -d ${ROOTDIR}/var/sadm/wbem/logr/preUnreg/pm1cfg ];
then
    rm -r ${ROOTDIR}/var/sadm/wbem/logr/preUnreg/pm1cfg
    rm -rf ${ROOTDIR}/var/sadm/wbem/logr/unregDir/pm1cfg
fi

# Once mofs are registered, they get placed in the /var/sadm/wbem/logr/unregDir
# directory. We need to check for pm2 and pm2cfg tags. If any of them are
# registered then they must be setup to be unregistered by placing these
# tags in /var/sadm/wbem/logr/preUnreg. This unregisters the mofs upon the
# next (re)start of the CIMOM. 

# WORKAROUND: There is a problem with mofreg/mofunreg between FCS version
# and later version introduced by earlier revision(s) of WBEM patch. The bug
# is that when the WBEM patch is applied the mof registration uses the newer
# mofreg that stores the backout information with a different syntax than
# the FCS version. So when the patch is removed, the FCS version of mofunreg
# doesn't understand the format of the backout file so it fails to unregister
# mof changes. The workaround is to do another mofreg (instead of doing
# mofunreg) that basically does the equivalent of what needs to happen.
# So, for 'pm2' tag we apply this workaround.

PM2_MOF=Solaris_Application.mof
MOFDIR=${ROOTDIR}/usr/sadm/mof
TMP_MOF=/tmp/$PM2_MOF

# remove unreg tag for 'pm2'
if [ -d ${ROOTDIR}/var/sadm/wbem/logr/unregDir/pm2 ];
then
    rm -rf ${ROOTDIR}/var/sadm/wbem/logr/unregDir/pm2
    rm -rf ${ROOTDIR}/var/sadm/wbem/logr/unregDir/pm2undo
    # register a new tag, pm2undo
    mkdir -p ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2undo
    echo "#pragma namespace(\"__modify\")" > $TMP_MOF
    echo "#pragma include(\"${MOFDIR}/$PM2_MOF\")" >> $TMP_MOF
    cp $TMP_MOF ${ROOTDIR}/var/sadm/wbem/logr/preReg/pm2undo
    rm -f $TMP_MOF
fi


# unregister 'pm2cfg' tag
if [ -d ${ROOTDIR}/var/sadm/wbem/logr/unregDir/pm2cfg ];
then
    mkdir -p ${ROOTDIR}/var/sadm/wbem/logr/preUnreg/pm2cfg
fi

#
# Register tools and services
#

if [ ! -d "${ROOTDIR}/var/sadm/smc" ] ; then
    exit 0
fi

SMCREG=${ROOTDIR}/usr/sadm/bin/smcregister
ADMIN_LIBDIR=${ROOTDIR}/usr/sadm/lib

if [ -f ${SMCREG} ]; then
    ${SMCREG} tool -n com.sun.admin.patchmgr.client.VPatchMgr.jar \
        ${ADMIN_LIBDIR}/patchmgr/VPatchMgr.jar \
	${ADMIN_LIBDIR}/patchmgr/VPatchMgr_classlist.txt \
	${ADMIN_LIBDIR}/patchmgr/VPatchMgrInfo.xml

    ${SMCREG} tool -n com.sun.admin.patchmgr.cli.PatchMgrCli.jar \
        ${ADMIN_LIBDIR}/patchmgr/PatchMgrCli.jar \
        ${ADMIN_LIBDIR}/patchmgr/PatchMgrCli_classlist.txt \
        ${ADMIN_LIBDIR}/patchmgr/PatchMgrCliInfo.xml
fi

     # CIL proposed mod for 550596 resolution
     # Unregister the new VSysInfo tool and register the old one
     ${SMCREG} tool -u com.sun.admin.sysinfo.client.VSysInfo.jar
     ${SMCREG} tool -n com.sun.admin.sysinfo.client.VSysInfo.jar \
         ${ADMIN_LIBDIR}/sysinfo/VSysInfo.jar \
         ${ADMIN_LIBDIR}/sysinfo/VSysInfo_classlist.txt \
         ${ADMIN_LIBDIR}/sysinfo/VSysInfoInfo.xml

exit 0
