#! /bin/sh
#set -x
#
#  Name:
#     install_matlab    point of entry for all MATLAB 5.x installations
#
#  Usage:
#     install_matlab [-h|-help] | -l | -o license_file | -f | -w | -e | -E |
#			     -r | [-d] [-t] [-s] [-b|-m] [1] [-u] -x |
#			          [-d] [-t] [-s] [-b|-m] [1] [-u] -X |
#			          [-d] [-t] [-s] [-b|-m] [-u] [-arch] [type]
#
#  Description:
#     "install_matlab" is the point of entry for all MATLAB 5.x installations.
#     You do not have to be superuser to install a working MATLAB. However, you
#     must be superuser to complete all steps
#
#     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.
#
#	4. LICENSE MANAGER ONLY -
#
#     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 .matlab5rc.sh
#	    in "./bin" so that MATLABPATH is defined. Additional script files
#	    in "./bin/scripts" are installed in "./bin". [1]
#
#	3.  Installs template M-files from "./toolbox/local/template" in
#	    "./toolbox/local" for initial installation only. [1]
#
#	4.  Prompts for the MATLAB license number and customizes the
#	    license M-file, license.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 installs the FLEXlm license manager. The script
#	    files in "./etc/scripts" are installed in "./etc".
#	    Creates a template license.dat file in "./etc". Optionally,
#           creates the symbolic links
#		/etc/lmboot_TMW5 -> $MATLAB/etc/lmboot
#		/etc/lmdown_TMW5 -> $MATLAB/etc/lmdown
#	    [1, 3, 4]
#
# Options:
#
#     -h
#     -help
#	    Help. Show command usage.
#
#     -b
#	    Batch mode. Ignore all queries to continue. Cannot be
#	    be specified with -m option.
#
#     -d
#	    (FTP only) Delete each ftp file immediately after it is
#	    untared.
#
#     -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 INCREMENT 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 superuser and
#           network superuser.
#
#     -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.
#
#     -arch
#	    Assume this architecture instead of the one determined
#	    by arch.sh
#
#     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 must support internal functions
#	4. Other required scripts:
#
#		main.sh
#		abort.sh, actualp, bld_lbin.sh, bld_sbin.sh,
#		center.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, oldname.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
#
#	        rmtpdir.sh, tapecln.sh, tapepos.sh, tarchive.sh, tintro.sh,
#		tpdscren.sh, tpdselct.sh, trewind.sh, twelcome.sh
#
#		fpdscren.sh  fpdselct.sh ftp.sh fwelcome.sh
#
#		arch.sh oscheck.sh* vstring.map
#
#	   * imbedded
#
#	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 files in $MATLAB/ftp
#			. Set FTP_TBX = 1 if any files are toolbox files
#			. 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
#		    . install_state=2
#		    . Source temp_boot
#		    ->
#
#		. else
#
#		    . Source mapname_sh
#		    . Set dir
#
#		. fi
#
#	    . fi
#
#	    . if install_state == 2 && ! CD_LM_INSTALL
#
#	          . Source mapname_sh
#		  . Set dir
#
#	    .fi
#
#	    . Source main_sh
#==========================================================================
#
# Copyright (c) 1992-1998 by The MathWorks, Inc.
# $Revision: 1.67 $  $Date: 1998/12/24 17:31:34 $
#--------------------------------------------------------------------------
#
    arg0_=$0
#
    temp_file=/tmp/$$a; cat /dev/null > /tmp/$$a
#
    trap "rm -rf $temp_file > /dev/null 2>&1; exit 1" 1 2 3 15
#
#=======================================================================
# Functions:
#   scriptpath ()
#   check_for_ftp_untar ()
#   delete_after_untar ()
#   enc_ftp_products ()
#=======================================================================
    scriptpath () { # returns path of this script as a directory,
                    # ROOTDIR, and command name, CMDNAME.
		    #
		    # Returns a 0 status unless an error.
		    #
                    # usage: scriptpath
                    #
#
	filename=$arg0_
#
# 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 = $arg0_"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	        return 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 ''
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	        return 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"
	        CMDNAME="$newbase"
	        ROOTDIR=`/bin/pwd`
	        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 ''
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    return 1
        fi
        cd $cpath
        return 0
    }
#=======================================================================
    check_for_ftp_untar () { # Checks whether arguments are passed 
			     # that require the ftp files to be
			     # untared.
			     #
			     # Any of the following arguments to
			     # install_matlab DO NOT require ftp
			     # files to be untared.
			     # 
			     # -help | -h | -l | -o  | -f | -w
                             #
                             # Returns a 0 status if files are to be
			     # untared else 1.
                             #
                             # usage: check_for_ftp_untar args
                             #
        i=1
        while [ $i -le $# ]
        do
            value=`eval echo '$'"$i"`
	    case "$value" in
		-help|-h|-l|-o|-f|-w)
		     return 1
		     ;;
	        *)
		     :
		     ;;
	    esac
            i=`expr $i + 1`
        done
	return 0
    }
#=======================================================================
    delete_after_untar () { # Outputs 1 if -d option passed else 0.
			    # The -d option causes each ftp file to be
			    # deleted immediately after untaring.
			    # 
                            # Always returns a 0 status.
                            #
                            # usage: delete_after_untar args
                            #
        i=1
        while [ $i -le $# ]
        do
            value=`eval echo '$'"$i"`
	    case "$value" in
		-d)
		     echo 1
		     return 0
		     ;;
	        *)
		     :
		     ;;
	    esac
            i=`expr $i + 1`
        done
	echo 0
	return 0
    }
#=======================================================================
    enc_ftp_products () { # Returns 1 if ftp files exist with encrypted
			  # components else 0
                          #
                          # Always returns a 0 status.
                          #
                          # usage: enc_ftp_products args
                          #
		          # Required Files:
			  #	input:
		          # 	    $MATLAB/install/vstring.map - encrypted
		          #			components file
		          #	    /tmp/$$b - list of downloaded ftp files
			  #     created only for this function:
			  #	    /tmp/$$a

	if [ -f $MATLAB/install/vstring.map ]; then
	    cat $MATLAB/install/vstring.map > /tmp/$$a
	    echo 'EOF' >> /tmp/$$a
	    cat /tmp/$$a /tmp/$$b | awk '
#---------------------------------------------------------------------------
    BEGIN { state = 0; found = 0 }
    $1 == "EOF" { state = 1; next }
    NF == 0 { next }
    state == 0 && $2 ~ /NA\./ { next }
    state == 0 && $2 ~ /NO\./ { next }
	    { if ( state == 0 ) 
		  entry[$2] = 1
	      else {
		  s = $1
# Take off last .* - file never starts with a "."
		  for (i = length($1); i > 0; i = i - 1)
		      if (substr($1,i,1) == ".") {
			  s = substr($1,1,i-1)
		          break
		      }
		  if (entry[s] == 1) {
		      print 1
		      found = 1
		      exit
		  }
	      }
	    }
    END {if (!found) print 0}'
#---------------------------------------------------------------------------
	fi
	return 0
    }
#=======================================================================
#
#=========================== hpuxbug.sh (start) ============================
#
# usage:        hpuxbug.sh
#
# abstract:     This Bourne Shell checks for and handles the HP-UX
#		10.x 'expr' bug.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1996-1998 The Mathworks, Inc. All Rights Reserved.
# $Revision: 1.4 $  $Date: 1998/12/24 17:31:57 $
#----------------------------------------------------------------------------
#
# Check for HP-UX 10.x 'expr' bug.
#
    if [ "`expr 'CASE' : '\(CA=\)'`" = "0" ]; then 
	Arch="unknown"
        if [ -f /bin/hp9000s700 ]; then
	    (/bin/hp9000s700) > /dev/null 2>&1
            if [ $? -eq 0 ]; then
		Arch="hp700"
	    fi
	fi
        if [ -f /bin/hp9000s800 ]; then
            (/bin/hp9000s800) > /dev/null 2>&1
            if [ $? -eq 0 ]; then
                Arch="hp700"
            fi
	fi
	if [ "$Arch" = "hp700" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '-------------------------------------------------------------------'
    echo '    Sorry! MATLAB cannot be installed on this HP system! We have'
    echo "           detected a HP bug in the 'expr' command that prevents"
    echo '           you from installing and running MATLAB. It affects'
    echo '           HP-UX 10.0, 10.01, 10.10, and 10.20 systems. A patch'
    echo '           directory has been provided and we will create it now'
    echo '           in /tmp. You must install this patch on every affected'
    echo '           HP system.'
    echo ' '    
#
	    d=`dirname $0`
	    cp "$d/HPUX10.PCH;1" /tmp/$$a
	    (cd /tmp; tar -xf /tmp/$$a; rm -f /tmp/$$a)
#
    echo '    Created patch directory: /tmp/hpux10.pch'
    echo ' '
    echo '    See the README file in this directory for installation'
    echo '    instructions.'
    echo '-------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    exit 1
        else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '-------------------------------------------------------------------'
    echo '    Sorry! MATLAB cannot be installed on this system! We have'
    echo "           detected a bug in the 'expr' command that prevents"
    echo '           you from installing and running MATLAB. For help'
    echo '           please contact The MathWorks Technical Support:'
    echo ' '
    echo '               The MathWorks, Inc.'
    echo '               phone: (508) 647-7000'
    echo '               email: support@mathworks.com'
    echo '               web:   http://www.mathworks.com'
    echo ' '    
    echo '-------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    exit 1
	fi
    fi
#=========================== hpuxbug.sh (end) ==============================
#
#**************************************************************************
# Call the main body of the install program
#**************************************************************************
#
# Determine cpath, dir, CMDNAME, and ROOTDIR
#
    scriptpath
    if [ $? -ne 0 ]; then
        exit 1
    fi
#
    command="$CMDNAME"
    MATLAB="$ROOTDIR"; export MATLAB
    WD=$cpath
#
# Do not use ARCH if it exists in the environment
#
    ARCH=""
#
#========================= archlist.sh (start) ============================
#
# usage:        archlist.sh
#
# abstract:     This Bourne Shell script creates the variable ARCH_LIST.
#
# note(s):      1. This file is always imbedded in another script
#
# Copyright (c) 1997-1998 by The MathWorks, Inc.
# $Revision: 1.3 $  $Date: 1998/11/03 22:06:40 $
#----------------------------------------------------------------------------
#
    ARCH_LIST='sol2 hp700 alpha ibm_rs sgi sgi64 lnx86'
#========================= archlist.sh (end) ==============================
#
# 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 determines the architecture
#		of the the current machine.
#
#		ARCH	  - Machine architecture
#
# note(s):	1. This routine must be called using a . (period)
#
# Copyright (c) 1986-1997 by The MathWorks, Inc.
# $Revision: 1.8 $  $Date: 1997/11/06 23:02:48 $
#----------------------------------------------------------------------------
#
#=======================================================================
# Functions:
#=======================================================================
	matlab5_arch () { # Determine the architecture for MATLAB 5
			  # and outputs it to standard output
                          #
                          # Always returns a 0 status.
                    	  #
                    	  # usage: matlab5_arch
                    	  #
	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)					# hp700, hp800
	            if [ -f /bin/hp9000s700 ]; then
		        (/bin/hp9000s700) > /dev/null 2>&1
		        if [ $? -eq 0 ]; then
	    	            Arch="hp700"
		        fi
	            fi
	            if [ -f /bin/hp9000s800 ]; then
		        (/bin/hp9000s800) > /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)		# Want this to mean MIPS 4/64 bit OS sgi
    	            if [ -f /bin/4d ]; then
		        (/bin/4d) > /dev/null 2>&1
		        if [ $? -eq 0 ]; then
	    	            Arch="sgi64"
		        fi
	            fi
#
# Watch out! Some machines are not MIPS 4 (R4400)
#
		    if [ -f /bin/hinv ]; then
			cpu=`/bin/hinv | awk '
#-----------------------------------------------------------------------
	$1 == "CPU:" { print substr($3,1,2) }'`
#-----------------------------------------------------------------------
			if [ "$cpu" = "R4" ]; then
			    Arch=sgi
			fi
		    fi
	            ;;
	        OSF1)					# alpha
	    	    Arch="alpha"
	            ;;
	        AIX*)					# ibm_rs
#
# With AIX 4.1, uname can return more than just 'AIX'
#
	            Arch="ibm_rs"
	            ;;
	        Linux)
		    Arch="lnx86"
		    ;;
	        *)
		    :
	            ;;
	    esac
	elif [ -f /bin/arch ]; then				# early sun4
	    Arch="`/bin/arch`"
	fi
#
        echo $Arch
#
	return 0
    }
#
    if [ "$ARCH_CHECK" = "" -a "$ARCH_LIST" != "" ]; then
#
# Check input arguments $1, ..., $$# for -ARCH
#
	i=1
	while [ $i -le $# ]
	do
	    value=`eval echo '$'"$i"`
	    ARCH=`echo "$ARCH_LIST EOF $value" | awk '
#-----------------------------------------------------------------------
	{ for (i = 1; i <= NF; i = i + 1)
	      if ($i == "EOF") {
		  narch = i - 1
		  if (NF != i + 1) exit
	          break
	      }
	  for (i = 1; i <= narch; i = i + 1)
		if ("-" $i == $NF) {
		    print $i
		    exit
		}
	}'`
#-----------------------------------------------------------------------
	    if [ "$ARCH" != "" ]; then
		break
	    fi
	    i=`expr $i + 1`
	done
    fi
#
    if [ "$ARCH" = "" ]; then
	ARCH=`matlab5_arch`
    fi
    Arch=$ARCH
#============================= 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)
#
#----------------------------------------------------------------------------
#
    rm -f $temp_file $temp_file2a $temp_file2b $temp_file2 $temp_file3 $temp_file4 $temp_file5 $MATLAB/update/$$a
#------------------------------------------------------------------------------
    echo ''
    echo '    Sorry! install_matlab aborted . . .'
    echo ''
#------------------------------------------------------------------------------
    exit 1
#============================= abort.sh (end) ==============================
    else
	LOCAL_ARCH=$ARCH; export LOCAL_ARCH
    fi
#
    if [ "$OSCHECK_DONE" = "" ]; then
#
#			Check OS version number [all]
#			-----------------------------
#
# Do not call oscheck.sh if executing from the CD-ROM. It was called by
# the CD-ROM install.
#
	if [ "$CD_ROOT" = "" ]; then
#=========================== oscheck.sh (start) ============================
#!/bin/sh
#set -x
#
# usage:        oscheck.sh
#
# abstract:     This Bourne Shell script determines the OS level of the
#		system and responds according to what it finds. There
#		are four numbers of interest:
#
#		    minimum_ver - major release number of minimum
#				  version to run
#		    version     - current version
#		    built_ver   - built version
#		    future_ver  - future version that we know doesn't work
#				  "-" means infinite
#
#		if version >= future_ver 
#		     new error message
#		     request to stop
#		If built_ver <= version < future_ver
#		     no message
#		If minimum_ver <= version < built_ver 
#		     warning message only
#		If version < minimum_ver
#		     old error message
#		     request to stop
#
#		Arch	  - Machine architecture variable must be set
#
# note(s):	1. This routine must be called using a . (period)
#
# 		2. token is the version in N.N... form
#
#		   sun4:   uname -r     -> token
#		   sol2:   uname -r     -> token
#		   hp700:  uname -r     -> Letter.token
#		   alpha:  uname -r     -> Vtoken
#		   ibm_rs: uname -v -r  -> token(2).token(1) = token
#		   sgi:    uname -r     -> token
#		   sgi64:  uname -r     -> token
#		   lnx86:  uname -r     -> token		   
#		   
#		3. Cases to watch out for
#
#		   SunOS:  4.1.3_U1     - non number at some point
#		   OSF1:   V4.0		- starts with v or V 
#
#		4. This requires at least the System V Bourne Shell since
#		   internal functions are used.
#
#		5. Algorithm:
#
#		   a. write output to a temporary file
#		   b. If empty cleanup and continue
#		   c. If not ERROR
#			  print the file
#		          cleanup and continue
#		      else
#			  print the file
#			  output request to quit
#			  get input (force quite in batch)
#			  continue if n (default is to quit)
#			  cleanup and continue if not quit
#
#		6. Assume that this routine is called using the
#		   unused temporary file defined by
#
#		      $temp_file
#
#		7. The calling routine will exit if the variable,
#		   oscheck_status, is set as follows:		 
#
#		       oscheck_status=1
#
#		8. Also, any cleanup associated with of an interrupt
#		   will be handled by the calling routine.
#
# Copyright (c) 1996-1998 by The MathWorks, Inc.
# $Revision: 1.10 $  $Date: 1998/10/08 21:45:43 $
#----------------------------------------------------------------------------
#
   oscheck_status=0
#
#                  arch   OSprefix built_ver minimum_ver future_ver
#
   oslist="        sun4   SunOS    4.1.4     4           -"
   oslist="$oslist sol2   SunOS    5.5.1     5           -"
   oslist="$oslist hp700  HP-UX    10.20     10          -"
   oslist="$oslist alpha  OSF1     4.0       4           -"
   oslist="$oslist ibm_rs AIX      4.2       4           -"
   oslist="$oslist sgi    IRIX     6.3       6           -"
   oslist="$oslist sgi64  IRIX     6.4       6           -"
   oslist="$oslist lnx86  Linux    2.0.34    2           -"
#
   if [ -f /bin/uname ]; then
   	case $Arch in
	    sun4|sol2|sgi|sgi64|lnx86)
                ver=`/bin/uname -r`
		;;
	    hp700)
		ver=`/bin/uname -r | awk '{print substr($1,3)}'`
		;;
	    alpha)
		ver=`/bin/uname -r | awk '{print substr($1,2)}'`
		;;
	    ibm_rs) # I think there are only 2 digits even though the 'real'
		    # version can have 3
		ver=`/bin/uname -v -r | awk '{print $2 "." $1}'`
		;;
	    *)
                ver=`/bin/uname -r | awk '{print $1}'`
		;;
	esac
   fi
#
   echo $Arch $ver "$oslist"| awk '
#---------------------------------------------------------------------------
	BEGIN { str = "0123456789"; strp = str "." }
	{ arch = $1;
	  origver = $2;
#
# remove any non-numeric prefix from the version like V, etc.
#
	  ver = ""
	  for (j = 1; j <= length(origver); j = j + 1)
	      if (index(strp,substr(origver,j,1)) != 0) {
		  ver = substr(origver,i)
		  break
	      }
          lver = length(ver)
	  for (i = 3; i <= NF; i = i + 5) {
	      n[$i] = $(i+1) ""
	      v[$i] = $(i+2) ""
	      m[$i] = $(i+3) ""
	      f[$i] = $(i+4) ""
	  }
	  rver = v[arch]
	  if (rver == "") exit 
          mver = m[arch]
	  fver = f[arch]  
#
# split the release version
#
	  nrver = split(rver,rv,".")
	  for (i = 1; i <= nrver; i = i + 1)
	      if (rv[i] == "") rv[i] = 0
#
# split the minimum version
#
	  nmver = split(mver,mv,".")
	  for (i = 1; i <= nmver; i = i + 1)
	      if (mv[i] == "") mv[i] = 0
#
# split the future version if there is one
#
	  if (fver != "-") {
	      nfver = split(fver,fv,".")
	      for (i = 1; i <= nfver; i = i + 1)
	          if (fv[i] == "") fv[i] = 0
	  }
#
# split the actual version
# remove everything in a word after a nondigit
#
          nver = split(ver,v,".")
	  for (i = 1; i <= nver; i = i + 1) {
	      new = ""
	      for (j = 1; j <= length(v[i]); j = j + 1)
	          if (index(str,substr(v[i],j,1)) != 0)
		      new = new substr(v[i],j,1)
		  else
		      break
	      v[i] = new
	      if (v[i] == "") v[i] = 0
	  }
#
# errmode: 0 - ok
#          1 - too old error
#          2 - warning
#          3 - too new error
#
          errmode = 0
#
# check against the minimum
#
	  if (nmver < nver)
	      ncd = nmver
	  else
	      ncd = nver
	  for (i = 1; i <= ncd; i = i + 1)
	      if (mv[i] + 0 > v[i] + 0)
		  errmode = 1
	      else if (mv[i] + 0 < v[i] + 0)
		  break
	  if (fail == 0 && i == ncd + 1 && ncd == nver)
	      for (i = ncd + 1; i <= nmver; i = i + 1)
	          if (mv[i] + 0 == 0 )
		      continue
	          else
		      errmode = 1
#
# check against the built version
#
	  if (errmode == 0) {
	      if (nrver < nver)
	          ncd = nrver
	      else
	          ncd = nver
	      for (i = 1; i <= ncd; i = i + 1)
	          if (rv[i] + 0 > v[i] + 0)
		      errmode = 2
	          else if (rv[i] + 0 < v[i] + 0)
		      break
	      if (errmode == 0 && i == ncd + 1 && ncd == nver)
	          for (i = ncd + 1; i <= nrver; i = i + 1)
	              if (rv[i] + 0 == 0)
		          continue
	              else
		          errmode = 2
          }
#
# check against the future version
#
	  if (errmode == 0 && fver != "-") {
	      if (nfver < nver)
	          ncd = nfver
	      else
	          ncd = nver
	      for (i = 1; i <= ncd; i = i + 1)
	          if (fv[i] + 0 <= v[i] + 0)
		      errmode = 3
	          else if (fv[i] + 0 > v[i] + 0)
		      break
	      if (errmode == 0 && i == ncd + 1 && ncd == nver)
	          for (i = ncd + 1; i <= nfver; i = i + 1)
	              if (fv[i] + 0 == 0)
		          continue
	              else
		          errmode = 3
          }
	  if (errmode == 1) {
print ""   
print "---------------------------------------------------------------------------"
printf "Warning: %s %-10s - Unsupported Operating System\n", n[arch], ver
printf "         %s %-10s - MATLAB built using this Operating System\n", n[arch], rver
print "---------------------------------------------------------------------------"
print ""
          }
          else if (errmode == 2) {
print ""   
print "---------------------------------------------------------------------------"
printf "Warning: %s %-10s - Your Operating System\n", n[arch], ver
printf "         %s %-10s - MATLAB built using this Operating System\n", n[arch], rver
print "---------------------------------------------------------------------------"
print ""
          }
          else if (errmode == 3) {
print ""   
print "---------------------------------------------------------------------------"
printf "Warning: %s %-10s - Unqualified Operating System\n", n[arch], ver
printf "         %s %-10s - MATLAB built using this Operating System\n", n[arch], rver
print "---------------------------------------------------------------------------"
print ""
	  }
	}' > $temp_file
#---------------------------------------------------------------------------
#=======================================================================
# Functions:
#=======================================================================
    echon ()    { # echo without a newline - UNIX dependent
                  #
                  # usage: echon
                  #
        if [ "`echo -n`" != "" ]; then
            echo "$1\c"
        else
            echo -n "$1"
        fi
    }
#=======================================================================
    if [ -s $temp_file ]; then
	cat $temp_file
	errmode=`cat $temp_file | awk 'NR == 3 {print $2}'`
	case "$errmode" in
	    'OLD):')
#---------------------------------------------------------------------------
echo 'Your Operating System APPEARS to be too OLD to install or run MATLAB!'
echo '------------------------------------------------------------------------'
echo 'Please contact The MathWorks, Inc. if you have any questions ...'
echo '       phone: (508) 647-7000'
echo '       email: support@mathworks.com'
echo '       web:   http://www.mathworks.com'
echo 'Press the <return> key at the prompt to quit ...'
echo ' '
echon 'Please quit now ([y]/n) > '
#---------------------------------------------------------------------------
		if [ "$batch" != "1" ]; then
		    read ans
		    if [ `expr "//$ans" : '//[Nn].*'` -gt 0 ]; then
		        :
		    else
			oscheck_status=1
		    fi
		else
#---------------------------------------------------------------------------
     echo 'n'		    
#---------------------------------------------------------------------------
		fi
		;;
	    'NEW):')
#---------------------------------------------------------------------------
echo 'Your Operating System APPEARS to be too NEW to install or run MATLAB!'
echo '------------------------------------------------------------------------'
echo 'Please contact The MathWorks, Inc. if you have any questions ...'
echo '       phone: (508) 647-7000'
echo '       email: support@mathworks.com'
echo '       web:   http://www.mathworks.com'
echo 'Press the <return> key at the prompt to quit ...'
echo ' '
echon 'Please quit now ([y]/n) > '
#---------------------------------------------------------------------------
		if [ "$batch" != "1" ]; then
		    read ans
		    if [ `expr "//$ans" : '//[Nn].*'` -gt 0 ]; then
		        :
		    else
			oscheck_status=1
		    fi
		else
#---------------------------------------------------------------------------
     echo 'n'		    
#---------------------------------------------------------------------------
		fi
		;;
	     *)
		:
		;;
	esac
    fi
    rm -f $temp_file
#============================ oscheck.sh (end) =============================
            if [ "$oscheck_status" = "1" ]; then
                exit 1
            fi
	    OSCHECK_DONE=1; export OSCHECK_DONE
            sleep 3
	else
	    OSCHECK_DONE=1; export OSCHECK_DONE
	fi
    fi

#
#                       Augment path [all]
#                       ------------
    case "$ARCH" in
        sgi|sgi64)
           PATH=$PATH:/usr/bsd:/usr/sbin
           export PATH
           ;;
        *) ;;
    esac
#
    if [ "$install_state" = "" ]; then
        install_state=0
    fi
    export install_state
#
    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, sgi64, 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
	    check_for_ftp_untar $*
	    if [ $? -eq 0 ]; then 
#
	        trap "rm -f /tmp/$$a /tmp/$$b; 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
	    else
#
# 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
	            fi
	        fi
		nfiles=0
	    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
#
# Delete ftp files immediately after untaring?
#
		    rmftp=`delete_after_untar $*`
		    install_state=1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# If in batch and file $MATLAB/batch.boot was used then save the file as
# $MATLAB/batch.boot.start before it is overwritten by the untarring of boot.ftp.
# The environment variable BATCH_FILE must be the same as $MATLAB/batch.boot
#
		    if [ "$batch" = "1" -a -f $MATLAB/boot.ftp -a \
		         "$MATLAB/batch.boot" = "$BATCH_FILE" ]; then
			mv $MATLAB/batch.boot $MATLAB/batch.boot.start
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '$MATLAB/batch.boot saved as $MATLAB/batch.boot.start before overwrite . . .'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		    fi
#
# Explode all files
#
		    if [ "$rmftp" != "0" ]; then
    		        mesg='Untaring and deleting ftp files  . . . . . [please wait]'
		    else
    		        mesg='Untaring ftp files . . . . . . . . . . . . [please wait]'
		    fi
        	    if [ "`echo -n`" != "" ]; then
            		echo "$mesg\c"
        	    else
            		echo -n "$mesg"
        	    fi
#
		    (while read file
		     do
		         cd $MATLAB
		         tar -xf $file
			 if [ "$rmftp" != "0" ]; then
			    rm -f $file
			 fi
		     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" -a "$rmftp" = "0" ]; then
#
# 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
#
		        (while read file
		         do
		             cd $MATLAB
		             mv $file ftp
		         done) < /tmp/$$b
		         echo ''
		    fi
		    FTP_TBX=`enc_ftp_products $*`
		fi
	    fi
	    rm -f /tmp/$$a /tmp/$$b
	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|sgi64)
                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
    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|sgi64)
		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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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|sgi64)
        	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
    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
#
    install_state=2
#
    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
#
    if [ "$install_state" = "2" -a "$CD_LM_INSTALL" = "" ]; then
	. $dir/install/mapname.sh
        dir=$dir/install
    fi
#
    . $dir/$main_sh
