#
# $Source: /project/fspro/src/unix/sol/common/cmd/common/isis/provider/Attic/patch_config.sh,v $
# $Id: patch_config.sh,v 1.1.2.2 2003/06/06 00:18:44 hchen Exp $
# $Copyrights: Copyright (c) 2003 VERITAS Software Corporation.
# All rights reserved.
# VERITAS, the VERITAS Logo and all other VERITAS product names and
# slogans are trademarks or registered trademarks of VERITAS Software
# Corporation. VERITAS and the VERITAS Logo Reg. U.S. Pat. & Tm. Off.
# Other product names and/or slogans mentioned herein may be trademarks or
# registered trademarks of their respective companies.
#
# UNPUBLISHED - RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF THE UNITED
# STATES.  USE OF A COPYRIGHT NOTICE IS PRECAUTIONARY ONLY AND DOES NOT
# IMPLY PUBLICATION OR DISCLOSURE.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF
# VERITAS SOFTWARE.  USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT
# THE PRIOR EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
#
# The Licensed Software and Documentation are deemed to be "commercial
# computer software" and "commercial computer software documentation" as
# defined in FAR Sections 12.212 and DFARS Section 227.7202.  $
#

#############################################################################
# This script, used by "make hpx_patch", is a complement to fspro.sh.
# NOTE: This is SxRT 3.5MP2 (and HxRT 3.5 Update-2) specific.
# In the later/future patches the situation will be different.
#
# When building the patch package for SxRT 3.5MP2, a patch to release
# SxRT 3.5 (or 3.5MP1), the regular fspro_patchadd()/fspro_patchrm() of
# fspro.sh does not configure the Registry fully. One thing is missing:
#
# Between the base release and the patch release, we have removed the
# dependency on diskprovider.  This is something that is not handled
# by fspro.sh.  We have to remove/add the dependency and the corresponding
# registry key for the disk resource bundle in postinstall/preremove.
#
# This script, fspro_patchadd_adj()/fspro_patchrm_adj(), handles the
# special need:
#
# Remove/add dependency and the registry key of the disk resource bundle.
#############################################################################

#
# VERITAS Object Bus Registry file paramaters
#

#############################################################################
# globals for VRTSob package and VRTSfspro package
#############################################################################
FSPROREGBASE=/opt/VRTSfspro

#############################################################################
# Solaris packaging/patching for jump start compliance needs some
# specific environment variables to be used. Since jumpstart packaging &
# jumpstart patching do not seem to use the same vars, some workarounds
# would be needed. BASEDIR would be set to pkginfo's ROOTDIR in pkgadd/pkgrm
# by the time we get here (in postinstall and postremove). Since we use this
# script for patches also, by the time we get here in in patchadd/patchrm
# (in postbackout and prebackout), BASEDIR does not seem to be set. So
# if BASEDIR is NOT set, we assume we are patch paths and if its set
# we assume we are in pkg paths (hacky!). And since our package base
# is always relative to '/', we will set BASEDIR to "$ROOTDIR/" in the
# patch paths. The trailing '/' will work even if -R is not specified,
# in which case ROOTDIR would be NULL. (ROOTDIR is patch equivalent of
# PKG_INSTALL_ROOT).
#############################################################################
OS_PLAT=`uname -s`
if [ $OS_PLAT = SunOS -o $OS_PLAT = Solaris ]; then
	if [ "$BASEDIR" = "" ]; then
#		We MUST have been in the patch paths, since this is
#		always set in pkg paths by the time we get here.
		PKG_INSTALL_ROOT=$ROOTDIR
		BASEDIR=$ROOTDIR/
	fi
	. $BASEDIR/opt/VRTSfspro/config/ce_guids.sh
	OBBASE=$PKG_INSTALL_ROOT/opt/VRTSob
	FSPROBASE=$BASEDIR/opt/VRTSfspro
	REGFILE=$PKG_INSTALL_ROOT/etc/vx/isis/Registry
else
	. /opt/VRTSfspro/config/ce_guids.sh
	OBBASE=/opt/VRTSob
	FSPROBASE=/opt/VRTSfspro
	REGFILE=/etc/vx/isis/Registry
fi
REGOPS=$OBBASE/bin/vxregctl
OBJTYPOPS=$OBBASE/bin/vxobjecttype
VXSVC=$OBBASE/bin/vxsvc

#############################################################################
# Security stuff
#############################################################################
ACCESSGROUPS="vrtsadm"
ACCESSUSERS=""

#############################
# Client Extension paramaters
#############################
GUIKEY=Software/VERITAS/VxSvc/CurrentVersion/ClientExtensions
GUIKEY_VxFsCE=Software/VERITAS/VxSvc/CurrentVersion/ClientExtensions/{$CLIENT_EXT_VxFsCE}/IsisSkin/1/1033
GUIKEY_VxFsDskRS=Software/VERITAS/VxSvc/CurrentVersion/ClientExtensions/{$CLIENT_EXT_VxFsDskRS}
GUIKEY_VxFsDskRS_VxFsResourceBundle_en=$GUIKEY_VxFsDskRS/IsisSkin/1/1033

error()
{
	if [ $OS_PLAT = HP-UX -o $OS_PLAT = hpux ]; then
		$_ECHO "ERROR:   $@"
	else
		$_ECHO "	 $@"
	fi
}

warning()
{
	if [ $OS_PLAT = HP-UX -o $OS_PLAT = hpux ]; then
		$_ECHO "WARNING: $@"
	else
		$_ECHO "	 $@"
	fi
}

note()
{
	if [ $OS_PLAT = HP-UX -o $OS_PLAT = hpux ]; then
		$_ECHO "NOTE:    $@"
	else
		$_ECHO "	 $@"
	fi
}

fatalexit()
{
	[ "$verbose" = "yes" ] && \
		error "Please fix the problem and re-run this script."
	exit 1
}

usage()
{
	if [ "$prt_usage" = "yes" ]
	then
		error "Usage:  patch_config.sh [-f|v|p] { patchadd | patchrm }"
		exit 1
	fi
}

##############################################################################
# adjustment function to patchadd the fs provider to VEA		     #
##############################################################################
fspro_patchadd_adj()
{
    if [ ! -x $REGOPS -o ! -x $OBJTYPOPS -o ! -f $REGFILE ]
    then
	[ "$verbose" = "yes" -o "$prt_error_only" = "yes" ] && \
	error "Can not locate the VEA utilities. Please fix this problem and
	 then reattempt this configuration adjustment.

	 Aborting VRTSfspro patch add configuration adjustment attempt."
	exit 3
    fi

    #
    # update VERITAS Object Bus registry file
    #
    [ "$verbose" = "yes" ] && \
	note "Adjusting VRTSfspro patch installation in VEA Registry ... \c"

    cp $REGFILE $REGFILE.pre-fspro-patch

    ##############################
    # remove the client extension resource bundle CLIENT_EXT_VxFsDskRS:
    ##############################
    $REGOPS $REGFILE deletekeyrecursive $GUIKEY/{$CLIENT_EXT_VxFsDskRS} 2>/dev/null

    ##############################
    # remove the dependency of CLIENT_EXT_VxFsDskRS from GUIKEY_VxFsCE:
    ##############################
    $REGOPS $REGFILE deletevalue $GUIKEY_VxFsCE StrictDependsOn 2>/dev/null
    $REGOPS $REGFILE setvalue $GUIKEY_VxFsCE StrictDependsOn REG_SZ "VxFsResourceBundle, VxSearchCE, VxFsVmResourceBundle, VxFsVmLibResourceBundle, VxFsOneguiResourceBundle, VxFsHelp";

    rm -rf $REGFILE.pre-fspro-patch 2>/dev/null

    [ "$verbose" = "yes" ] && echo ""
    [ "$verbose" = "yes" ] && \
	note "Registry adjustment for VRTSfspro patch installation complete."
    [ "$verbose" = "yes" ] && echo ""
}

##############################################################################
# adjustment function to patchrm the fs provider to VEA		      #
##############################################################################
fspro_patchrm_adj()
{
    if [ ! -x $REGOPS -o ! -x $OBJTYPOPS -o ! -f $REGFILE ]
    then
	[ "$verbose" = "yes" -o "$prt_error_only" = "yes" ] && \
	error "Can not locate the VEA utilities. Please fix this problem and
	 then reattempt this configuration adjustment.

	 Aborting VRTSfspro patch removal configuration adjustment attempt."
	exit 3
    fi

    #
    # update VERITAS Object Bus registry file
    #
    [ "$verbose" = "yes" ] && \
	note "Adjusting VEA Registry before VRTSfspro patch removal ... \c"

    cp $REGFILE $REGFILE.pre-fspro-patch

    ##############################
    # adding the client extension CLIENT_EXT_VxFsDskRS entry:
    ##############################
    $REGOPS $REGFILE createkey $GUIKEY_VxFsDskRS
    $REGOPS $REGFILE setvalue $GUIKEY/{$CLIENT_EXT_VxFsDskRS} SymbolicName REG_SZ VxFsSysDiskResourceBundle
    $REGOPS $REGFILE createkey $GUIKEY_VxFsDskRS_VxFsResourceBundle_en
    $REGOPS $REGFILE setvalue $GUIKEY_VxFsDskRS_VxFsResourceBundle_en ImageFile REG_SZ $FSPROREGBASE/extensions/VxFsSysDiskResourceBundle.en.jar
    $REGOPS $REGFILE setvalue $GUIKEY_VxFsDskRS_VxFsResourceBundle_en Version REG_SZ $CLIENT_EXT_VxFsDskRS_version

    ##############################
    # add the dependency of CLIENT_EXT_VxFsDskRS back to GUIKEY_VxFsCE:
    ##############################
    $REGOPS $REGFILE deletevalue $GUIKEY_VxFsCE StrictDependsOn 2>/dev/null
    $REGOPS $REGFILE setvalue $GUIKEY_VxFsCE StrictDependsOn REG_SZ "VxFsResourceBundle, VxSearchCE, VxFsVmResourceBundle, VxFsSysDiskResourceBundle, VxFsVmLibResourceBundle, VxFsOneguiResourceBundle, VxFsHelp";

    rm -rf $REGFILE.pre-fspro-patch 2>/dev/null

    [ "$verbose" = "yes" ] && echo ""
    [ "$verbose" = "yes" ] && \
	note "Registry adjustment for VRTSfspro patch removal complete."
    [ "$verbose" = "yes" ] && echo ""
}

set_echo()
{
	case $OS_PLAT in
	SunOS | Solaris)
		_ECHO="echo"
		;;
	AIX | aix)
		_ECHO="echo"
		;;
	HP-UX | hpux)
		_ECHO="echo"
		;;
	Linux | linux)
		_ECHO="echo -e"
		;;
	esac
}

###########################################################################
###  main()
###########################################################################
force=no
verbose=no
debug=no
prt_usage=yes
prt_error_only=yes
_ECHO="echo"

set_echo

if [ $# -lt 1 ]
then
	usage
	exit 1
fi

while getopts :fFvVdDpPqQeE c
do
	case $c in
	f|F)	force=yes
		;;
	v|V)	verbose=yes
		;;
	d|D)	debug=yes
		;;
	p|P)	prt_usage=yes; verbose=yes; prt_error_only=yes
		;;
	q|E)	prt_usage=no; verbose=no; prt_error_only=no
		;;
	e|E)	prt_usage=no; verbose=no; prt_error_only=yes
		;;
	?)	usage; exit 1
		;;
	esac
done

shift `expr $OPTIND - 1`
if [ $# -ne 1 ]
then
	usage
	exit 1
fi

option=$1
if [ -z "$option" ]
then
	usage
	exit 1
fi

case $option in
	patchadd)	action=patchadd	;;
	patchrm)	action=patchrm	;;
	*)		usage; exit 1	;;
esac

###################################
#
# patchadd VRTSfspro Registry adjustment
#
###################################
if [ "$option" = "patchadd" ]
then
    set_echo

    case $OS_PLAT in
    SunOS | Solaris)
	SHLIB_EXT=so
	;;

    AIX | aix)
	SHLIB_EXT=so
	;;

    HP-UX | hpux)
	SHLIB_EXT=sl
	;;

    Linux | linux)
	SHLIB_EXT=so
	;;
    esac

    #############################################
    # adjust the VEA Registry for the fs provider patchadd
    #############################################
    fspro_patchadd_adj

fi   # patchadd

###################################
#
# patchrm VRTSfspro Registry adjustment
#
###################################
if [ "$option" = "patchrm" ]
then
    set_echo

    ###########################################################
    # adjust the VEA Registry for the fs provider patchrm
    ###########################################################
    fspro_patchrm_adj

fi   # patchrm

exit 0
