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


################################################################################
#
# The following safety checks attempt to prevent the loading of DesktopConfig
# to multi-user systems, servers, etc.  In addition, these checks prevent
# DesktopConfig from being loaded in the event the user selects the 
# "Load All Filesets" option during a cold-install or specifies wild-card ("\*")
# software selections during a normal swinstall session.
#
# The current algorithm is to not install (i.e., exit $EXCLUDE) DesktopConfig 
# if the following filesets (*only* present in the Run-Time HP-UX product) 
# have either been selected for loading --or-- are already present on disk.
# Note that in order to minimize checkinstall overhead, we only check a few
# critical filesets that would generally be mutually exclusive with 
# DesktopConfig and that would serve to identify the intended use of the system.
#
# Note: We do not check for NFS.NFS-SERVER since this fileset may be manually
# added by the customer to an existing Desktop HP-UX system.
#
################################################################################

for fileset in			\
	UserLicense.32-USER  	\
	NFS.NIS-SERVER		\
	X11.X11-FONTSRV
do
	# If this fileset is selected for installation -- abort !
	if is_software_selected "$fileset"; then
	    print "NOTE:    \"$PRODUCT\" excluded from installation."
	    print "         Cannot safely install \"$PRODUCT\" onto the system"
	    print "         at the same time \"$fileset\" is being installed."
	    print "         To correct this problem, you must de-select"
	    print "         \"$fileset\" and then install \"$PRODUCT\"."
	    print "         You can alternatively run SAM.  See WARNING below."
	    [[ $exitval -ne $FAILURE ]] && exitval=$EXCLUDE
	fi

	#
	# If this isn't an alternate root install, 
	# then if this fileset is already installed on disk -- abort !
	#
	if [[ "${SW_ROOT_DIRECTORY}" = "/" ]]; then
	    state=`get_install_state "$fileset"`
	    [[ "$state" = "not found" ]] && continue
	    print "NOTE:    \"$PRODUCT\" excluded from installation."
	    print "         Cannot safely install \"$PRODUCT\" onto the system"
	    print "         because \"$fileset\" is already installed." 
	    print "         To correct this problem, you must remove"
	    print "         \"$fileset\" from the system and then install"
	    print "         \"$PRODUCT\".  You can alternatively run SAM."
	    print "         See WARNING below."
	    [[ $exitval -ne $FAILURE ]] && exitval=$EXCLUDE
	fi
done


################################################################################
#
# Query the kernel configuration of the system looking for fairly large values 
# of a couple key tunable parameters.  Should these tunables exceed the 
# limits defined below, we conclude that the system is being used in more
# of a multi-user fashion and will EXCLUDE DesktopConfig from installation.
#
# This is also done because several of the tunables that are "lite'ned" by
# DesktopConfig must generally scale with each other -- reducing the values
# of only *some* of these tunables may worsen the system by creating a resource
# imbalance problem.  
#
################################################################################

#
# Extract/query the system file if this is not a cold-install nor an 
# alternate root install.  
#
SYSTEMFILE="/tmp/systemfile$$"
GET_KDFILE="/usr/lbin/sysadm/get_kdfile"
GET_SYSFILE="/usr/lbin/sysadm/get_sysfile"
if [[ -z "${SW_INITIAL_INSTALL}" && "${SW_ROOT_DIRECTORY}" = "/" ]]; then

	#
	# Extract the system file.
	# Run get_kdfile if its present 
	# (for either pre-10.0 or pre-cycleR kernels).
	# If it isn't present (or it fails), then run get_sysfile.
	#
	status=0
	rm -f $SYSTEMFILE 2>/dev/null
	if [[ -x $GET_KDFILE ]]; then
		$GET_KDFILE $SW_KERNEL_PATH > $SYSTEMFILE 2>/dev/null
		status=$?
	fi
	if [[ ! -x $GET_KDFILE || $status -ne 0 ]]; then
		$GET_SYSFILE $SW_KERNEL_PATH > $SYSTEMFILE 2>/dev/null
		status=$?
	fi

	# Exit if errors from system file extraction
	if [[ $status -ne 0 ]]; then
		print "ERROR:   Cannot read kernel configuration information"
		print "         from \"$SW_KERNEL_PATH\"."
		rm -f $SYSTEMFILE 2>/dev/null
		exit $FAILURE
	fi

	#
	# Look for the following tunables explicitly set in the system file:
	#	* maxusers > 64  (default is 32)
	#	* nproc    > 400 (default is 276)
	#
	for tunable in 		\
		maxusers=64 	\
		nproc=400 
	do
	    param=${tunable%%=*}
	    limit=${tunable##*=}
	    curval=`query_systemfile $SYSTEMFILE $param`
	    [[ ${curval:=0} -le $limit ]] && continue
	    print "NOTE:    \"$PRODUCT\" excluded from installation."
	    print "         Cannot safely install \"$PRODUCT\" onto the system"
	    print "         because the tunable parameter \"$param\" is greater"
	    print "         than \"$limit\" in the \"$SW_KERNEL_PATH\" kernel."
	    print "         To correct this problem, you must reduce the value"
	    print "         of the \"$param\" tunable, re-build the kernel, and"
	    print "         then install \"$PRODUCT\".  You can alternatively"
	    print "         run SAM.  See WARNING below."
	    [[ $exitval -ne $FAILURE ]] && exitval=$EXCLUDE
	done

	# Cleanup
	rm -f $SYSTEMFILE 2>/dev/null
fi


################################################################################
#
# Finished (return $exitval status).
# Print exiting messages if we're excluding DesktopConfig.
#
################################################################################

if [[ $exitval -eq $EXCLUDE ]]; then
	print "WARNING: \"$PRODUCT\" is generally only intended for use with"
	print "         single-user Series 700 systems installed with the"
	print "         \"Desktop HP-UX\" product.  Installing \"$PRODUCT\""
	print "         will result in a kernel that is built with a reduced"
	print "         (minimal) set of kernel tunable parameters appropriate"
	print "         for only single-user desktop environments.  See the"
	print "         on-line swinstall product descriptions of \"$PRODUCT\"."
	print "         If you still wish to install \"$PRODUCT\", then correct"
	print "         the problem(s) shown above and install it again,"
	print "         -or- run the SAM utility and select the \"Apply Lite"
	print "         HP-UX Configuration\" Action from within any of SAM's"
	print "         Kernel Configuration screens."
fi
exit $exitval 
