#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 18.3 $ generated on Fri Jun  1 01:11:43 MDT 2001
#
# (c)Copyright 1983-2001 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD postremove script template for 11.X patches.                  #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to perform any necessary cleanup actions after the     #
# patch's files have been removed.                                 #
#------------------------------------------------------------------#

_PATCHID=PHSS_23546

UTILS="/usr/lbin/sw/control_utils"

if [ ! -f $UTILS ]; then
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

. $UTILS
exitval=$SUCCESS

#####
##### Insert any code you may require at this point in the script.
##### Pay attention to the exitval variable and set appropriately
##### in your code.  If you are unsure as to what types of operations
##### are legal in this file and what types aren't, consult the 
##### "Guidelines for SD Control Scripts" document.
#####
##### START_CUSTOMIZATION_HERE
################### begin postremove #####################

########################## begin bhl #####################
#
# These utilities are "almost" identical to the ones 
# located in the control_utils file.  However, we found
# it necessary to over ride the IPD stuff in this
# instance.
#                      - bhl administrator
#


########
# bhl_cp_retain --
#       $1:     copy fromfile
#       $2:     copy destination path
#
# Unconditionally copy $1 to $2 and set attributes.  Create necessary
# directories.  Caller should verify existence of $1 before calling
# 'bhl_cp_retain'.  Caller is responsible for trapping and handling errors.
#
bhl_cp_retain ()
{
    if [[ $# -ne 2 ]]
    then
	echo "Usage: bhl_cp_retain source target" >&2
	return 1
    fi

    typeset dirname=${2%/*}

    [[ -z $dirname ]] && dirname=/
    r_mkdir 755 bin bin $dirname
    cp -p $1 $2 
    if [[ $? -ne $SUCCESS ]]
    then
	echo "ERROR:   Attempt to copy \"$1\" to \"$2\" failed for the above reason."
	return 1
    else
	#####IPD_addfile $2
	return 0
    fi
}
########################### end bhl ######################

	##
	## Restore /etc/X11 stuff
	##

X11FILES="X0devices X0pointerkeys X0screens XHPKeymaps \
		rgb.dir rgb.pag rgb.txt"

for FILE in $X11FILES
do
	if [ -a ${SW_ROOT_DIRECTORY}etc/X11/${FILE} ]
	then
		bhl_cp_retain ${SW_ROOT_DIRECTORY}usr/old/etc/X11/${FILE} ${SW_ROOT_DIRECTORY}etc/X11/
	fi
done

#
# swmodify the GAGTAR file out of existence so the
# patch can be swverified.
#
GAGTAR="/opt/graphics/common/doc/GAG/GAG-11.0.tar"
swlist -l fileset | grep X11-SERV-MAN > /tmp/swlist.out
while read line
do
    prod_fs=`echo $line | awk ' { print $1 } '`
    swlist -l file ${prod_fs} | grep ${GAGTAR} > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        swmodify -uxfiles=${GAGTAR} $prod_fs
    fi
done < /tmp/swlist.out
rm -f /tmp/swlist.out

exit $exitval
