#! /bin/sh
#set -x
#
#  Name:
#     install_matlab    point of entry for all MATLAB 4.x installations
#
#  Usage:
#     install_matlab -h | -l | -o license_file | -f | -r | -e | -E | -w |
#			  [-t] [-s] [-b|-m] [1] [-u] -x |
#			  [-t] [-s] [-b|-m] [1] [-u] -X |
#			  [-t] [-s] [-b|-m] [-u] [type]
#
#  Description:
#     "install_matlab" is the point of entry for all MATLAB 4.x installations.
#     The system administrator should be logged in as "root" to complete all
#     steps. A non-root user can install a working MATLAB.
#
#     The installer can select ONLY ONE from the following types of
#     installation for a GIVEN execution of this program. It may require
#     several executions of this program using different types of installation 
#     to fully install MATLAB.
#
#	1. NORMAL -
#	   You can install everything.
#
#	2. CLIENT -
#	   Install symbolic links to scripts in $MATLAB/bin directory
#	   and copy MATLAB man pages only.
#
#	3. CLIENT WITH LICENSE MANAGER -
#	   Same as 2, but you MAY install the license manager.
#	   Not available on convex and cray.
#
#	4. LICENSE MANAGER ONLY -
#	   Not available on convex and cray.
#
#     Each type of installation performs all or a subset of the following
#     functions. The number list in brackets at the end of each function
#     description indicate which types of installation perform that function.
#
#	1.  Prompts for verification of or get new MATLAB root directory
#	    path from user. [all]
#
#	2.  Checks for any supplied toolboxes and edits the scripts so
#	    that the toolboxes are added to MATLABPATH.  These script files
#	    are moved to "./bin".
#	    [1]
#
#	3.  Renames M-files in "./toolbox/local".
#	    [1]
#
#	4.  Prompts for the MATLAB license number and customizes the
#	    license ID M-file, siteid.m in "./toolbox/local". [1]
#
#	5.  Optionally prompts for the machine's ACCESS directory
#	    and creates symbolic links in the machine's ACCESS
#	    directory which point to the scripts in "./bin".
#	    This directory should be in the path of all MATLAB users.
#	    Default is "/usr/local/bin".
#	    [1, 2, 3]
#
#	6.  Optionally prompts for the directory where to copy the MATLAB
#	    man pages and does the copying.
#	    [1, 2, 3]
#
#	7.  Optionally installs the FLEXlm license manager. Edits the
#	    "*.etc" scripts in "./.scripts" and moves them to "./etc".
#	    Creates a template license.dat file in "./etc". Optionally,
#           creates the symbolic link /etc/lmboot -> $MATLAB/etc/lmboot.
#	    [1, 3, 4]
#
# Options:
#
#     -h
#	    Help. Show command usage.
#
#     -b
#	    Batch mode. Ignore all queries to continue. Cannot be
#	    be specified 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 license_file
#
#	    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 welcome messages.
#
#     -t
#	    Terse mode. Only print screens that are critical to the
#	    installation.
#
#     -u
#           Run in user mode, i.e. 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:
#		1 - normal
#		2 - client
#		3 - client with license manager
#		4 - license manager only
#
# Notes:
#
#	1. required commands: awk, chmod, cat, clear, cp, echo, expr, find,
#			      hostname, mkdir, more, mv, rm, sed, tar, umask,
#			      uncompress, zcat
#	   desirable commands: id
#	2. Bourne shell must support [ ] notation in if-then
#	3. Bourne shell path versus platform
#
#		apollo		- /etc/sys_sh		
#		other		- /bin/sh
#
#	4. other required scripts:
#
#		main.sh
#		abort.sh, actualp, arch.sh, bld_lbin.sh,
#		bld_sbin.sh, cleanup.sh, clearsc.sh, cont.sh, echon.sh,
#		fin.sh, intro_c.sh, intro_cl.sh, intro_l.sh, intro_s.sh,
#		lm.sh, local.sh, man.sh, netruser.sh, options.sh,
#		perm.sh, ruser.sh, searchp.sh, undotarZ.sh, verifyp.sh,
#		version.sh, welcome1.sh, welcome2.sh, whichi.sh
#
#		fcleanpe.sh, icleanpe.sh, ucleanpe.sh, update.sh
#
#		getlmhid.sh, mapname.sh, mklicdat.sh
#
#		getver.sh, tbxquery.sh
#
#		cktmw_al.sh, decryptl.sh, tmw_alsc.sh
#
#		cleanup2.sh, defltmap.sh, pdextrct.sh tpdscren.sh,
#		tpdselct.sh, rmtpdir.sh, tapecln.sh, tapepos.sh,
#		tarchive.sh, tintro.sh, trewind.sh, twelcome.sh
#
#		ftp.sh fwelcome.sh fpdscren.sh  fpdselct.sh
#
#		vstring.map
#
#	5. batch scripts:
#
#		batch1.sh, batch2.sh, batch3.sh, batch4.sh
#
#	6. Flow of control for types of install
#
#==========================================================================
#	   State Machine:
#
#	     install_state:
#
#		0 - initial state
#		1 - found media, but still may need to expand pd pieces
#		2 - all pd pieces expanded
#
#==========================================================================
#	   . Determine command name and MATLAB (environ)
#	   . Determine Arch (local) and set to LOCAL_ARCH (environ)
#	   . Set PATH
#	   . set install_state = 0
#	   . set FTP_TBX = 0 unless it is already not blank.
#	   . if install_state == 0 && CD_LM_INSTALL
#
#		. Determine TMW_CD_FORMAT
#		. Source mapname_sh
#		. Set dir
#		. install_state=2
#
#          . fi
#	   . if 2nd pass for tape
#
#		. install_state=1
#
#	   . fi
#	   . if install_state == 0 && -d $MATLAB/update/maps/ftp
#	  
#	        . Check for any FTP files
#		. if FTP files and -d $MATLAB/update/tape
#
#		  output selection
#
#		  1. FTP
#			. Expand any ftp files
#			. Place boot.ftp in $MATLAB/ftp
#			. Place files in $MATLAB/ftp
#			. Set FTP_TBX = 1 if any files are toolbox files
#                                         or mathlib
#			. install_state=1
#		  2. TAPE
#
#		. fi
#
#	   . fi
#	   . if install_state == 0 && -d $MATLAB/update/tape
#	  
#		. Make tape_boot file
#		. Source tape_boot file
#		->
#	   . fi
#
#	   . if install_state != 2
#
#		. if certain pd files exist
#
#		    . Make temp_boot
#		    . Source temp_boot
#		    ->
#
#		. else
#
#		    . Source mapname_sh
#		    . Set dir
#
#		. fi
#
#	    . fi
#
#	    . Source main_sh
#==========================================================================
#
# Copyright (c) 1992-95 by The MathWorks, Inc.
# $Revision: 1.53 $  $Date: 1995/11/17 17:36:56 $
#--------------------------------------------------------------------------
#
#**************************************************************************
# Determine the path of the install directory and the command name
#**************************************************************************
#
    filename=$0
#
# Now it is either a file or a link to a file.
#
    cpath=`pwd`
#
# Follow up to 8 links before giving up. Same as BSD 4.3
#
    n=1
    maxlinks=8
    while [ $n -le $maxlinks ]
    do
#
# Get directory correctly!
#
	newdir=`echo "$filename" | awk '
                        { tail = $0
                          np = index (tail, "/")
                          while ( np != 0 ) {
                             tail = substr (tail, np + 1, length (tail) - np)
                             if (tail == "" ) break
                             np = index (tail, "/")
                          }
                          head = substr ($0, 1, length ($0) - length (tail))
                          if ( tail == "." || tail == "..")
                             print $0
                          else
                             print head
                        }'`
	if [ ! "$newdir" ]; then
	    newdir="."
	fi
	(cd $newdir) > /dev/null 2>&1
	if [ $? -ne 0 ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 1: We could not determine the path of the'
    echo '                  MATLAB root directory.'
    echo ''
    echo "                  original command path = $0"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    exit 1
	fi
	cd $newdir
#
# Need the function pwd - not the built in one
#
	newdir=`/bin/pwd`
#
	newbase=`expr //$filename : '.*/\(.*\)' \| $filename`
        lscmd=`ls -l $newbase 2>/dev/null`
	if [ ! "$lscmd" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 2: Could not determine the path of the'
    echo '                  MATLAB root directory.'
    echo ''
    echo "                  original command path = $filename"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    exit 1
	fi
#
# Check for link portably
#
	if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then
	    filename=`echo "$lscmd" | awk '{ print $NF }'`
	else
#
# It's a file
#
	    dir="$newdir"
	    command="$newbase"
	    MATLAB=`/bin/pwd`; export MATLAB
	    break
	fi
	n=`expr $n + 1`
    done
    if [ $n -gt $maxlinks ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 3: More than $maxlinks links in path to'
    echo "                  this script. That's too many!"
    echo ''
    echo "                  original command path = $filename"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	exit 1
    fi
    cd $cpath
#
#**************************************************************************
# Call the main body of the install program
#**************************************************************************
#
    WD=$cpath
#
# Determine Arch first so that we can determine which name mapping to use.
# It MUST be inline and is a copy of arch.sh.
#
#			Determine the Machine Architecture [all]
#			----------------------------------
#
#============================= arch.sh (start) =============================
#!/bin/sh
#
# usage:        arch.sh
#
# abstract:     This Bourne Shell script sets the variable Arch to
#		reflect the current machine architecture.
#
#		Arch	  - Machine architecture
#
# note(s):	1. This routine must be called using a . (period)
#
# Copyright (c) 1986-95 by The MathWorks, Inc.
# Revision: 1.24   Date: 1995/04/28 19:41:28
#----------------------------------------------------------------------------
#
   Arch="unknown"
#
   if [ -f /bin/uname ]; then
   	case "`/bin/uname`" in
	    SunOS)					# sun4 and sol2
	        if [ -d /dev/pts ]; then
		    Arch="sol2"
	        else
		    Arch="sun4"
	        fi
	        ;;
	    HP-UX)					# hp300 and hp700
    	        if [ -f /bin/hp9000s300 ]; then
		    (/bin/hp9000s300) > /dev/null 2>&1
		    if [ $? -eq 0 ]; then
	    	        Arch="hp300"
	            fi
		fi
	        if [ -f /bin/hp9000s700 ]; then
		    (/bin/hp9000s700) > /dev/null 2>&1
		    if [ $? -eq 0 ]; then
	    	        Arch="hp700"
		    fi
	        fi
	        ;;
	    IRIX)					# sgi
    	        if [ -f /bin/4d ]; then
		    (/bin/4d) > /dev/null 2>&1
		    if [ $? -eq 0 ]; then
	    	        Arch="sgi"
		    fi
	        fi
	        ;;
            IRIX64)                                     # sgi IRIX 6 64 bit OS
                if [ -f /bin/4d ]; then
                    (/bin/4d) > /dev/null 2>&1
                    if [ $? -eq 0 ]; then
                        Arch="sgi"
                    fi
                fi
                ;;
	    ULTRIX)					# dec_risc
    	        if [ -f /ultrixboot ]; then
		    Arch=`file /ultrixboot`
		    if [ `expr "$Arch" : ".*mipsel.*"` -gt 0 ]; then
	    	        Arch="dec_risc"
		    else
	    	        Arch="vax_unix"
		    fi
	        fi
	        ;;
	    OSF1)					# alpha
	    	Arch="alpha"
	        ;;
	    AIX*)					# ibm_rs
#
# With AIX 4.1, uname can return more than just 'AIX'
#
	        Arch="ibm_rs"
	        ;;
	    DomainOS)					# System V apollo
                if [ -d /usr/apollo/bin ]; then
	            Arch="apollo"
	        fi
	        ;;
	    Linux)
		Arch="lnx86"
		;;
	    *)
		if [ "`/bin/uname -a | grep CRAY`" != "" ]; then 
		    Arch="cray"
		fi
	        ;;
        esac
   elif [ -f /bin/arch ]; then				# early sun4
	Arch="`/bin/arch`"
   elif [ -d /usr/apollo/bin ]; then			# BSD apollo
	Arch="apollo"
   elif [ -f /ultrixboot ]; then			# early ultrix
	typefile=`file /ultrixboot`
	if [ `expr "$typefile" : ".*mipsel.*"` -gt 0 ]; then
	    Arch="dec_risc"
	else
	    Arch="vax_unix"
	fi
   elif [ -d $MATLAB/bin/c2mp ]; then
	Arch="c2mp"
   fi
#============================= arch.sh (end) ===============================
    if [ "$Arch" = "unknown" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '    Sorry! We could not determine the machine architecture for your'
    echo '           host. Please contact:'
    echo ''
    echo '               MathWorks Technical Support'
    echo ''
    echo '           for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Call abort.sh inline here.
#
#============================= abort.sh (start) ============================
#
# usage:        abort.sh
#
# abstract:     This Bourne Shell script prints out an abort message and
#		exits.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1992-94 by The MathWorks, Inc.
# Revision: 1.7 Date: 1994/04/11 11:11:03
#
#----------------------------------------------------------------------------
#
    rm -f $temp_file $temp_file2a $temp_file2b $temp_file2 $temp_file3 $temp_file4 $temp_file5 $MATLAB/update/$$a > /dev/null 2>&1
#------------------------------------------------------------------------------
    echo ''
    echo '    Sorry! install_matlab aborted . . .'
    echo ''
#------------------------------------------------------------------------------
    exit 1
#============================= abort.sh (end) ==============================
    else
	LOCAL_ARCH=$Arch; export LOCAL_ARCH
    fi
#
#                       Augment path [all]
#                       ------------
    case "$Arch" in
        sgi)
           PATH=$PATH:/usr/bsd:/usr/sbin
           export PATH
           ;;
        *) ;;
    esac
#
    install_state=0
    boot_header=0
    if [ "$FTP_TBX" = "" ]; then
        FTP_TBX=0
    fi
    export FTP_TBX
    if [ "$batch" = "" ]; then
	batch=0
    fi
#
# CDROM case: Map names so that this install can be run on the CDROM.
#
    if [ "$install_state" = "0" -a "$CD_LM_INSTALL" != "" ]; then
#
# Determine value of TMW_CD_FORMAT by looking at the value of the
# 'command' variable which is the ISO 9660 version of 'setup'.
#
	cdtype=1
    	TMW_CD_FORMAT=;  export TMW_CD_FORMAT
    	case "$command" in
	    'linstall')		# ufs, sgi, alpha
	    	TMW_CD_FORMAT='unix'
            	. $dir/install/mapname.sh
            	dir=$dir/install
	    	;;
	    'linstall.')	# sun4, sol2, ibm_rs
	    	TMW_CD_FORMAT='sun'
            	. $dir/install/mapname.sh
            	dir=$dir/install
	    	;;
	    'LINSTALL')		# dec-risc
	        TMW_CD_FORMAT='dec'
                . $dir/INSTALL/MAPNAME.SH
                dir=$dir/INSTALL
	    	;;
	    'LINSTALL.;1')	# hp700, hp300
	        TMW_CD_FORMAT='hp'
                . $dir/INSTALL/'MAPNAME.SH;1'
                dir=$dir/INSTALL
	        ;;
	    *)		# unknown
	        cdtype=0
	        ;;
    	esac
#
        if [ "$cdtype" = "0" ]; then
#------------------------------------------------------------------------------
    echo '-------------------------------------------------------------------'
    echo ''
    echo '    Sorry! Could not determine the Format of the CDROM for'
    echo "           architecture ($Arch)"
    echo ''
    echo '-------------------------------------------------------------------'
#------------------------------------------------------------------------------
	    exit 1
    	fi
	install_state=2
    fi
#
# 2nd pass for tape install
#
    if [ "$MODE" = "tape" ]; then
	install_state=1
    fi
#
# FTP case:
# 
    if [ "$install_state" = "0" -a -d $MATLAB/update/maps/ftp ]; then
	if [ -f $MATLAB/update/maps/ftp/piece.map ]; then
#
	    trap "rm -f /tmp/$$a /tmp/$$b > /dev/null 2>&1; exit 1" 1 2 3 15
#
	    (cd $MATLAB; ls) > /tmp/$$a
	    echo 'EOF' >> /tmp/$$a
	    cat /tmp/$$a $MATLAB/update/maps/ftp/piece.map | awk '
#---------------------------------------------------------------------------
    BEGIN { state = 0 }
    $1 == "EOF" { state = 1; next }
    NF == 0 { next }
    $1 ~ /^#.*/ { next }
	    { if ( state == 0 ) 
		  entry[$1] = 1
	      else if ( entry[$2] == 1)
		  print $2 
	    }' > /tmp/$$b
#---------------------------------------------------------------------------
	    nfiles=`wc -l /tmp/$$b  | awk '{print $1}'`
#
# Move any $MATLAB/update/decrypt/decrypt.$Arch -> $MATLAB/decrypt.$Arch
#
	    if [ ! -f $MATLAB/decrypt.$Arch ]; then
	        if [ -f $MATLAB/update/decrypt/decrypt.$Arch ]; then
		    mv $MATLAB/update/decrypt/decrypt.$Arch $MATLAB
		    echo decrypt.$Arch >> /tmp/$$b
	        fi
	    fi
#
	    if [ "$nfiles" != "0" ]; then
#
# Clear the screen
#
        	if [ "$batch" = "0" ]; then
	    	    clear
		fi
		ans=0
		boot_header=1
		if [ -d $MATLAB/update/tape ]; then
#
# Both ftp and tape. Ask the user what to do.
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '                      Booting up install for MATLAB'
    echo '                      -----------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		    while true
		    do
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo "There are 'ftp' files AND a 'tape' boot area . . ."
    echo ''
    echo "Select the source of files . . ."
    echo ''
    echo '    [1] ftp'
    echo '    [2] tape'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    			mesg='Source of files? ([1]/2) '
        		if [ "`echo -n`" != "" ]; then
            		    echo "$mesg\c"
        		else
            		    echo -n "$mesg"
        		fi
                	if [ "$batch" != "1" ]; then
                    	    read ans
                	else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '1'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			    ans=1
                	fi
			if [ `expr "//$ans" : '//[ 	]*$'` -ne 0 ]; then
			    ans=1
			    break
		        elif [ `expr  "//$ans" : '//[ 	]*[1-2][ 	]*$'` -ne 0 ]; then 
			    break
			fi
		    done
		    ans=`echo "//$ans" : '//[ 	]*\([1-2]\)[ 	]*$'`
		else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '                      Booting up install for MATLAB'
    echo '                      -----------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		fi
		if [ "$ans" = "2" ]; then
			:
		else
		    install_state=1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Explode all files
#
    		    mesg='Detarring ftp files . . . . . . . . . . . [please wait]'
        	    if [ "`echo -n`" != "" ]; then
            		echo "$mesg\c"
        	    else
            		echo -n "$mesg"
        	    fi
#
		    (while read file
		     do
		         cd $MATLAB
		         tar -xf $file
		     done) < /tmp/$$b
		    echo ''
#
# Check that $MATLAB/ftp exists and if not attempt to create it.
#
		    found=1
		    if [ ! -d $MATLAB/ftp ]; then
			mkdir $MATLAB/ftp > /dev/null 2>&1
			if [ $? -ne 0 ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo 'Cannot create ftp directory - no permission. No ftp files moved . . .'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			    found=0
			fi
		    fi
		    if [ "$found" = "1" ]; then
#
# Move boot.ftp to ftp it it exists
#
		        if [ -f $MATLAB/boot.ftp ]; then
			    mv $MATLAB/boot.ftp $MATLAB/ftp
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo 'Moving boot.ftp file to $MATLAB/ftp . . .'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		        fi
#
# Move files to ftp
#
    		        mesg='Moving ftp files to $MATLAB/ftp . . . . . [please wait]'
        	        if [ "`echo -n`" != "" ]; then
            		    echo "$mesg\c"
        	        else
            		    echo -n "$mesg"
        	        fi
#
			echo "0" > /tmp/$$a
		        (while read file
		         do
		             cd $MATLAB
		             mv $file ftp
			     if [ "$FTP_TBX" = "0" ]; then
				 if [ `expr "$file" : 'tbx\..*'` -ne 0 -o `expr "$file" : 'mathlib.*'` -ne 0 ]; then
			             FTP_TBX=1
				     echo "1" > /tmp/$$a
				 fi
			     fi
		         done) < /tmp/$$b
		         echo ''
		    else
			echo "0" > /tmp/$$a
		        (while read file
		         do
			     if [ "$FTP_TBX" = "0" ]; then
				 if [ `expr "$file" : 'tbx\..*'` -ne 0 -o `expr "$file" : 'mathlib.*'` -ne 0 ]; then
			             FTP_TBX=1
				     echo "1" > /tmp/$$a
				 fi
			     fi
		         done) < /tmp/$$b
		    fi
		    FTP_TBX=`cat /tmp/$$a | awk '{print $1}'`
		fi
	    fi
	    rm -f /tmp/$$a /tmp/$$b > /dev/null 2>&1
	else
#
# Clear the screen
#
            if [ "$batch" = "0" ]; then
	        clear
	    fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '                      Booting up install for MATLAB'
    echo '                      -----------------------------'
    echo ''
    echo '-------------------------------------------------------------------'
    echo ''
    echo '    Sorry! $MATLAB/update/maps/ftp/piece.map does not exist . . .'
    echo '           Please contact:'
    echo ''
    echo '               MathWorks Technical Support'
    echo ''
    echo '           for further assistance.'
    echo ''
    echo '-------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    exit 1
	fi
    fi
#
# Collective TAPE case:
#
    if [ "$install_state" = "0" -a -d $MATLAB/update/tape ]; then
#
#---------------------------------------------------------------------------
#
# Tape Archive section:
#
#   1. This file will be overwritten
#   2. Sets mode to tape
#   3. Create temporary file that is sourced and uses
#
#      dir = $MATLAB/update/tape/install
#
#      It must be deleted at the end. 
#
#   4. After the files are extracted, another boot file is created:
#
#      4.1 which deletes the $MATLAB/update/tape directory 
#      4.2 execs' install_matlab -s arguments
#
	tape_boot=$MATLAB/update/tape/$$boot; export tape_boot
        TAPE_DIR=$MATLAB/update/tape; export TAPE_DIR
        dir=$MATLAB/update/tape
#==========================================================================
	cat > $tape_boot << EOF
#
# Tape Archive boot program:
#
    trap "rm -f $tape_boot; exit 1" 1 2 3 15
#
    MODE='tape'; export MODE
    . $dir/install/mapname.sh
#
    dir=$MATLAB/update/tape/install
    . $dir/install/main.sh
EOF
	chmod +x $tape_boot
	. $tape_boot
#==========================================================================
# 
    fi
#
# Detar and remove any remaining decrypt.$Arch:
#
    if [ -f $MATLAB/decrypt.$Arch ]; then
	(cd $MATLAB; tar -xf decrypt.$Arch)
	rm -f $MATLAB/decrypt.$Arch
    fi
#
    if [ "$install_state" != "2" ]; then
#
#---------------------------------------------------------------------------
#
# If required create and run boostrap program that pulls off install piece(s)
# and then runs install_matlab.
#
# IMPORTANT: 1. This file will be overwritten
#	     2. The temporary file that is run must be deleted at the
#		end
#
        if [ -f "$dir/update/pd/install/tar.cmp" -o \
	     -f "$dir/update/pd/install/tarr.cmp" -o \
	     -f "$dir/update/pd/install/$Arch/tar.cmp" -o \
	     -f "$dir/update/pd/install/$Arch/tarr.cmp" -o \
	     -f "$dir/update/pd/lm/tar.cmp" -o \
	     -f "$dir/update/pd/lm/tarr.cmp" -o \
	     -f "$dir/update/pd/lm/$Arch/tar.cmp" -o \
	     -f "$dir/update/pd/lm/$Arch/tarr.cmp" -o \
	     -f "$dir/update/pd/update/tar.cmp" -o \
	     -f "$dir/update/pd/update/tarr.cmp" -o \
	     -f "$dir/update/pd/update/$Arch/tar.cmp" -o \
	     -f "$dir/update/pd/update/$Arch/tarr.cmp" ]; then
#
	    temp_boot=/tmp/$$boot; export temp_boot
#==========================================================================
            cat > $temp_boot << EOF
#
# MATLAB installation boot program:
#
#--------------------------------------------------------------------------
    trap "rm -f $temp_boot; exit 1" 1 2 3 15
#
    MODE="$MODE"; export MODE
#
# Clear screen if appropriate
#
    if [ "$batch" = "0" ]; then
       if [ "$MODE" != "tape" -a "$boot_header" = "0" ]; then
           clear
       fi
    fi
# 
    if [ "$MODE" != "tape" -a "$boot_header" = "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '                      Booting up install for MATLAB'
    echo '                      -----------------------------'
    echo ''
    echo 'Working . . .'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Working . . .'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    fi
#
# Pull off the installation software
#              ---------------------
    if [ -f "$dir/update/pd/install/tar.cmp" ]; then
        if [ ! -f $MATLAB/update/pd/install/.b ]; then
	    rm -rf $MATLAB/install > /dev/null 2>&1
        fi
	mv $dir/update/pd/install/tar.cmp $dir/update/pd/install/tar.Z
	case "$Arch" in
            sgi)
                zcat $dir/update/pd/install/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
                zcat $dir/update/pd/install/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/install/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/install/tarr.cmp" ]; then
	mv $dir/update/pd/install/tarr.cmp $dir/update/pd/install/tarr.Z
	case "$Arch" in
            sgi)
		zcat $dir/update/pd/install/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
		zcat $dir/update/pd/install/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/install/tarr.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/install/$Arch/tar.cmp" ]; then
        if [ ! -f $MATLAB/update/pd/install/$Arch/.b ]; then
	    rm -rf $MATLAB/install/$Arch > /dev/null 2>&1
        fi
	mv $dir/update/pd/install/$Arch/tar.cmp $dir/update/pd/install/$Arch/tar.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/install/$Arch/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/install/$Arch/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/install/$Arch/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/install/$Arch/tarr.cmp" ]; then
	mv $dir/update/pd/install/$Arch/tarr.cmp $dir/update/pd/install/$Arch/tarr.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/install/$Arch/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/install/$Arch/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/install/$Arch/tarr.Z > /dev/null 2>&1 
    fi
#
# Pull off the license manager also so that -x and -o will work.
#              ---------------
#
    if [ -f "$dir/update/pd/lm/tar.cmp" ]; then
        if [ ! -f $MATLAB/update/pd/lm/.b ]; then
#
# Can't delete all of etc - because it contains license.dat and other things
# useful to th user. Just delete ./etc/util.
#
	    rm -rf $MATLAB/etc/util > /dev/null 2>&1
        fi
	mv $dir/update/pd/lm/tar.cmp $dir/update/pd/lm/tar.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/lm/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/lm/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/lm/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/lm/tarr.cmp" ]; then
	mv $dir/update/pd/lm/tarr.cmp $dir/update/pd/lm/tarr.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/lm/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/lm/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/lm/tarr.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/lm/$Arch/tar.cmp" ]; then
        if [ ! -f $MATLAB/update/pd/lm/$Arch/.b ]; then
	    rm -rf $MATLAB/etc/$Arch > /dev/null 2>&1
        fi
	mv $dir/update/pd/lm/$Arch/tar.cmp $dir/update/pd/lm/$Arch/tar.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/lm/$Arch/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/lm/$Arch/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/lm/$Arch/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/lm/$Arch/tarr.cmp" ]; then
	mv $dir/update/pd/lm/$Arch/tarr.cmp $dir/update/pd/lm/$Arch/tarr.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/lm/$Arch/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/lm/$Arch/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/lm/$Arch/tarr.Z > /dev/null 2>&1 
    fi
#
# Pull off the decryption software so that *.enc files can decrypted
#              -------------------
#
    if [ -f "$dir/update/pd/update/tar.cmp" ]; then
#
# Don't worry about deleting anything
#
	mv $dir/update/pd/update/tar.cmp $dir/update/pd/update/tar.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/update/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/update/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/update/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/update/tarr.cmp" ]; then
	mv $dir/update/pd/update/tarr.cmp $dir/update/pd/update/tarr.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/update/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/update/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/update/tarr.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/update/$Arch/tar.cmp" ]; then
#
# Don't worry about deleting anything
#
	mv $dir/update/pd/update/$Arch/tar.cmp $dir/update/pd/update/$Arch/tar.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/update/$Arch/tar.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/update/$Arch/tar.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/update/$Arch/tar.Z > /dev/null 2>&1 
    fi
    if [ -f "$dir/update/pd/update/$Arch/tarr.cmp" ]; then
	mv $dir/update/pd/update/$Arch/tarr.cmp $dir/update/pd/update/$Arch/tarr.Z
	case "$Arch" in
            sgi)
        	zcat $dir/update/pd/update/$Arch/tarr.Z | (cd $MATLAB; tar -xfB -)
		;;
	    *)
        	zcat $dir/update/pd/update/$Arch/tarr.Z | (cd $MATLAB; tar -xf -)
		;;
	esac
	rm -f $dir/update/pd/update/$Arch/tarr.Z > /dev/null 2>&1 
    fi
#
    if [ "$MODE" != "tape" ]; then
        if [ "`echo -n`" != "" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "Please press <return> to continue . . . >\c"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo -n "Please press <return> to continue . . . >"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        fi
        if [ "$batch" != "1" ]; then
            read ans
        else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        fi
    else
	clear
	MODE=
    fi
#
    exec $MATLAB/install_matlab $*
#
EOF
	    chmod +x $temp_boot
	    . $temp_boot
#==========================================================================
#
#---------------------------------------------------------------------------
	else
	    if [ "$boot_header" != "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		if [ "`echo -n`" != "" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "Please press <return> to continue . . . >\c"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        	else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo -n "Please press <return> to continue . . . >"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        	fi
        	if [ "$batch" != "1" ]; then
            	    read ans
        	else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        	fi
	    fi
            . $dir/install/mapname.sh
            dir=$dir/install
	fi
    fi
#
    . $dir/$main_sh
