#!/sbin/sh
#############################
# Product: DesktopConfig
# Fileset: LITECONFIG
# preremove
# @(#) $Revision: 1.3.98.1 $
#############################
#
# (c) Copyright Hewlett-Packard Company, 1993
#
################################################################################
#                            
# Setup general environment. 
#                           
################################################################################

UTILS="/usr/lbin/sw/control_utils"
if [[ ! -f $UTILS ]]
then
	print "ERROR:   Cannot find $UTILS"
	exit 1
fi
. $UTILS
exitval=$SUCCESS			# Anticipate success


################################################################################
#
# Perform system file "un-lite" modifications.
# We can only modify the system file if this isn't an alternate root swremove. 
#
# NOTE: Because swremove doesn't support kernel rebuilds, the system file
# is *not* actually modified.  Because of this limitation, the best we can do 
# is to instruct the user (via the swagent.log file) how to *manually* restore 
# the system file to its original "un-lite'ned" state.  
#			      
################################################################################

if [[ "${SW_ROOT_DIRECTORY}" = "/" ]]; then
	#
	# Verify the existence of the lite_config utility.
	#
	LITE_CONFIG="${SW_CONTROL_DIRECTORY}/lite_config"
	if [[ ! -x ${LITE_CONFIG} ]]; then
	    print "ERROR:   Internal error: cannot execute $LITE_CONFIG."
	    print "         This is a fatal swinstall error and should be"
	    print "         reported to the appropriate HP customer support"
	    print "         representative."
	    exit $FAILURE
	fi

	#
	# Since swremove doesn't extract the system file, we do it here.
	# If the extracted system file is different than $SW_SYSTEM_FILE_PATH, 
	# then use the extracted system file instead.  
	# Note that normally $SW_SYSTEM_FILE_PATH should match the kernel. 
	#
	SYSFILE=$SW_SYSTEM_FILE_PATH
	TEMP_SYSFILE="/tmp/system$$"
	GET_SYSFILE="/usr/lbin/sysadm/get_sysfile"
	rm -f $TEMP_SYSFILE 2>/dev/null
	$GET_SYSFILE $SW_KERNEL_PATH > $TEMP_SYSFILE 2>/dev/null && \
	if [[ -n "`cmp $SYSFILE $TEMP_SYSFILE 2>&1`" ]]; then
		# The system files are different- use the extracted one.
		SYSFILE=$TEMP_SYSFILE
		print "NOTE:    The system file has been extracted from the"
		print "         \"$SW_KERNEL_PATH\" kernel and placed in"
		print "         \"$TEMP_SYSFILE\"."
	fi
	# Cleanup $TEMP_SYSFILE if necessary
	[[ $SYSFILE = $SW_SYSTEM_FILE_PATH ]] && rm -f $TEMP_SYSFILE 2>/dev/null

	#
	# Invoke lite_config.
	# lite_config prints an appropriate warning message and then lists 
	# the various driver(s) to be added back to the system file as well 
	# as all "lite" tunable parameters that need to be deleted from the 
	# system file.  To highlight this to the user, lite_config exits with 
	# a $WARNING status.
	#
	${LITE_CONFIG} -u -s $SYSFILE 2>/dev/null
	status=$?
	[[ $status -ne 0 && $exitval -ne $FAILURE ]] && exitval=$status
fi
exit $exitval
