#!/bin/ksh

################################################################################
# This prebackout script is created in-order to solve the following problem
# in the local zone
#
#WARNING: /usr/bin/cputrack <no longer a linked file>
#pkgadd: ERROR: unable to create unique temporary file </usr/bin/cputrack9AaaWj>
#Installation of <SUNWcpcu> partially failed.
################################################################################

Quiet() {
        typeset -r cmd_n_args=$*
	 eval "$cmd_n_args" > /dev/null 2>&1
}

if [ "$ROOTDIR" = '/' ] ; then
	typeset -r RT_DIR=$ROOTDIR
else
	typeset -r RT_DIR="$ROOTDIR/"
fi

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

################################################################################
# Regardless of the zone type, remove the cputrack entry from the contents DB
################################################################################

fix_cputrak() {
	Quiet removef -R $ROOTDIR $cpu_pkg ${RT_DIR}usr/bin/cputrack
	Quiet removef -R $ROOTDIR -f $cpu_pkg
}

PKGCOND=/usr/bin/pkgcond
ZONENAME=global
[ -x /sbin/zonename ] && ZONENAME=`/sbin/zonename`

if [ -x "$PKGCOND" ] ; then
        ##  $PKGCOND is_path_writable $ROOTDIR/usr/bin && fix_cputrak
        /usr/bin/touch ${ROOTDIR}/usr/bin/.test.$$ > /dev/null 2>&1 && {
            fix_cputrak
            /usr/bin/rm /usr/bin/.test.$$ > /dev/null 2>&1
        }
else
   	fix_cputrak
fi 
exit 0
