# $Source: /usr/local/kcs/sys.DAVIS_800/kconf/RCS/kernsize,v $
# $Revision: 1.3.98.1 $       $Author: root $
# $State: Exp $       $Locker:  $
# $Date: 95/07/20 10:39:15 $

# @(#) kernsize $Revision: 1.3.98.1 $

## This script is to be called from HP-UX kernel makefile only.
## No usage message, or other niceties

# Right justify (must be strings to justify, not ints)
# The math functions below should catch any non-numbers.
typeset -R10 actual limit maxlimit

maxlimit=0
limit=0
actual=0

while getopts "a:l:m:" opt "$@"
do
  case "$opt" in
    a) actual="${OPTARG##*= }"	     # Pull last field from 'size' output
	;;
    l) limit="$OPTARG"
	;;
    m) maxlimit="$OPTARG"
	;;
  esac 
done

if (( actual <= 0 || limit <= 0 ))
then
  print -u2 "ERROR:   $0 called incorrectly"
  exit 2
fi

if (( actual > limit ))
then
  if (( maxlimit > 0 ))
  then
    if (( actual > maxlimit ))
    then
      print -u2 "ERROR:   Kernel is too large to boot with the PBO loader."
      print -u2 "         Actual:  $actual bytes"
      print -u2 "         Limit:   $maxlimit bytes"

      exit 1
    else
      print -u2 "WARNING: Kernel is too large to boot with the standard loader."
      print -u2 "         The special PBO loader must be used."
      exit 0
    fi
  fi

  print -u2 "ERROR:   Kernel is too large to boot."
  print -u2 "         Actual:  $actual bytes"
  print -u2 "         Limit:   $limit bytes"

  exit 1
fi

exit 0
