#!/bin/ksh
#
#ident	"@(#)tech_check	1.26	05/06/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#


hctsdir=SUNWhcts            # base directory
prgdir=prgs             # program directory
act=                    # action to be taken
bname=`basename $0`     # shell name
gotocgi="http://$HTTP_HOST/cgi-bin/$hctsdir/`basename $0`"      # program name
i=0                     # loop counter
mdir=menu               # menu directory
rdir=results		# results directory
hname=                  # test system
option=                 # option selected
fdir=forms              # forms directory
dname=                  # display system
stafdir=/opt/SUNWstaf
count=0
technology=
tmpdir=/tmp		# directory for temp files
remotemachine=
usbtest="/tmp/usbtest"



lvfile=$tmpdir/level.dat
stfile=$tmpdir/suite.dat
tcfile=$tmpdir/technology.dat
opfile=$tmpdir/option.dat

i6file=/tmp/ipv6.dat	#if this file exists, then means ipv6 test enabled. by bill

csfile=$tmpdir/clientstatus.dat	#clients listed in it should be displaied in status bar, added by Matthew on 2004.09.26

if [ -s $stfile ]
then
    suite=`cat $stfile`
fi


# functions

# do function
go_fun()
{
        $prgdir/funcs "$*" 2>&1
}

### MAIN ###

# change to base directory
cd `dirname $0`
while [ `basename $PWD` != $hctsdir ]
do
        cd ..
done

# parse input
if [ -n "$CONTENT_LENGTH" ]
then
        eval `$prgdir/pq.p`
        CONTENT_LENGTH=
fi

# to fix 5005395, will putback in 2.4
#is_console=`$prgdir/is_console.sh`
#if [ ! $is_console ]
#then
#	if [ -n "$hostn" ]
#	then
#		hname=$hostn
#	fi
#	go_fun bhtml $hname $0 $technology
#	go_fun err_pg "You are not console now."
#	go_fun ehtml
#	exit 1
#fi

if [ ! -d $rdir/$hname ]
then
	mkdir -p $rdir/$hname

	if [ $? -ne 0 ]
	then
		go_fun bhtml $0
		go_fun err_pg "Cannot make output directory -> $rdir/$hname"
		go_fun ehtml
		exit 1
	fi
	
	$fdir/cforms $rdir/$hname
	
fi

echo "$level" > $lvfile
echo "$hname" > $rdir/$hname/.dname.dat

if [[ -n $option && $option = usbdisk ]]; then
    touch $usbtest
else
    rm $usbtest 2>/dev/null
fi

echo "$option" > $opfile
if [ $suite = CC ]; then

	if [ -z $option ]; then
		go_fun bhtml $hname $0
		go_fun err_pg "Go back and select one of the technologies."
		go_fun ehtml
		exit 1

	elif [ $option = scsi ] || [ $option = fibre ] || [ $option = raid ] || [ $option = usbdisk ] || [ $option = sata ]; then
		technology=storage
		echo "$technology" > $tcfile

		$prgdir/reqcheck $hname $technology $option > $tmpdir/errors 2>&1
		if [ $? -ne 0 ]; then
			go_fun bhtml $hname $0 $technology
			go_fun err_pg
			cat $tmpdir/errors
			rm $tmpdir/errors
			rm $tmpdir/diskinfo
			go_fun ehtml
			exit 1
		fi

		exec ./slice_conf $hname $option $technology
		exit 0

	elif [ $option = fast ] || [ $option = gigabit ]; then

			#rm $i6file 
		if [ -e $i6file ]
		then
			rm $i6file > $tmpdir/errors 2>&1
			if [ $? -ne 0 ]; then
				go_fun bhtml $hname $0
				go_fun err_pg
				cat $tmpdir/errors
				rm $tmpdir/errors
				go_fun ehtml
				exit 1
			fi
		fi

		if [ ! -z $ipv6 ]
		then
			if [ $ipv6 = ipv6 ]
			then
				touch $i6file
			fi
		fi
			
		technology=network
		echo "$technology" > $tcfile

		$prgdir/reqcheck $hname $technology > $tmpdir/errors 2>&1 
		if [ $? -ne 0 ]; then
			go_fun bhtml $hname $0
       			go_fun err_pg
			cat $tmpdir/errors
			rm $tmpdir/errors
			go_fun ehtml
			exit 1
		fi
	
	
	elif [ $option = "saip" ]; then
		technology=serial
		echo "$technology" > $tcfile
		
		if [ -n "$remotemachine" ]; then
			echo "$remotemachine" > /tmp/pclient
			echo "$remotemachine" > /tmp/rhnames
			echo "$remotemachine" > $csfile
			rhname=`echo $remotemachine`
		else
			go_fun bhtml $hname $0
       			go_fun err_pg "!ERROR: ppp-client name is missing. Click Back button and enter ppp-client name."
       			go_fun ehtml
       			exit 1
       		fi

		$prgdir/reqcheck $hname $technology > /tmp/errors 2>&1 
		if [ $? -ne 0 ]
		then
		        go_fun bhtml $hname $0
       			go_fun err_pg
			cat /tmp/errors
			rm /tmp/errors
			go_fun ehtml
			exit 1
		fi

		$prgdir/devidio.sh $remotemachine $rhname > /tmp/errors 2>&1 
		if [ $? -ne 0 ]
		then
		        go_fun bhtml $hname $0
       			go_fun err_pg
			tail -1 /tmp/errors
			rm /tmp/errors
			go_fun ehtml
			exit 1
		fi
	fi
		
#	exec $mdir/menu2 $hname $option $technology
	
elif [ $suite = SC ]; then
	#add for motherboard certification 

	if [ -z $option ]; then
		go_fun bhtml $hname $0
		go_fun err_pg "Go back and select one of the test items."
		go_fun ehtml
		exit 1
	fi
	#add end
	technology="system"
	$prgdir/reqcheck $hname $technology > /tmp/errors 2>&1
	if [ $? -ne 0 ]
	then
		go_fun bhtml $hname $0
		go_fun err_pg
		cat /tmp/errors
		rm /tmp/errors
		go_fun ehtml
		exit 1
	fi
	
	rm -f $tmpdir/opt

		
#	if [ -z "$coption" ]; then
#		echo "cdrom" > $tmpdir/opt
#	fi
	
  	if [ $option = system ] #Modified for motherboard certification 
	then	
		if [ -z "$zoption" ]; then
		echo "zip" >> $tmpdir/opt	
		fi
	fi
	
#	if [ -z "$toption" ]; then
#		echo "tape" >> $tmpdir/opt
#	fi
	
#	if [ -z "$foption" ]; then
#		echo "floppy" >> $tmpdir/opt
#	fi
		
#	technology=stress #comment for motherboard certification 
	#add for motherboard certification 
	if [ $option = system ]
	then	
		technology=system
	elif [ $option = motherboard ]
	then
		technology=motherboard
	fi
	#end add 

#	option=stress	#comment for motherboard certification 2004/09/06
	echo "$option" > $opfile #comment for motherboard certification 2004/09/06
	echo "$technology" > $tcfile

#	exec $mdir/menu1 $hname

	exec ./slice_conf $hname $option $technology
	exit 0
fi

exec ./test_opt $hname $option $technology
	
