#
# usage:        main.sh
#
# abstract:     This Bourne Shell script is the main install program
#		for Matlab 6.x.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1986-2003 The MathWorks, Inc.
# $Revision: 1.59.4.2 $  $Date: 2003/12/11 18:21:48 $
#----------------------------------------------------------------------------
#
    trap ". '$dir/$abort_sh'" 1 2 3 15
#
#----------------------------------------------------------------------------
# Globals
#
    temp_file=/tmp/$$a
    temp_file2=/tmp/$$b
    temp_file3=/tmp/$$c
    temp_file4=/tmp/$$d
    temp_file5=/tmp/$$e
#
    . $dir/$util_sh
#----------------------------------------------------------------------------
#
# 			Get options [all]
#			-----------
#
    . $dir/$options_sh
#
#
# 			Check for superuser [all]
#			-------------------
#
    if [ "$usermode" = "0" ]; then
        . $dir/$ruser_sh
    fi
#
# 			Type of install [all]
#			---------------
#
    while true
    do
# 
	if [ $type -gt 0 ]; then 
	    whichi=$type
	fi
        case "$whichi" in
	    1|'')
    		if [ "$terse" = "0" ]; then
		    clear_screen
		    . $dir/$intro_s_sh
		fi
		whichi=1
		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, 4]
#			---------------------------
#
    if [ "$usermode" = "0" ]; then
	. $dir/$netruser_sh
    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_TOOLBOX_DIR=$ML_ROOT_DIR/toolbox
    ML_UPDATE=$ML_ROOT_DIR/update
#
    ROOTDIR=$MATLAB
    LM_ROOT=$MATLAB/etc
    LM_SCRIPTS=$ML_ROOT_DIR/etc/scripts
#
#	    Set the MATLAB directory to have at least r-w permission [all]
#           --------------------------------------------------------
#
    chmod ugo+rx $MATLAB
#
#			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 and generate path [1]
#          		-------------------------------
#
    if [ $whichi -eq 1 ]; then
        . $dir/$bld_sbin_sh
	$dir/$genpathdef_sh $ML_ROOT_DIR
    fi
#
#			Stop now after build scripts [-X option]
#			----------------------------
#
    if [ "$extract_fix_only" = "1" ]; then
	clear_screen
        . $dir/$fin_sh
    fi
#
#
#	      Rename M-files in toolbox/local [1]
#	      --------------------------------------------------
#
    if [ $whichi -eq 1 ]; then
	. $dir/$local_sh
    fi
#
#         Create symbolic links to the binaries if requested [1]
#         --------------------------------------------------
#
    if [ $whichi -eq 1 -a "$minimal_install" != "1" ]; then
	. $dir/$bld_lbin_sh
    fi
#
#		Install License Manager [1] 
#		-----------------------
#
    . $dir/$lm_sh
    install_license_manager
#
#				Finished [all]
#				--------
#
    clear_screen
    . $dir/$fin_sh
