#! /sbin/sh
###############
# Product: OS-Core
# Fileset: CORE_KRN
# postinstall
# @(#) $Revision: 1.3.98.2 $
################
#
# (c) Copyright Hewlett-Packard Company, 1994
#
########################################################################
#                                                                      #
# General requirements:                                                #
#                                                                      #
# 1) Create /dev/rroot for /sbin/pre_init_rc.                          #
#                                                                      #
# 2) Propagate and translate names of drivers from the "old" dfile     #
#    to the "new" dfile.   NOT YET IMPLEMENTED - may be in preinstall. #
#                                                                      #
# 3) Create /dev/config for autoconfig, if needed.		       #
#                                                                      #
# 4) Turn the tunable DEFAULT_DISK_IR to ON for 700's.                 #
#								       #
########################################################################

# The global variables SUCCESS, FAILURE, WARNING, EXCLUDE, PATH, ROOT,
# SW_CTL_SCRIPT_NAME, _pf, PRODUCT, and FILESET are all set by control_utils.

UTILS=/usr/lbin/sw/control_utils
if [[ ! -f $UTILS ]]
then
    print "ERROR:   Cannot find the sh functions library $UTILS."
    exit $FAILURE
fi
. $UTILS

# Variable declarations.

exitval=$SUCCESS                # Anticipate success
VERBOSE=""			# Debugging flag

RROOT=${SW_ROOT_DIRECTORY}dev/rroot		# raw root device.
CONFIG=${SW_ROOT_DIRECTORY}dev/config		# /dev/config - used by S800 autoconfigurator

########################################################
# Only modify the system file on the root file system. #
# If this is an NFSdiskless installation, or alternate #
# root, then configure will handle it.                 #
########################################################

if [[ -z "${SW_DEFERRED_KERNBLD}" ]]
then
   
    #####################################################
    #							#
    # 1) Create /dev/rroot for (we always re-create it, #
    #    to be sure that it is correct).                #
    #							#
    #####################################################

    if [[ -n "${VERBOSE}" ]]
    then
        print "NOTE:    Remaking ${RROOT}"
    fi

    rm -f $RROOT
    mknod $RROOT c 255 0xffffff
    chmod 644  $RROOT
    chown root $RROOT
    chgrp sys  $RROOT

    #################################################
    #						    #
    # 2) Translate driver names from the old format #
    #    to the new one and truncate the system     #
    #    file to core drivers only.                 #
    #						    #
    #################################################

    typeset -i OldSys=$(uname -r | grep 'B.10.20' | wc -l) # 1 if release 10.20, 0 otherwise

    if [[ $OldSys -eq 0 || -n "$SW_INITIAL_INSTALL" ]]
    then
	/usr/lbin/sysadm/truncate_sys -m ${SW_ROOT_DIRECTORY}usr/conf/master.d/core-hpux -s ${SW_SYSTEM_FILE_PATH}
	if [[ $? -ne 0 ]]
	then
	    exitval=$FAILURE
	fi
    fi

    ##########################################
    #                                        #
    # 3) Create /dev/config for autoconfig.  #
    #                                        #
    ##########################################

    if [[ ! -c ${CONFIG} ]]   # Does config file already exist ?
    then
	if [[ -n "${VERBOSE}" ]]
	then
	    print "NOTE:    Creating ${CONFIG}."
	fi

	rm -f $CONFIG	# Just in case something other than a character device is here.
	mknod ${CONFIG} c 69 0
	chown root ${CONFIG}
	chgrp sys  ${CONFIG}
	chmod 644  ${CONFIG}    # rw-r--r--
    fi # [[ ! -c ${CONFIG} ]]

    ######################################################
    #							 #
    # 4) Change DEFAULT_DISK_IR tunable to ON (700 only) #
    #							 #
    ######################################################

    if [[ $( get_arch ) = "700" ]]; then
	value="$( query_systemfile ${SW_SYSTEM_FILE_PATH} "default_disk_ir" )"
	if [[ $? -ne 0 ]]; then
	    exitval=$FAILURE	# Only fails if system file unreadable - query_systemfile handles messages.
	else
	    mod_systemfile ${SW_SYSTEM_FILE_PATH} -d DEFAULT_DISK_IR
	    if [[ -z "$value" ]]; then					# Don't reset if there currently is a value.
		mod_systemfile ${SW_SYSTEM_FILE_PATH} -t "default_disk_ir" 1
		if [[ $? -ne 0 ]]; then
		    print "WARNING: The tunable paramater \"default_disk_ir\" has been left OFF. This may"
		    print "         result in lower performance for some SCSI devices."
		    exitval=$WARNING
		fi # [[ $? -ne 0 ]]
	    fi # [[ -z "$value" ]]
	fi # [[ $? -ne 0 ]]
    fi # [[ "$(get_arch)" = "700" ]]

    #############
    # Finished. #
    #############

fi	# end of "if [[ -z ${SW_DEFERRED_KERNBLD}" ]]

exit $exitval
