#!/sbin/sh
#############################
# Product: DesktopConfig
# Fileset: LITECONFIG
# verify
# @(#) $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

#
# Setup variables
#
LOGD="/var/adm/liteconfig"
IS_LITE="/usr/bin/is_lite"
CONFDIR="/etc/rc.config.d"


################################################################################
#
# First check for the presence of the DesktopConfig saved configuration files.
# Since verify scripts are *only* run if the fileset is in the CONFIGURED state
# and this is *not* an alternate root installation, all of the saved 
# configuration files should already be present in the 
# /var/adm/liteconfig directory.
#
################################################################################

# Check for the existence of the LITECONFIG logging directory.
if [[ ! -d ${LOGD} ]]; then
	print "WARNING: The \"${LOGD}\" logging directory does not exist."
	print "         All \"lite\" changes previously made to the system"
	print "         have not been saved away."
	[[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
fi

# Check for the existence of the "removed drivers" log file.
if [[ ! -f ${LOGD}/RemovedDrivers ]]; then
	print "WARNING: The \"${LOGD}/RemovedDrivers\" log file does not"
	print "         exist.  This file lists the optional drivers that have"
	print "         been removed from \"${SW_SYSTEM_FILE_PATH}\" as a"
	print "         result of installing \"$PRODUCT\"."
	[[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
fi

# Check for the existence of the "reduced tunables" log file.
if [[ ! -f ${LOGD}/ReducedTunable ]]; then
	print "WARNING: The \"${LOGD}/ReducedTunable\" log file does not"
	print "         exist.  This file lists the kernel tunable parameters"
	print "         that have been reduced in \"${SW_SYSTEM_FILE_PATH}\""
	print "         as a result of installing \"$PRODUCT\"."
	[[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
fi

# Check for the existence of the "saved rc.config.d" log file.
if [[ ! -f ${LOGD}/SavedRcConf ]]; then
	print "WARNING: The \"${LOGD}/SavedRcConf\" log file does not"
	print "         exist.  This file lists those subsystems (or daemons)"
	print "         that have been disabled as a result of installing"
	print "         \"$PRODUCT\".  It is not possible to determine if the"
	print "         configuration files located in the \"$CONFDIR\""
	print "         directory are \"lite\"."
	[[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
fi

# Issue summary warning message
if [[ $exitval -eq $WARNING ]]; then
	print "WARNING: Because of the above warning(s), this will allow"
	print "         subsequent swinstall's of \"$PRODUCT\" to completely"
	print "         re-install the above indicated portion(s) of the"
	print "         \"Lite HP-UX Configuration\" to the system."
fi


################################################################################
#
# Verify that the kernel itself is indeed "lite".
# We invoke the "is_lite" utility to do the actual analysis;
# is_lite returns an exit status of "0" if at least *one* kernel tunable
# parameter is found to be lite.  
#
################################################################################

status=0			# Assume success
if [[ -x $IS_LITE ]]; then

	# Run is_lite utility and print appropriate status
	$IS_LITE -k $SW_KERNEL_PATH 2>/dev/null
	status=$?
	if [[ $status -eq 0 ]]; then
	    print "NOTE:    The \"$SW_KERNEL_PATH\" kernel is \"lite\"."
	    print "         For more details, invoke the \"$IS_LITE\" command"
	    print "         as follows:"
	    print "         $IS_LITE -k $SW_KERNEL_PATH -v"
	
	# Kernel isn't lite
	elif [[ $status -eq 1 ]]; then
	    print "WARNING: The \"$SW_KERNEL_PATH\" kernel is not considered"
	    print "         \"lite\".  If you wish to correct this, you must"
	    print "         perform a complete swremove of \"$PRODUCT\","
	    print "         followed by a swinstall of \"$PRODUCT\"."
	    [[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
	fi
fi

# Check for fatal errors and report
if [[ ! -x $IS_LITE || $status -eq 2 ]]; then
	print "ERROR:   Error executing \"$IS_LITE\".  It is not possible"
	print "         to determine if the \"$SW_KERNEL_PATH\" kernel is"
	print "         \"lite\"."
	exitval=$FAILURE
fi


################################################################################
#
# Verify that the /etc/rc.config.d/<subsystem> files are "lite".
# Unlike the kernel verification portion above, we print out the state 
# of each subsystem.  This is because the is_lite command doesn't support
# subsystems (and hence can't display detail on them).
#
################################################################################

if [[ -f ${LOGD}/SavedRcConf ]]; then
	#
	# Query the state of each subsystem listed in the
	# "saved rc.config.d" log file.
	#
	while read configfile var prevval tunedval junk
	do
		# Skip over leading comments.
		[[ "$configfile" = "#" ]] && continue

		# If configuration file doesn't exist- skip to next one
		rccfg=${CONFDIR}/${configfile}
		[[ ! -f $rccfg ]] && continue

		#
		# Query the state of the control variable.
		# Use the ch_rc(1m) utility.
		#
		curval=`ch_rc -l -p $var $rccfg`
		if [[ $? -ne 0 ]]; then
		    print "ERROR:   Error accessing \"$rccfg\".  Cannot"
		    print "         determine if the \"$rccfg\" configuration"
		    print "         file is \"lite\"."
		    exitval=$FAILURE
		    continue
		fi

		#
		# Print out state of control variable.
		#
		if [[ $curval -eq $tunedval ]]; then
		print "NOTE:    \"$var\" is set to \"$curval\" in \"$rccfg\"."
		print "         This means that \"$var\" subsystem is disabled."

		else
		print "WARNING: \"$var\" is set to \"$curval\" in \"$rccfg\"."
		print "         This means that \"$var\" subsystem is enabled."
		[[ $exitval -ne $FAILURE ]] && exitval=$WARNING		
		fi
	done < ${LOGD}/SavedRcConf
fi


################################################################################
#
# Finished (return $exitval status).
#
################################################################################
exit $exitval 
