#! /bin/sh
#
#  Name:
#     install	point of entry for MATLAB CDROM installation
#
#  Usage:
#     install -h | [-<arch>] [-debug] [ [-t] | [-x] ]
#
#  Description:
#     "install" is the point of entry for all MATLAB CDROM installations.
#     The system administrator should be logged in as "root".
#
#     This script is assumed to be called from the CDROM at path
#
#         $CD_ROOT/install  (or equivalent ISO 9660 path)
#
#     The script performs the following functions:
#     
#	case 1:  -h
#
#	    Outputs the usage.
#
#	case 2: [-<arch>] [-debug] [ [-t] | [-x] ]
#
#	    Calls xsetup.
#
#       In general:
#
#       1. Determine the local arch.
#
#	2. Determines the environment variable TMW_CD_FORMAT by looking
#	   at the value of the command 'install' and maps the filename
#	   variables depending on this values.
#
#	3. Sets environment variables
#
#	   CD_ROOT
#	   LOCAL_ARCH
#
#	4. Parses any command line options.
#
#	   NOTE: Any paths below are mapped appropriately to ISO 9660
#		 conforming names.
#
#	   Case 1: 
#
#	       Ends in:
#
#		   $CD_ROOT/update/install/options.sh
#
#	   Case 2:
#
#	       Depending on the options it calls: 
#
#		   $CD_ROOT/update/bin/$LOCAL_ARCH/xsetup
#
#	       with options -debug 
#
# Options:
#
#     -h
#           Help. Show command usage.
#
#     -<arch>
#	    Run this install program assuming this architecture.
#	    (This does not change the CD-ROM format type).
#
#     -debug
#
#	    Turn on debugging.
#
#     -t
#           Use the terminal install.
#
#     -x
#           Use the X Window install
#
# Notes:
#
# 	(UNIX naming - convert to ISO 9660 as required)
#
#	1. required commands: awk, cd, echo, expr, ls, pwd, rm
#	2. Bourne shell must support [ ] notation in if-then
#	3. other required scripts:
#
#		main.sh
#		arch.sh
#		mapname.sh
#		options.sh
#		license.sh
#	        util.sh
#		backend
#		batch4
#
#	   which are in $CD_ROOT/update/install
#
#
# Copyright (c) 1994-2004 by The MathWorks, Inc.
# $Revision: 1.38.4.8 $  $Date: 2004/03/22 23:28:10 $
#--------------------------------------------------------------------------
#
    arg0_=$0
#
#   temp_file is needed by oscheck
    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 ()
#
#=======================================================================
    scriptpath () { # returns command name of this script, 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 Mathworks Technical Support'
    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 Mathworks Technical Support'
    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"
	        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 Mathworks Technical Support'
    echo '                  for further assistance.'
    echo ''
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    return 1
        fi
        cd $cpath
        return 0
    }
#=======================================================================
#
#**************************************************************************
# Call the main body of the install program
#**************************************************************************
# Determine cpath, dir and CMDNAME
#
    scriptpath   
    if [ $? -ne 0 ]; then
        exit 1
    fi   
#
    command="$CMDNAME"
#
# 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 1997-2003 The MathWorks, Inc.
# $Revision: 1.9.4.3 $  $Date: 2004/04/06 01:01:25 $
#----------------------------------------------------------------------------
#
    ARCH_LIST='sol2 hpux glnx86 glnxi64 glnxa64 mac'
#=======================================================================
# Functions:
#   check_archlist ()
#=======================================================================
    check_archlist () { # Sets ARCH. If first argument contains a valid
			# arch then ARCH is set to that value else
		        # an empty string. If there is a second argument
			# do not output any warning message. The most
			# common forms of the first argument are:
			#
			#     ARCH=arch
			#     MATLAB_ARCH=arch
			#     argument=-arch
			#
                        # Always returns a 0 status.
                        #
                        # usage: check_archlist arch=[-]value [noprint]
                        #
	if [ $# -gt 0 ]; then
	    arch_in=`expr "$1" : '.*=\(.*\)'`
	    if [ "$arch_in" != "" ]; then
	        ARCH=`echo "$ARCH_LIST EOF $arch_in" | awk '
#-----------------------------------------------------------------------
	{ for (i = 1; i <= NF; i = i + 1)
	      if ($i == "EOF")
		  narch = i - 1
	  for (i = 1; i <= narch; i = i + 1)
		if ($i == $NF || "-" $i == $NF) {
		    print $i
		    exit
		}
	}'`
#-----------------------------------------------------------------------
	       if [ "$ARCH" = "" -a $# -eq 1 ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ' '
echo "    Warning: $1 does not specify a valid architecture - ignored . . ."
echo ' '
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	       fi
	    else
		ARCH=""
	    fi
	else
	    ARCH=""
	fi
#
	return 0
    }
#=======================================================================
#========================= archlist.sh (end) ==============================
#
# Check input arguments $1, ..., $$# for -ARCH
#
    i=1
    while [ $i -le $# ]
    do
        value=`eval echo '$'"$i"`
        if [ `expr "//$value" : '//-.*'` -ne 0 ]; then
            check_archlist argument=$value noprint
            if [ "$ARCH" != "" ]; then
                break
            fi
        fi
        i=`expr $i + 1`
    done
#
# 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
#
#		IMPORTANT: The shell function 'check_archlist' is used
#			   by this routine and MUST be loaded first.
#			   This can be done by sourcing the file,
#
#			       archlist.sh
#
#			   before using this routine.
#
# note(s):	1. This routine must be called using a . (period)
#
#		2. Also returns ARCH_MSG which may contain additional
#		   information when ARCH returns 'unknown'.
#
# Copyright 1986-2000 The MathWorks, Inc.
# $Revision: 1.17.4.4 $  $Date: 2004/04/06 01:01:24 $
#----------------------------------------------------------------------------
#
#=======================================================================
# Functions:
#   realfilepath ()
#   matlab6_arch ()
#=======================================================================
    realfilepath () { # Returns the actual path in the file system
		      # of a file. It follows links. It returns an
		      # empty path if an error occurs.
		      #
                      # Returns a 1 status if the file does not exist
		      # or appears to be a circular link. Otherwise, 
		      # a 0 status is returned. 
                      #
                      # usage: realfilepath filepath
                      #
	file=$1
	n=1
#
	dir=`dirname $file`
	dir=`(cd $dir; /bin/pwd)`
 	file=`basename $file`
#
# Try up to 8 links
#
    	while [ $n -le 8 ]
    	do
	    (cd $dir) >/dev/null 2>&1
	    if [ $? -eq 0 ]; then
	        lscmd=`(cd $dir; ls -l $file 2>/dev/null)`
#
# Check for link portably
#
                if [ `expr "//$lscmd" : '//.*->.*'` -ne 0 ]; then
                    link=`echo "$lscmd" | awk '{ print $NF }'`
		    dirnext=`dirname $link`
		    dir=`(cd $dir; cd $dirnext; /bin/pwd)`
		    file=`basename $link`
                elif [ "$lscmd" != "" ]; then
	            echo `(cd $dir; /bin/pwd)`/$file
	            return 0
	        else
		    return 1
	        fi
	    else
		return 1
	    fi
	    n=`expr $n + 1`
        done
	return 1
    }
#
#=======================================================================
    matlab6_arch () { # Determine the architecture for MATLAB 6.x
		      # It returns the value in the ARCH variable.
		      # If 'unknown' is returned then sometimes a
		      # diagnostic message is returned in ARCH_MSG.
                      #
                      # Always returns a 0 status.
                      #
                      # usage: matlab6_arch
                      #
	ARCH="unknown"
#
	if [ -f /bin/uname ]; then
   	    case "`/bin/uname`" in
	        SunOS)					# sol2
	            if [ -d /dev/pts ]; then
		        ARCH="sol2"
	            fi
	            ;;
	        HP-UX)					# hp 700 & 800
		    majorversion=`/bin/uname -r | awk '
#-----------------------------------------------------------------------
			{ split(substr($1,3),a,"."); print a[1] }'`
#-----------------------------------------------------------------------
	            if [ -f /bin/hp9000s700 ]; then
		        (/bin/hp9000s700) > /dev/null 2>&1
		        if [ $? -eq 0 ]; then
			    if [ $majorversion -lt 11 ]; then
	    	                ARCH="hp700"
			    else
				ARCH="hpux"
			    fi
		        fi
	            fi
	            if [ -f /bin/hp9000s800 ]; then
		        (/bin/hp9000s800) > /dev/null 2>&1
		        if [ $? -eq 0 ]; then
			    if [ $majorversion -lt 11 ]; then
	    	                ARCH="hp700"
			    else
				ARCH="hpux"
			    fi
		        fi
	            fi
	            ;;
	        IRIX|IRIX64)				# sgi
    	            if [ -f /bin/4d ]; then
		        (/bin/4d) > /dev/null 2>&1
		        if [ $? -eq 0 ]; then
		            if [ -f /bin/hinv ]; then
			        ARCH_MSG=`/bin/hinv | awk '
#-----------------------------------------------------------------------
# If we want -mips4 -n32. Must be cpu >= 5000
# If we want -mips3 -n32. Must be cpu >= 4000
#
	$1 == "CPU:" { cpu = substr($3,2) + 0
		       if (cpu < 5000)
#-----------------------------------------------------------------------
print "Appears to be sgi: But processor must be at least a R5000 ..."
#-----------------------------------------------------------------------
		     }'`
#-----------------------------------------------------------------------
			        if [ "$ARCH_MSG" = "" ]; then
			            ARCH=sgi
			        fi
			    else
#-----------------------------------------------------------------------
ARCH_MSG='Appears to be sgi: But processor could not be determined ...'
#-----------------------------------------------------------------------
			    fi
			fi
		    fi
	            ;;
	        OSF1)					# alpha
	    	    ARCH="alpha"
	            ;;
	        AIX*)					# ibm_rs
#
# With AIX 4.1, uname can return more than just 'AIX'
#
	            ARCH="ibm_rs"
	            ;;
	        Linux)
		    case "`/bin/uname -m`" in
		    i*86)
			ARCH="glnx86"
			;;
		    ia64)
			ARCH="glnxi64"
			;;
		    x86_64)
			ARCH="glnxa64"
			;;
		    esac
		    ;;
# Usually uname lives in /usr/bin on the Mac, but sometimes people 
# have links in /bin that link uname to /usr/bin.  Because of this
# Mac needs to be listed in the checks for both /bin/uname and /usr/bin/uname
	        Darwin)					# Mac OS X
                    ARCH="mac"
                    ;;
	        *)
		    :
	            ;;
	    esac
	elif [ -f /usr/bin/uname ]; then
   	    case "`/usr/bin/uname`" in
	        Darwin)					# Mac OS X
                    ARCH="mac"
                    ;;
            esac
        fi
        ARCH="glnx86"
	return 0
    }
#=======================================================================
#
# The local shell function check_archlist is assume to be loaded before this
# function is sourced.
#
    ARCH_MSG=''
    check_archlist ARCH=$ARCH
    if [ "$ARCH" = "" ]; then
	if [ "$MATLAB_ARCH" != "" ]; then
	    check_archlist MATLAB_ARCH=$MATLAB_ARCH
	fi
	if [ "$ARCH" = "" ]; then
	    matlab6_arch
	fi
    fi
    Arch=$ARCH
#============================= arch.sh (end) ===============================
    if [ "$ARCH" = "unknown" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '    Sorry! We could not determine the machine architecture for your'
    echo '           host. '
    echo '      You may be attempting to install on an unsupported OS. '
    echo ''
    echo "      For a list of supported OS's, refer to the Mathworks website at:"
    echo '           http://www.mathworks.com/'
    echo ''
    echo '      or contact Mathworks Technical Support for further assistance.'
    echo ''
    echo ''
    echo '    Sorry! Setup aborted . . .'
    echo ''
#------------------------------------------------------------------------------
        exit 1
    else
	LOCAL_ARCH="$ARCH"
    fi
#                       Check OS version number [all]
#                       -----------------------------
#
#=========================== 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 - minimum version allowed to run
#                   release_ver - release version
#                   future_ver  - future version that we know doesn't work
#
#                                 Note: "-" means infinite and is allowed
#                                       only for future_ver
#
#                   version     - current version
#
#		and the environment variable:
#
#		    OSCHECK_ENFORCE_LIMITS - used to determine whether to
#					     ignore the limits when
#					     deciding how to respond.
#
#					  !=  0  (enforce limits: DEFAULT)
#					   =  0  (ignore limits)
#
#               We check for:
#
#                   minimum_ver<=release_ver<=future_ver
#
#               If this condition is not met on the current platform
#               no further analysis is done and the behavior depends
#               on the value of oscheck_debug set in this script.
#               If oscheck_debug=1 an internal error message is
#               generated and you are asked to quit. If oscheck_debug=0
#               then a normal return is done with no messages produced
#               and an attempt is made to start MATLAB.
#
#               Here are the cases tested and the resulting behavior:
#
#               If version > future_ver ||
#                  version == future_ver && release_ver < future_ver
#		     if OSCHECK_ENFORCE_LIMITS != 0
#                        too new warning message
#                        request to stop
#		     else
#                        no message
#                        continue
#               If release_ver <= version <= future_ver
#                    no message
#                    continue
#               If minimum_ver <= version <= release_ver 
#                    standard warning message
#                    continue
#               If version < minimum_ver
#		     if OSCHECK_ENFORCE_LIMITS != 0
#                        too old warning message
#                        request to stop
#		     else
#                        standard warning message
#                        continue
#
#               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
#
#                  sol2:    uname -r          -> token
#		   hpux:    uname -r          -> token(1)(3:end)
#                  glnx86:  /lib/libc.so.6    -> messy parsing to yield token 
#                  glnxi86: (fixed until more experience)
#		   glnxa86: /lib/libc.so.6    -> messy parsing to yield token
#		   mac:     uname -r	      -> token(1)
#
#               3. This requires at least the System V Bourne Shell since
#                  internal functions are used.
#
#               4. Algorithm:
#
#		   a. Generate version results.
#                  b. If no results then nothing to do.
#		   c. Otherwise fix error state depending on results
#		      and OSCHECK_ENFORCE_LIMITS.
#		   d. Output any messages.
#		   e. Handle input user interaction when
#		      action required to continue.
#
#               5. Assume that this routine is called using the
#                  unused temporary file defined by
#
#                     $temp_file
#
#               6. The calling routine will exit if the variable,
#                  oscheck_status, is set as follows:            
#
#                      oscheck_status=1
#
#               7. Also, any cleanup associated with of an interrupt
#                  will be handled by the calling routine.
#
#               8. Set oscheck_debug=1 to check for the consistency 
#                  of the data. Set oscheck_debug=0 for shipping.
#
# Copyright 1996-2004 The MathWorks, Inc.
# $Revision: 1.20.4.4 $  $Date: 2004/04/10 23:02:27 $
#----------------------------------------------------------------------------
#
    oscheck_status=0
#
#                   arch   OSprefix minimum_ver release_ver future_ver
#
    oslist="        sol2    SunOS    5.8         5.8         -"
    oslist="$oslist hpux    HP-UX    11.00       11.00       -"
    oslist="$oslist glnx86  glibc    2.2.0       2.2.5       -"
    oslist="$oslist glnxi64 glibc    2.2.4       2.2.4       -"
    oslist="$oslist glnxa64 glibc    2.3.2       2.3.2       -"
    oslist="$oslist mac     Darwin   7.2.0       7.2.0       -"
#
    if [ -f /bin/uname ]; then
        case $Arch in
            glnx86)
#
# Note: R13 used 'uname -r'. If you use ver below, we shipped with 2.1.2
#
# This may be run on either glnx86 or glnxa64. Note that things are OK
# since release_ver on glnx86 <= glnxa64.
#
# Example: first line from executing /lib/libc.so.6
# glnx86:  GNU C Library stable release version 2.2.5, by Roland McGrath et al.
# glnxa64: GNU C Library stable release version 2.3.2 (20030827), by Roland McGrath et al.
#
                ver=`/lib/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
                ;;
            glnxi64)
#
# We do not have a lot of experience yet on how things will look across multiple
# vendors. So we will pick a fixed version for now.
#
# 1. Red Hat version: ver=`/lib/libc.so.6.1 | head -1 | sed -e "s/^[^0-9]*//" -e "s/,.*$//"`
#
                ver=2.2.4
                ;;
            glnxa64)
#
# Example: first line from executing /lib64/libc.so.6
# glnxa64: GNU C Library stable release version 2.3.2 (20030827), by Roland McGrath et al.
#
                ver=`/lib64/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
                ;;
            sol2)
                ver=`/bin/uname -r`
                ;;
            hpux)  # Remove the leading capital letter and period
                ver=`/bin/uname -r | awk '{print substr($1,3)}'`
                ;;
	    Darwin)					# Mac OS X
        	ver=`/usr/bin/uname -r | awk '{print $1}'`
                ;;
            *)
		ver=`/bin/uname -r | awk '{print $1}'`
                ;;
        esac
    elif [ -f /usr/bin/uname ]; then
        case "`/usr/bin/uname`" in
	    Darwin)					# Mac OS X
                ver=`/usr/bin/uname -r | awk '{print $1}'`
                ;;
        esac
    fi
#
# Be sure that OSCHECK_ENFORCE_LIMITS has a value
#
    if [ "$OSCHECK_ENFORCE_LIMITS" = "" -o "$OSCHECK_ENFORCE_LIMITS" != "0" ]; then
	OSCHECK_ENFORCE_LIMITS=1
    fi
#
#  Set oscheck_debug=0 for shipping
#
    oscheck_debug=0
#
    results=`echo $Arch $ver "$oslist"| awk '
#---------------------------------------------------------------------------
        BEGIN { str = "0123456789"; strp = str "."
                astr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
        { 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) ""
              m[$i] = $(i+2) ""
              r[$i] = $(i+3) ""
              f[$i] = $(i+4) ""
          }
          mver = m[arch]
          rver = r[arch]
          if (rver == "") exit 
          fver = f[arch]  
#
# split the minimum version
#
          nmver = split(mver,mv,".")
          for (i = 1; i <= nmver; i = i + 1)
              if (mv[i] == "") mv[i] = 0
#
# split the release version
#
          nrver = split(rver,rv,".")
          for (i = 1; i <= nrver; i = i + 1)
              if (rv[i] == "") rv[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 - no warning
#          1 - too old warning
#          2 - warning
#          3 - too new warning
#          4 - internal error (not shipped)
#
          errmode = 0
#
# check: minimum_ver<=release_ver<=future_ver
#        minimum_ver != "-"
#        release_ver != "-"
#
          if (nmver < nrver)
              ncd = nmver
          else 
              ncd = nrver
          for (i = 1; i <= ncd; i = i + 1)
              if (mv[i] + 0 > rv[i] + 0) {
                   errmode = 4
                   break
              }
              else if (mv[i] + 0 < rv[i] + 0)
                   break
          if (errmode == 0 && i == ncd + 1 && nmver > nrver)
              for (i = ncd + 1; i <= nmver; i = i + 1)
                  if (mv[i] + 0 != 0 ) {
                      errmode = 4
                      break
                  }
          if (errmode == 0 && fver != "-") {
              if (nrver < nfver)
                  ncd = nmver
              else 
                  ncd = nfver
              for (i = 1; i <= ncd; i = i + 1)
                  if (rv[i] + 0 > fv[i] + 0) {
                      errmode = 4
                      break
                  }
                  else if (rv[i] + 0 < fv[i] + 0)
                      break
              if (errmode == 0 && i == ncd + 1 && nrver > nfver)
                  for (i = ncd + 1; i <= nrver; i = i + 1)
                      if (rv[i] + 0 != 0 ) {
                          errmode = 4
                          break
                      }
          }
          if (errmode == 0 && nmver == 1 && mver == "-")
              errmode = 4
          else if (errmode == 0 && nrver == 1 && rver == "-")
              errmode = 4
#
# check whether release_ver < future_ver (futuremode = 1)
#
          if (errmode == 0) {
              futuremode = 1
              if (fver != "-") {
                  if (nrver < nfver)
                      ncd = nrver
                  else
                      ncd = nfver
                  futuremode = 0
                  for (i = 1; i <= ncd; i = i + 1)
                      if (rv[i] + 0 < fv[i] + 0) {
                          futuremode = 1
                          break
                      }
                 if (futuremode == 0)
                     for (i = ncd + 1; i <= nfver; i = i + 1)
                         if (fv[i] + 0 != 0) {
                             futuremode = 1
                             break
                         }
              }
          }
#
# check if version > future_ver ||
#          version == future_ver && release_ver < future_ver
#
          if (errmode == 0 && fver != "-") {
              if (nfver < nver)
                  ncd = nfver
              else
                  ncd = nver
              for (i = 1; i <= ncd; i = i + 1)
                  if (v[i] + 0 > fv[i] + 0) {
                      errmode = 3
                      break
                  }
                  else if (v[i] + 0 < fv[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)
                          break
                  if (i == nfver + 1 && futuremode == 1)
                      errmode = 3
                  else if (i == nfver + 1 && futuremode == 0)
#
# case: version == future_ver && release_ver == future_ver
#
                      exit
              }
              else if (errmode == 0 && i == ncd + 1 && ncd == nfver) {
                  for (i = ncd + 1; i <= nver; i = i + 1)
                      if (v[i] + 0 != 0) {
                          errmode = 3
                          break
                      }
                  if (i == nver + 1 && futuremode == 1)
                      errmode = 3
                  else if (i == nver + 1 && futuremode == 0)
#
# case: version == future_ver && release_ver == future_ver
#
                      exit
              }
          }
#
# check if release_ver <= 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)
                      break
                  else if (rv[i] + 0 < v[i] + 0)
                      exit
              if (i == ncd + 1 && ncd == nrver)
                  exit
              else if (i == ncd + 1 && ncd == nver) {
                  for (i = ncd + 1; i <= nrver; i = i + 1)
                      if (rv[i] + 0 != 0)
                          break
                  if (i == nrver + 1)
                      exit
              }
          }   
#
# check if minimum_ver <= version || version < minimum_ver
#
          if (errmode == 0) {
              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
                      break
                  }
                  else if (mv[i] + 0 < v[i] + 0) {
                      errmode = 2
                      break
                  }
              if (i == ncd + 1 && ncd == nmver) {
                  errmode = 2
              }
              else if (i == ncd + 1 && ncd == nver) {
                  for (i = ncd + 1; i <= nmver; i = i + 1)
                      if (mv[i] + 0 != 0) {
                          errmode = 1
                          break
                      }
                  if (i == nmver + 1) 
                      errmode = 2
              }
          }   
	  print errmode, n[arch], ver, mver, rver, fver
        }'`
#---------------------------------------------------------------------------
#
# No results means no error.
#
    if [ "$results" != "" ]; then
        errmode=`echo $results | awk '{ print $1}'`
        errflag=$errmode
#
# Fix errflag depending on the value of $OSCHECK_ENFORCE_LIMITS
#
        if [ "$errmode" = "1" -a "$OSCHECK_ENFORCE_LIMITS" = "0" ]; then
	    errflag=2
        elif [ "$errmode" = "3" -a "$OSCHECK_ENFORCE_LIMITS" = "0" ]; then
	    errflag=0
        fi
#
        echo $errflag $results $oscheck_debug | awk '
#---------------------------------------------------------------------------
	{ errmode = $1
	  arch = $3
	  ver = $4
	  mver = $5
	  rver = $6
	  fver = $7
	  debug = $8
          if (errmode == 1) {
print " "   
print "----------------------------------------------------------------------------"
printf "Warning: %s %-10s - Unsupported version\n", arch, ver
printf "         %s %-10s - MATLAB built using this version\n", arch, rver
print "----------------------------------------------------------------------------"
          }
          else if (errmode == 2) {
print " "   
print "----------------------------------------------------------------------------"
printf "Warning: %s %-10s - Your version\n", arch, ver
printf "         %s %-10s - MATLAB built using this version\n", arch, rver
print "----------------------------------------------------------------------------"
          }
          else if (errmode == 3) {
print " "   
print "----------------------------------------------------------------------------"
printf "Warning: %s %-10s - Unqualified version\n", arch, ver
printf "         %s %-10s - MATLAB built using this version\n", arch, rver
print "----------------------------------------------------------------------------"
          }
          else if (errmode == 4) {
              if (debug == 0) exit
print " "   
print "----------------------------------------------------------------------------"
printf "Error: %s %-10s - Internal Error - oscheck.sh has inconsistent data\n", arch, ver
printf "       %s %-10s - Minimum supported version\n", arch, mver
printf "       %s %-10s - MATLAB built using this version\n", arch, rver
printf "       %s %-10s - Maximum supported version\n", arch, fver
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
            errtype=`cat $temp_file | awk 'NR == 3 {print $5}'`
            case "$errtype" in
                'Unsupported')
#---------------------------------------------------------------------------
echo '-> Your configuration APPEARS to be too OLD to run this MATLAB program!'
echo '----------------------------------------------------------------------------'
#---------------------------------------------------------------------------
                    ;;
                'Unqualified')
#---------------------------------------------------------------------------
echo '-> Your configuration APPEARS to be too NEW to run this MATLAB program!'
echo '----------------------------------------------------------------------------'
#---------------------------------------------------------------------------
                    ;;
                'Your')
		    if [ "$errmode" = "1" ]; then
#---------------------------------------------------------------------------
echo '-> Please Note: This program may work on this host but MATLAB will not!'
echo '----------------------------------------------------------------------------'
echo 'Please wait . . .'
echo ' '
#---------------------------------------------------------------------------
		        sleep 5
		    else
#---------------------------------------------------------------------------
echo ' '
#---------------------------------------------------------------------------
		    fi
		    ;;
                 *)
                    :
                    ;;
            esac
#
            case "$errtype" in
                'Unsupported'|'Unqualified')
#---------------------------------------------------------------------------
echo '   For system requirements consult http://www.mathworks.com ...'
#---------------------------------------------------------------------------
                    ;;
                'Internal')
#---------------------------------------------------------------------------
echo 'Please report this problem to The MathWorks, Inc. Technical Support'
echo '       phone: (508) 647-7000'
echo '       email: support@mathworks.com'
#---------------------------------------------------------------------------
                    ;;
                 *)
                    :
                    ;;
            esac
#
            case "$errtype" in
                'Unsupported'|'Unqualified'|'Internal')
#---------------------------------------------------------------------------
echo ' '
echo '***************************************************************************'
echo '-> Best to quit by pressing <return> at the next prompt ...'
echo ' '
echon '   Do you still want to try to continue? (y/[n]) > '
#---------------------------------------------------------------------------
                    if [ "$batch" != "1" ]; then
                        read ans
                        if [ `expr "//$ans" : '//[Yy].*'` -gt 0 ]; then
                            :
                        else
                            oscheck_status=1
                        fi
                    else
#---------------------------------------------------------------------------
     echo 'y'               
#---------------------------------------------------------------------------
                    fi
#---------------------------------------------------------------------------
echo ' '
#---------------------------------------------------------------------------
                    ;;
                 *)
                    :
                    ;;
            esac
	fi
    fi
    rm -f $temp_file
#============================ oscheck.sh (end) =============================
    if [ "$oscheck_status" = "1" ]; then
        exit 1
    fi
#
# Map names so that this install can be run on the CDROM.
#
# Determine value of TMW_CD_FORMAT by looking at the value of the
# 'command' variable which is the ISO 9660 version of 'install'.
#
    cdtype=1
    TMW_CD_FORMAT=;  export TMW_CD_FORMAT
    case "$command" in
	'install')	# ufs, sgi, alpha
	    TMW_CD_FORMAT='sgi'
            . $dir/update/install/mapname.sh
            dir=$dir/update/install
	    ;;
	'install.')	# sun4, sol2, ibm_rs
	    TMW_CD_FORMAT='sun'
            . $dir/update/install/mapname.sh
            dir=$dir/update/install
	    ;;
	'INSTALL')	# dec_risc
	    TMW_CD_FORMAT='dec'
            . $dir/UPDATE/INSTALL/MAPNAME.SH
            dir=$dir/UPDATE/INSTALL
	    ;;
	'INSTALL.;1')	# hp700, hp300
	    TMW_CD_FORMAT='hp'
            . $dir/UPDATE/INSTALL/'MAPNAME.SH;1'
            dir=$dir/UPDATE/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
#
#   Set library path to find the installer's shared libraries
    case "$ARCH" in
	"mac")	
           if [ "$DYLD_LIBRARY_PATH" != "" ]; then
               DYLD_LIBRARY_PATH=$cd_bin:$DYLD_LIBRARY_PATH
           else
               DYLD_LIBRARY_PATH=$cd_bin
           fi
           export DYLD_LIBRARY_PATH
	   ;;
	"hpux")	
           if [ "$SHLIB_PATH" != "" ]; then
               SHLIB_PATH=$cd_bin:$SHLIB_PATH
           else
               SHLIB_PATH=$cd_bin
           fi
           export SHLIB_PATH
	   ;;
	"sol2"|"glnx86"|"glnxi64")	
           if [ "$LD_LIBRARY_PATH" != "" ]; then
               LD_LIBRARY_PATH=$cd_bin:$LD_LIBRARY_PATH
           else
               LD_LIBRARY_PATH=$cd_bin
           fi
           export LD_LIBRARY_PATH
	   ;;
    esac
#
    . $dir/$main_sh

