#!/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 preinstall script template for 11.X patches.                  #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to prepare the system for installation of the patch.   #
#------------------------------------------------------------------#

_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 preinstall #####################

########################## 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 ######################

	##
	## Unregister SAM
	##

	SAM_DIR=${SW_ROOT_DIRECTORY}usr/lib/X11/Xserver/misc/sam
	SAMREG=/usr/sam/bin/samreg


	$SAMREG -u $SAM_DIR >/dev/null 2>&1

	##
	## Save /etc/X11 stuff in case of swremove
	##

	if [ ! -d ${SW_ROOT_DIRECTORY}usr/old/etc/X11 ]
	then
		mkdir -p ${SW_ROOT_DIRECTORY}usr/old/etc/X11
		chmog 555 bin bin ${SW_ROOT_DIRECTORY}usr/old/etc/X11
	fi

	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}etc/X11/${FILE} ${SW_ROOT_DIRECTORY}usr/old/etc/X11/
		fi
	done

echo "" > /opt/graphics/common/doc/GAG/GAG-11.0.tar 
swmodify -xfiles="/opt/graphics/common/doc/GAG/GAG-11.0.tar" Xserver.X11-SERV-MAN
#################### end preinstall ######################

exit $exitval
