#! /sbin/sh
########
# Product: OS-CORE
# Fileset: KERN-RUN
# checkinstall
# @(#) $Revision: 1.3.98.1 $
#########
#
# (c) Copyright Hewlett-Packard Company, 1994
#
#########

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

. $UTILS

exitval=$SUCCESS		# Preset to everything is alright.

if [[ -n "$KERN_DEBUG" ]]; then	# Turn on debugging
    PS4='    + ${0##*/}:$LINENO -> '
    set -x
    BOOTFUNC=/CTL_TEST/KERN-RUN/bootlif_funcs
else
    BOOTFUNC=${SW_CONTROL_DIRECTORY}/bootlif_funcs
fi

if [[ ! -f $BOOTFUNC ]]; then
    print "ERROR: Cannot find the sh functions library $BOOTFUNC."
    exit $FAILURE
fi

. $BOOTFUNC		# sets BOOTCONF & the ReadBoot exitvalues as side effect

#########################
#                       #
# Function Declarations #
#                       #
#########################

########
# sd_msg - stolen tt_tools function used to allow the shell library
#          bootlif_funcs to use the standard approved tt_tools output
#          format.
#
# Output a message in a format compatible with the SD guidelines.
# The output is written to standard out.
#
# Usage: sd_msg [-e|-p|-w|-b] word [...]
#        text | sd_msg [-e|-p|-w|-b]
#   
#   -e  prefix the message with "ERROR:  "
#   -p  prefix the message with "ERROR:  " (hard coded to SD compatibility.)
#   -w	prefix the message with "WARNING:" (hard coded to SD compatibility.)
#   -b  prefix the message with "        " (blanks)
#
#   otherwise the message is prefixed with "NOTE:" and is line wrapped if
#   it extends beyond column 72. Remember to escape special shell characters
#   in "word".
#
#   sd_msg will accept message text which is piped in also.
#
sd_msg ()
{
    typeset -L8 MSGTYPE="NOTE:"
    typeset -L8 BLANKS=""
    typeset MSG
    typeset word
    typeset len
    typeset LINE
    typeset MSG_TYPE

    case $1 in
	-w) MSGTYPE="WARNING:"
            shift
	    ;;
        -e) MSGTYPE="ERROR:"
            shift
	    ;;
        -p) MSGTYPE="ERROR:"
            shift
	    ;;
        -b) MSGTYPE=""
            shift
	    ;;
    esac
    
    MSG_TEXT=""
    MSG="${MSGTYPE}"

		#
		# The message text is on the command line.
		#
    if [[ $# > 0 ]]
    then
        MSG_TEXT=$@
		#
		# The message text is being piped in.
		#
    else
        while read -r LINE
        do
                MSG_TEXT="${MSG_TEXT} ${LINE}"
        done
    fi
    for word in $MSG_TEXT
    do
        (( len = ${#MSG} + ${#word} ))
        if (( len > 72 ))
        then
                print - "${MSG}"
                MSG="${BLANKS}"
        fi
        MSG="${MSG} ${word}"
    done

    print - "${MSG}"
}

################
#	       #
# Main Program #
#              #
################

#
# Test to verify that a boot LIF may be found.
#

BootAreas=`FindBoot $BOOTCONF $SW_ROOT_DIRECTORY`	# Function handles error messages
Result=$?

case $Result in 
    $FAILURE)		exit $FAILURE
			;;
    $ALT_ROOT_FAILURE)
			print "NOTE:    Installing to an alternate root that isn't a mount point"
			print "         ($SW_ROOT_DIRECTORY). The boot area(s) will not be updated."
			exit $SUCCESS
			;;
    $LVM_SUCCESS)	Flag=l
			exitval=$SUCCESS
			;;
    $WHOLE_SUCCESS)	Flag=w
			exitval=$SUCCESS
			;;
    $PARTITION_SUCCESS) Flag=p
			exitval=$SUCCESS
			;;
    $LVM_WARNING)	Flag=l
			exitval=$WARNING
			;;
    $WHOLE_WARNING)	Flag=w
			exitval=$WARNING
			;;
    $PARTITION_WARNING)	Flag=p
			exitval=$WARNING
			;;
esac

if [[ -z "$BootAreas" ]]; then
    print "ERROR:   No updatable boot areas found on the the root disk."
    exit $FAILURE
elif [[ ! -f $BOOTCONF ]]
then
    PutConfig $BOOTCONF $Flag $BootAreas
    if [[ $? -ne 0 ]]; then
	print "WARNING: Could not save boot area information in $BOOTCONF."
	exitval=$WARNING
    fi
fi

exit $exitval

