#!/bin/ksh
#
#ident	"@(#)reqcheck	1.19	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

hname=$1
technology=$2
option=$3
i=0
memflg=0
cpuflg=0
swapflg=0
totalswap=0 #add for multiswap 
err=0
#clean duplicate code for hcts 2.4 workspace 
sysdir=/opt/SUNWstaf/prgs/si

DIR=bin #added for getting sysinfo by using sysconf function

clean_up()
{
	rm -f /tmp/sysinfo
}

if [ $# -lt 2 ]
then
	echo "!ERROR: $0 <hostname> <technology> [ <option> ]"
	echo "!ERROR: $0 called with bad arguments."
	exit 1
fi

#rsh -l root $hname $sysdir/$DIR/kvars -mu > /tmp/sysinfo # modify for separately getting system info from solaris 9 or 10
rsh -l root $hname $sysdir/$DIR/all_devices -mu > /tmp/sysinfo #added for getting sysinfo by using sysconf function

memory=`/usr/sbin/prtconf | grep 'Memory size:' | awk '{print $3}'`

if [ $memory -lt 256 ]; then
	memflg=1
	err=`expr $err + 1`
fi

cpu=`cat /tmp/sysinfo | grep 'CPU speed:' | awk '{print $3}'` #added for getting sysinfo by using sysconf function
numcpu=`cat /tmp/sysinfo | grep 'Number of CPUs:' | awk '{print $4}'`

if [ $cpu -lt 450 ]; then
	cpuflg=1
	err=`expr $err + 1`
fi

swap=`cat /tmp/sysinfo | grep 'Swap area' | awk '{print $5}'`

#modified for multiswap and different solaris version 

for i in $swap
do
  	totalswap=`expr $totalswap + $i`
done


version=`/usr/bin/uname -r|awk -F. '{print $2}'`
if [  $version -lt 9  ]
then
   		if [ $totalswap -lt 256 ]; then
		swapflg=1
		err=`expr $err + 1`
	fi
else
   		if [ $totalswap -lt 512 ]; then
		swapflg=1
		err=`expr $err + 1`
	fi
fi
#end modified

clean_up
	
if [ $err -gt 0 ]; then
	
	if [ $memflg -gt 0 ]; then
		echo "<b>!ERROR:</b> Your system does not have enough memory. "
		echo "You need at least 256 megabytes of RAM to run this test suite.<br>"
	fi

	if [ $cpuflg -gt 0 ]; then
		echo "<b>!ERROR:</b> The CPU on your system is too slow. "
		echo "Use a system with at least a single 450 MHZ processor. "
		echo "Hardware floating point support is required."
	fi

	if [ $swapflg -gt 0 ]; then
		echo "<b>!ERROR:</b> Your system does not have enough swap space. "
		if [  $version -lt 9  ]
		then
			echo "Allocate at least 256 megabytes for "
		else
			echo "Allocate at least 512 megabytes for "
			
		fi
		echo "swap slice when installing Solaris.<br>"
	fi

	exit 1
fi

