#
# usage:        main.sh
#
# abstract:     This Bourne Shell script is the main install program
#		for Matlab 4.x.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1986-95 by The MathWorks, Inc.
# $Revision: 1.41 $  $Date: 1995/04/21 16:10:23 $
#----------------------------------------------------------------------------
#
    trap ". '$dir/$abort_sh'" 1 2 3 15
#
    temp_file=/tmp/$$a
    temp_file2=/tmp/$$b
    temp_file2a=/tmp/$$b1
    temp_file2b=/tmp/$$b2
    temp_file3=/tmp/$$c
    temp_file4=/tmp/$$d
    temp_file5=/tmp/$$e
#
#			Determine the Machine Architecture [all]
#			----------------------------------
#
# NOTE: Arch is now determined inline in install_matlab
#
#			Check for License Manager Support [all]
#			---------------------------------
#
    License=1
    if [ "$Arch" = "c2mp" -o "$Arch" = "cray" ]; then
	License=0
    fi
#
#			Check for Mex Support [all]
#			---------------------
#
    Mex=1
    if [ "$Arch" = "c2mp" -o "$Arch" = "cray" ]; then
	Mex=0
    fi
#
# 			Get install version [all]
#			-------------------
#
    . $dir/$version_sh
#
# 			Get options [all]
#			-----------
#
    . $dir/$options_sh
#
#                       Get lmhostid only [-l option]
#                       -----------------
#
    if [ "$License" = "1" -a "$lmhostid_only" = "1" ]; then
        . $dir/$clearsc_sh
        . $dir/$getlmhid_sh
    fi
#
#                       Get template license only [-o option]
#                       -------------------------
#
    if [ "$License" = "1" -a "$licdat_only" = "1" ]; then
        . $dir/$clearsc_sh
        . $dir/$mklicdat_sh
    fi
#
#         Analyze TMW_Archive FEATURE lines in license.dat file [-f option]
#         -----------------------------------------------------
#
    if [ "$License" = "1" -a "$check_tmw_al" = "1" ]; then
        . $dir/$tmw_alsc_sh
    fi
#
#         		Select FTP files [-w option]
#			----------------------------
#
    if [ "$License" = "1" -a "$ftp_select" = "1" ]; then
        . $dir/$ftp_sh
    fi
#
# 			Welcome messages [all]
#			----------------
#
    if [ "$terse" = "0" -a "$skip_welcome" = "0" ]; then
        . $dir/$clearsc_sh
        . $dir/$welcome1_sh
        . $dir/$cont_sh
        . $dir/$clearsc_sh
        . $dir/$welcome2_sh
        . $dir/$cont_sh
    fi
#		      Remove 'collective tape' boot directory [-r option]
#		      ---------------------------------------
#
    if [ "$remove_tape_dir" = "1" ]; then
	. $dir/$rmtpdir_sh
    fi
#
#			Tape archive install [MODE = tape]
#			--------------------
#
    if [ "$MODE" = "tape" ]; then
	. $dir/$tarchive_sh
    fi
#
# 			Check for "root" user [all]
#			---------------------
#
    if [ "$usermode" = "0" ]; then
        . $dir/$ruser_sh
    fi
#
#		Check TMW_Archive FEATURE line if FTP_TBX=1
#		-------------------------------------------
#
    if [ "$FTP_TBX" != "0" ]; then
        . $dir/$clearsc_sh
	. $dir/$fwelcome_sh
    fi
#
# 			Type of install [all]
#			---------------
#
    while true
    do
# 
	if [ $type -gt 0 ]; then 
	    whichi=$type
	else
            . $dir/$clearsc_sh
	    . $dir/$whichi_sh
	    mesg='Which one? ([1]) '
            . $dir/$echon_sh
            read whichi
	fi
        case "$whichi" in
	    1|'')
    		if [ "$terse" = "0" ]; then
		    . $dir/$clearsc_sh
		    . $dir/$intro_s_sh
		fi
		whichi=1
		break
	        ;;
            2)
		if [ "$minimal_install" = "1" ]; then
    		    . $dir/$clearsc_sh
#-----------------------------------------------------------------------------
    echo ""
    echo "    'Minimal' install option skips all CLIENT install steps . . ."
#-----------------------------------------------------------------------------
    		    . $dir/$fin_sh
		fi
    		if [ "$terse" = "0" ]; then
		    . $dir/$clearsc_sh
		    . $dir/$intro_c_sh
		fi
		break
		;;
            3)
		if [ "$License" = "1" ]; then
    		    if [ "$terse" = "0" ]; then
		        . $dir/$clearsc_sh
		        . $dir/$intro_cl_sh
		    fi
		    break
		else
		    continue
		fi
		;;
	    4)
		if [ "$License" = "1" ]; then
    		    if [ "$terse" = "0" ]; then
		        . $dir/$clearsc_sh
		        . $dir/$intro_l_sh
		    fi
		    break
		else
		    continue
		fi
		;;
	    *)
		continue
		;;
        esac
    done
#
    
    if [ "$terse" = "0" ]; then
        . $dir/$cont_sh
    fi
#
# 			Check for NETWORK "root" user [1, 3, 4]
#			-----------------------------
#
    if [ $whichi -ne 2 ]; then
        if [ "$usermode" = "0" ]; then
	    . $dir/$netruser_sh
	fi
    fi
#
#			Check permissions on files and fix umask [all]
#			----------------------------------------
#
    . $dir/$perm_sh
#
#			Verify MATLAB path with user [all]
#	        	----------------------------
#
    . $dir/$verifyp_sh
#
#			Build important paths [all]
#			---------------------
# 
    ML_ROOT_DIR=$MATLAB
    ML_ETC_DIR=$ML_ROOT_DIR/etc
    ML_BIN_DIR=$ML_ROOT_DIR/bin
    ML_LIB_DIR=$ML_ROOT_DIR/lib
    ML_MAN_DIR=$ML_ROOT_DIR/man
    ML_TOOLBOX_DIR=$ML_ROOT_DIR/toolbox
    ML_UPDATE=$ML_ROOT_DIR/update
#
# if CD_LM_INSTALL is not defined then the .scripts directory is off of
# $MATLAB. Otherwise, use the value of $scripts_dir.
#
    if [ "$CD_LM_INSTALL" != "1" ]; then
    	ML_SCRIPT_DIR=$ML_ROOT_DIR/.scripts
    else
    	ML_SCRIPT_DIR=$scripts_dir
    fi
#
#	    Set the MATLAB directory to have at least r-w permission [all]
#           --------------------------------------------------------
#
    chmod ugo+rx $MATLAB
#
#			Uncompress and untar when 9-track tape [1]
#		        --------------------------------------
#
    if [ $whichi -eq 1 ]; then
	. $dir/$undotarZ_sh
    fi
#
#			Update distribution files [all]
#			-------------------------
#
    . $dir/$update_sh
#
#			Check permissions again on files and fix umask [all]
#			----------------------------------------------
#
    . $dir/$perm_sh
#
#			Stop now after extracting files [-x option]
#			-------------------------------
#
    if [ "$extract_only" = "1" ]; then
        . $dir/$clearsc_sh
        . $dir/$fin_sh
    fi
#
#          		Build scripts with MATLABPATH [1]
#          		-----------------------------
#
    if [ $whichi -eq 1 ]; then
	. $dir/$bld_sbin_sh
    fi
#
#			Stop now after build scripts [-X option]
#			----------------------------
#
    if [ "$extract_fix_only" = "1" ]; then
        . $dir/$clearsc_sh
        . $dir/$fin_sh
    fi
#
#
#	      Rename M-files and build siteid.m in toolbox/local [1]
#	      --------------------------------------------------
#
    if [ $whichi -eq 1 ]; then
	. $dir/$local_sh
    fi
#
#         Create symbolic links to the binaries if requested [1, 2, 3]
#         --------------------------------------------------
#
    if [ $whichi -ne 4 -a "$minimal_install" != "1" ]; then
	. $dir/$bld_lbin_sh
    fi
#		Copy MATLAB man pages if requested  [1, 2, 3]
#		----------------------------------
#
    if [ $whichi -ne 4 -a "$minimal_install" != "1" ]; then
	. $dir/$man_sh
    fi
#
#		Install License Manager [1, 3, 4] 
#		-----------------------
#
    if [ $whichi -ne 2  -a "$License" = "1" ]; then
	. $dir/$lm_sh
    fi
#
#				Finished [all]
#				--------
#
    . $dir/$clearsc_sh
    . $dir/$fin_sh
