#
# usage:        options.sh
#
# abstract:     This Bourne Shell script parsers the options on the
#		command line.
#
# note(s):      1. This routine must be called using a . (period)
#		2. Options:
#
#     		   -h   Help. Show command usage.
#     		   -b   Batch mode. Ignore all queries to continue.
#			Cannot be used with -m option.
#		   -e   (Tape Only) Extract files from 'collective tape'
#			and delete 'collective tape' boot directory only.
#		   -E   (Tape Only) Extract files from 'collective tape' only.
#		   -f   Analyze TMW_Archive FEATURE Lines in license.dat
#			file for validity.
#		   -l   Output hostname and lmhostid for this host only.
#		   -m   Minimal install. Do not allow changes to anything
#			outside the MATLAB root directory. Cannot be
#			specified with -b option.
#		   -o   Place a template license file in the path given by
#		        license_file. It will never replace an existing file.
#		   -r   (Tape Only) Remove the 'collective tape' boot directory.
#		   -s   Skip the welcome messages. Used by 'collective tape'
#			install.
#     		   -t 	Terse mode. Only print screens that are critical
#			to the installation.
#		   -u   User mode. Ignore checking for root and network root.
#		   -w   (FTP Only) Generate list of FTP files to download.
#		   -x   Extract files only, i.e. do updating only.
#		   -X   Extract files and update scripts only.
#     		   type Type of installation: (except c2mp and cray)
#               	1 - normal
#               	2 - client
#               	3 - client with license manager
#               	4 - license manager only
#     		   type Type of installation: (c2mp and cray)
#               	1 - normal
#               	2 - client
#
# Copyright (c) 1992-94 by The MathWorks, Inc.
# $Revision: 1.20 $  $Date: 1994/12/01 22:21:00 $
#----------------------------------------------------------------------------
#
    lmhostid_only=0
    licdat_only=0
    extract_only=0
    extract_fix_only=0
    terse=0
    skip_welcome=0
    remove_tape_dir=0
    textract_rm_only=0
    textract_only=0
    batch=0
    usermode=0
    check_tmw_al=0
    minimal_install=0
    ftp_select=0
#
    bad=0
    type=0
    nargs=$#
    msg=
    alone=0
    notalone=0
    while [ $# -gt 0 ]
    do
	case $1 in
	    -h)				# help
		bad=1
		;;
	    -l)				# (alone) lmhostid
	        if [ "$License" = "1" ]; then
		    alone=`expr $alone + 1`
		    lmhostid_only=1
		else
        	    msg='usage'
		    bad=1
		fi
		;;
	    -o)				# (alone) skeleton license.dat file
	        if [ "$License" = "1" ]; then
		    alone=`expr $alone + 1`
		    if [ $# -eq 1 ]; then
		        bad=1
        	        msg='no license_file argument'
		    else
			shift
		        licdat_only=1
			licdat_path=$1
		    fi
		else
        	    msg='usage'
		    bad=1
		fi
		;;
	    -x)				# extract files only
		notalone=`expr $notalone + 1`
		extract_only=1
		type=1
		;;
	    -X)				# extract files and update scripts
		notalone=`expr $notalone + 1`
		extract_fix_only=1
		type=1
		;;
	    -t)				# terse  
		notalone=`expr $notalone + 1`
		terse=1
		;;
	    -s)				# skip the welcome messages
		notalone=`expr $notalone + 1`
		skip_welcome=1
		;;
	    -r)				# (alone) (tape only) remove the
					# tape boot dir
		alone=`expr $alone + 1`
		remove_tape_dir=1
		if [ "$MODE" != "tape" ]; then
		    if [ "$License" = "1" ]; then
		        msg="no 'collective tape' boot directory loaded"
		        bad=1
		    else
        	        msg='usage'
		        bad=1
		    fi
		fi
		;;
	    -e)				# (alone) (tape only) extract files
				        # and remove tape boot dir only
		alone=`expr $alone + 1`
		textract_rm_only=1
		if [ "$MODE" != "tape" ]; then
		    if [ "$License" = "1" ]; then
		        msg="no 'collective tape' boot directory loaded"
		        bad=1
		    else
        	        msg='usage'
		        bad=1
		    fi
		fi
		;;
	    -E)		    		# (alone) (tape only) extract files only
		alone=`expr $alone + 1`
		textract_only=1
		if [ "$MODE" != "tape" ]; then
		    if [ "$License" = "1" ]; then
		        msg="no 'collective tape' boot directory loaded"
		        bad=1
		    else
        	        msg='usage'
		        bad=1
		    fi
		fi
		;;
	    -b)				# batch
		notalone=`expr $notalone + 1`
		batch=1
		;;
	    -u)				# install as non-root user
		notalone=`expr $notalone + 1`
		usermode=1
		;;
	    -f)				# (only) analyze TMW_Archive feature
					# line(s)
		alone=`expr $alone + 1`
		check_tmw_al=1
		;;
	    -m)				# only make changes inside of $MATLAB
		notalone=`expr $notalone + 1`
		minimal_install=1
		;;
	    -w)				# (alone) (FTP only) generate list of
					# files to download
		alone=`expr $alone + 1`
    		ftp_select=1
		if [ "$License" = "1" ]; then
		    if [ ! -d $MATLAB/update/maps/ftp ]; then
		        msg='boot.ftp not loaded.'
		        bad=1
		    fi
		else
        	    msg='usage'
		    bad=1
		fi
		;;
	     *)				# type of install and everything else
		notalone=`expr $notalone + 1`
		if [ "$License" = "1" ]; then
		    if [ "$1" != "1" -a "$1" != "2" -a "$1" != "3" -a "$1" != "4" ]; then
        	        msg='usage'
		        bad=1
		    else
		        type=`expr $1 + 0`
		    fi
		else
		    if [ "$1" != "1" -a "$1" != "2" ]; then
        	        msg='usage'
		        bad=1
		    else
		        type=`expr $1 + 0`
		    fi
		fi
		;;
	esac
	shift
	if [ "$bad" = "1" ]; then
	    break
	fi
    done
    alone=`expr $alone + 0`
    notalone=`expr $notalone + 0`
    if [ $alone -gt 1 ]; then
	bad=1
        msg='usage'
    elif [ $alone -gt 0 -a $notalone -gt 0 ]; then
	bad=1
        msg='usage'
    elif [ "$extract_only" = "1" -a "$type" != "1" ]; then
	bad=1
        msg='usage'
    elif [ "$extract_fix_only" = "1" -a "$type" != "1" ]; then
	bad=1
        msg='usage'
    elif [ "$extract_only" = "1" -a "$extract_fix_only" = "1" ]; then
	bad=1
        msg='usage'
    elif [ "$batch" = "1" -a "$minimal_install" = "1" ]; then
	bad=1
        msg='usage'
    fi
    if [ "$bad" = "1" -a "$License" = "1" ]; then
	if [ "$msg" != "" ]; then
	    cat /dev/null > $temp_file 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	cat > $temp_file << EOF
    echo '--------------------------------------------------------------------'
    echo "    Error: $msg"
EOF
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	cat >> $temp_file << EOF
    echo '--------------------------------------------------------------------'
    echo ''
    echo '    Usage: install_matlab -h | -l | -o license_file | -f | -r | -e |'
    echo '                          -E | -w | [-t] [-s] [-b|-m] [1] [-u] -x |'
    echo '                                    [-t] [-s] [-b|-m] [1] [-u] -X |'
    echo '                                    [-t] [-s] [-b|-m] [-u] [type]'
    echo ''
    echo '      -h   Help. Show command usage.'
    echo ''
    echo '      -b   Batch mode. Ignore all queries to continue. Cannot'
    echo '           be specified with -m option.'
    echo ''
    echo "      -e   (Tape Only) Extract files from 'collective tape' and"
    echo "           delete 'collective tape' boot directory only."
    echo ''
    echo "      -E   (Tape Only) Extract files from 'collective tape' only."  
    echo ''
    echo '      -f   Analyze TMW_Archive FEATURE Lines in license.dat file'
    echo '           for validity.'
    echo ''
    echo '      -l   Output hostname and lmhostid for this host only.'
    echo ''
    echo '      -m   Minimal install. Do not allow changes to anything'
    echo '           outside the MATLAB root directory. Cannot be specified'
    echo '           with -b option.'
    echo ''
    echo '      -o   Place a template license file in the path given by'
    echo '           license_file. It will never replace an existing file.'
    echo ''
    echo '      -r   (Tape Only) Remove the 'collective tape' boot directory.'
    echo ''
    echo '      -s   Skip welcome messages.'
    echo ''
    echo '      -t   Terse mode. Print critical screens only.'
    echo ''
    echo '      -u   User mode. Ignore checking for root and network root.'
    echo ''
    echo '      -w   (FTP Only) Generate list of FTP files to download.'
    echo ''
    echo '      -x   Extract files only, i.e. do updating only.'
    echo ''  
    echo '      -X   Extract files and update scripts only.'
    echo ''
    echo '      type Type of installation:'
    echo '           1 - normal      3 - client with license manager'
    echo '           2 - client      4 - license manager only'
    echo ''
    echo '--------------------------------------------------------------------'
EOF
	chmod +x $temp_file
	. $temp_file | more
        . $dir/$cleanup_sh
	exit 0
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    elif [ "$bad" = "1" -a "$License" = "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	if [ "$msg" != "" ]; then
	    cat /dev/null > $temp_file 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	cat > $temp_file << EOF
    echo '--------------------------------------------------------------------'
    echo "    Error: $msg"
EOF
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	fi
	cat > $temp_file << EOF
    echo '------------------------------------------------------------------'
    echo ''
    echo '    Usage: install_matlab -h | [-t] [-s] [-b|-m] [1] [-u] -x |'
    echo '                               [-t] [-s] [-b|-m] [1] [-u] -X |'
    echo '                               [-t] [-s] [-b|-m] [-u] [type]'
    echo ''
    echo '      -h   Help. Show command usage.'
    echo ''
    echo '      -b   Batch mode. Ignore all queries to continue. Cannot'
    echo '           be specified with -m option.'
    echo ''
    echo '      -m   Minimal install. Do not allow changes to anything'
    echo '           outside the MATLAB root directory. Cannot be specified'
    echo '           with -b option.'
    echo ''
    echo '      -s   Skip welcome messages.'
    echo ''
    echo '      -t   Terse mode. Print critical screens only.'
    echo ''
    echo '      -u   User mode. Ignore checking for root and network root.'
    echo ''
    echo '      -x   Extract files only, i.e. do updating only.'
    echo ''  
    echo '      -X   Extract files and update scripts only.'
    echo ''
    echo '      type Type of installation:'
    echo '           1 - normal'
    echo '           2 - client'
    echo ''
    echo '------------------------------------------------------------------'
EOF
	chmod +x $temp_file
	. $temp_file | more
        . $dir/$cleanup_sh
	exit 0
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    fi
#
