#
# 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-1998 by The MathWorks, Inc.
# $Revision: 1.50 $  $Date: 1998/11/30 18:20:30 $
#----------------------------------------------------------------------------
#
    trap ". '$dir/$abort_sh'" 1 2 3 15
#
#----------------------------------------------------------------------------
# Globals
#
    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
#
    . $dir/$util_sh
#----------------------------------------------------------------------------
#
#			Determine the Machine Architecture [all]
#			----------------------------------
#
# NOTE: Arch is now determined inline in install_matlab
#
# 			Get install version [all]
#			-------------------
#
    . $dir/$version_sh
#
# 			Get options [all]
#			-----------
#
    . $dir/$options_sh
#
#                       Get lmhostid only [-l option]
#                       -----------------
#
    if [ "$lmhostid_only" = "1" ]; then
	clear_screen
#
        . $dir/$getlmhid_sh
#
    fi
#
#                       Get template license only [-o option]
#                       -------------------------
#
    if [ "$licdat_only" = "1" ]; then
	clear_screen
#
        . $dir/$mklicdat_sh
#
	create2_license_file
	exit_state=$?
	clean_temp_areas
        exit $exit_state
    fi
#
#         Analyze TMW_Archive INCREMENT lines in license.dat file [-f option]
#         -----------------------------------------------------
#
    if [ "$check_tmw_al" = "1" ]; then
        . $dir/$tmw_alsc_sh
    fi
#
#			Create template license.dat file
#			--------------------------------
#
    if [ -f $MATLAB/license.dat ]; then
        licdat_path=$MATLAB/etc/license.dat
	clear_screen
#
        . $dir/$mklicdat_sh
#
	create2_license_file
        query_to_continue
    fi
#
#         		Select FTP files [-w option]
#			----------------------------
#
    if [ "$ftp_select" = "1" ]; then
        . $dir/$ftp_sh
    fi
#
#			View and accept license agreement
#			---------------------------------
#
    . $dir/$license_sh
#
    accept_license
#
#
# 			Welcome messages [all]
#			----------------
#
    if [ "$terse" = "0" -a "$skip_welcome" = "0" ]; then
	clear_screen
#
        . $dir/$welcome1_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 superuser [all]
#			-------------------
#
    if [ "$usermode" = "0" ]; then
        . $dir/$ruser_sh
    fi
#
#		Check TMW_Archive INCREMENT line if FTP_TBX=1
#		-------------------------------------------
#
    if [ "$FTP_TBX" != "0" ]; then
	clear_screen
	. $dir/$fwelcome_sh
    fi
#
# 			Type of install [all]
#			---------------
#
    while true
    do
# 
	if [ $type -gt 0 ]; then 
	    whichi=$type
	else
	    clear_screen
	    . $dir/$whichi_sh
	    mesg='Which one? ([1]) '
            . $dir/$echon_sh
            read whichi
	fi
        case "$whichi" in
	    1|'')
    		if [ "$terse" = "0" ]; then
		    clear_screen
		    . $dir/$intro_s_sh
		fi
		whichi=1
		break
	        ;;
            2)
		if [ "$minimal_install" = "1" ]; then
		    clear_screen
#-----------------------------------------------------------------------------
    echo ""
    echo "    'Minimal' install option skips all CLIENT install steps . . ."
#-----------------------------------------------------------------------------
    		    . $dir/$fin_sh
		fi
    		if [ "$terse" = "0" ]; then
		    clear_screen
		    . $dir/$intro_c_sh
		fi
		break
		;;
            3)
    		if [ "$terse" = "0" ]; then
		    clear_screen
		    . $dir/$intro_cl_sh
		fi
		break
		;;
	    4)
    		if [ "$terse" = "0" ]; then
		    clear_screen
		    . $dir/$intro_l_sh
		fi
		break
		;;
	    *)
		continue
		;;
        esac
    done
#
    
    if [ "$terse" = "0" ]; then
        . $dir/$cont_sh
    fi
#
# 			Check for NETWORK superuser [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_BIN_DIR=$ML_ROOT_DIR/bin
    ML_BSCRIPTS_DIR=$ML_ROOT_DIR/bin/scripts
    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
#
    ROOTDIR=$MATLAB
    LM_ROOT=$MATLAB/etc
#
# if CD_LM_INSTALL is not defined then the license manager scripts directory
# is off of $MATLAB/etc. Otherwise, use the value of $lscripts_dir.
#
    if [ "$CD_LM_INSTALL" != "1" ]; then
        LM_SCRIPTS=$ML_ROOT_DIR/etc/scripts
    else
    	LM_SCRIPTS=$lscripts_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
	clear_screen
        . $dir/$fin_sh
    fi
#
#          		Build scripts [1]
#          		-------------
#
    if [ $whichi -eq 1 ]; then
	if [ "$doc_only_install" = "1" ]; then
	    . $dir/$bld_help_sh
	else
	    . $dir/$bld_sbin_sh
	fi
    fi
#
#			Stop now after build scripts [-X or -D option]
#			----------------------------
#
    if [ "$extract_fix_only" = "1" -o "$doc_only_install" = "1" ]; then
	clear_screen
        . $dir/$fin_sh
    fi
#
#
#	      Rename M-files and build license.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 ]; then
	. $dir/$lm_sh
#
	install_license_manager
    fi
#
#				Finished [all]
#				--------
#
    clear_screen
    . $dir/$fin_sh
