#@(#)input	1.11 04/29/99 11:21:17


####
##
## This program process user input.
##
## Return Values:
## 	0 - explorer will start gathering system information
##	1 - explorer will stop processing, this may be due to error or
##		as a result of selecting -help or -v
##
####



# if more than 5 parameters passed stop. The most parameters is:
# -file file_name -myemail email_address -keep
if [ "$#" -gt 5 ]
then
    echo 
    echo
    echo "Too many parameters passed"
    echo "For usage see:"
    echo "     explorer -help"
    echo
    exit 1
fi

BATCH_MODE=false
export BATCH_MODE

KEEP=false
export KEEP

E10000_return_fru=false
export E10000_return_fru

# cycle through all of the input parameters, and process them
while [ "$#" -ne 0 ]
do
    case "$1" in
	-E10000_return_fru | -e10000_return_fru)
	    # this is to collect all the necessary information for
	    # E10000 returned bad parts. This will always run in
	    # interactive mode so we can get the questionnaire filled.
	    # This option will be executed only on the SSP
	    if [ ! -d /var/opt/SUNWssp ]
	    then
	       # not a SSP system. Assumptions is: SSPVAR=/var/opt/SUNWssp
	       echo 
	       echo
	       echo "The -E10000_return_fru option can be executed only on a"
	       echo "System Service Processor unit"
	       echo
	       exit 0
	    fi
	    E10000_return_fru=true
	    export E10000_return_fru
	    BATCH_MODE=false
	    export BATCH_MODE
	    touch .e10000-fru
	    break 2
	    ;;

	-file)
	    # get file name, it is the next paramerer following -file
	    shift
	    INPUT_FILE=$1

	    # cd into the parent dir is necessary in case the user
	    # specifies an input file with relative path to the
	    # parent dir.
	    cd ..
	    # input_file with data means -file was selected
	    cp -p $INPUT_FILE $DIRNAME/input_file
	    STATUS=$?
	    if [ $STATUS -ne 0 ] 
	    then
		rm -rf "$DIRNAME"
		echo
		echo 
		echo "Error: cannot access input file: $INPUT_FILE"
		echo
		exit 1
	    fi
	    cd $DIRNAME
	    BATCH_MODE=true
	    export BATCH_MODE
	    ;;
	
	-keep)
	    KEEP=keep
	    export KEEP
	    ;;

	-keepdata)
	    KEEP=keepdata
	    export KEEP
	    ;;

	-nofile)
	    # input_file empty means -nofile was selected
	    touch input_file
	    BATCH_MODE=true
	    export BATCH_MODE
	    ;;
	
	-mail)
	    EXPLORER_EMAIL=$EXPLORER_ADDRESS
	    export EXPLORER_EMAIL
	    ;;
	
	-myemail)
	    # get user's desired mail address, the next paramerer
	    # following -myemail. Store it mail-address
	    shift
	    export EXPLORER_EMAIL
	    EXPLORER_EMAIL="$1"
	    ;;
	
	-v)
	    cd ..
	    rm -rf "$DIRNAME"
    	    echo ""
    	    echo "SunExplorer Version $REV"
    	    echo ""
	    exit 0
	    ;;

	-help)
	    cd ..
	    rm -rf "$DIRNAME"
	    more ./explorer.man
	    exit 0
	    ;;

	*)
	    cd ..
	    rm -rf "$DIRNAME"
            echo 
    	    echo
    	    echo "Wrong parameters passed"
    	    echo "For usage see:"
	    echo "     explorer -help"
    	    echo
	    exit 1
	    ;;
    esac
    # Get the next parameter, i.e. $1 has the value of $2 after shift.
    shift
done
