#!/bin/ksh

rmpkg=SUNWusb
addpkg=SUNWckr
kbtrans=/kernel/misc/kbtrans

################################################################################
# Removal of cputrack object is to circumvent the stringent check ( attribute
# checking ) in the local zone environment.
# ERROR: attribute verification of </usr/bin/cputrac> failed.
################################################################################
Quiet() {
        typeset -r cmd_n_args=$*
	 eval "$cmd_n_args" > /dev/null 2>&1
}

typeset -r cpu_dir=$ROOTDIR/usr/bin
typeset -r cpu_track=$cpu_dir/cputrack
typeset -r cpu_pkg=SUNWcpcu

Quiet removef -R $ROOTDIR $cpu_pkg $cpu_track
Quiet removef -R $ROOTDIR -f $cpu_pkg

# Destroy the hardlink regardless of the zone type (global/local(sparse, blank))
/usr/bin/rm -f $cpu_track
################################################################################

relocate_kbtrans() {


        if [ ! -f $ROOTDIR/$kbtrans ] ; then
                return
        fi

	## This patch will add kbtrans to SUNWckr.  Manually remove it from SUNWusb
	## if it exists
	##
	Pgk=`pkgchk -R $ROOTDIR -l -p $kbtrans | grep $rmpkg`
	if [ "$?" =  "0" ] ; then
		removef -R $ROOTDIR $rmpkg $ROOTDIR/$kbtrans 1>/dev/null 2>&1
		removef -R $ROOTDIR -f $rmpkg
		installf -R $ROOTDIR $addpkg $ROOTDIR/$kbtrans
		installf -R $ROOTDIR -f $addpkg
	fi
}

if [ "$ROOTDIR" != "/" ]; then
    	# Handle diskless, alternate root case.
	relocate_kbtrans
    	return
fi

if [ -x '/usr/bin/zonename' ] ; then
	if [ `/usr/bin/zonename` != "global" ] ; then
		# We are in a local zone
		# kbtrans is taken care of in global zone.
		return
	else
		# In a global zone
		relocate_kbtrans
	fi
else
  	# we are in the global zone or on a system
   	# without zones support.
   	relocate_kbtrans
fi

exit 0
