#! /bin/sh
#set -x
#
#  Name:
#     install_matlab    point of entry for all MATLAB 6.x installations
#
#  Usage:
#     install_matlab [-h|-help] | -r | [-d] [-t] [-b|-m] [1] [-u] -x |
#			          [-d] [-t] [-b|-m] [1] [-u] -X |
#			          [-d] [-t] [-b|-m] [-u] [-arch] [type]
#
#  Description:
#     "install_matlab" is the point of entry for all MATLAB 6.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.
#
#	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 .matlab6rc.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.  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]
#
#	5.  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_TMW12 -> $MATLAB/etc/lmboot
#		/etc/lmdown_TMW12 -> $MATLAB/etc/lmdown
#	    [1, 4]
#
# Options:
#
#     -h
#     -help
#	    Help. Show command usage.
#
#     -b
#	    Batch mode. Ignore all queries to continue. Cannot be
#	    be specified with -m option.
#
#     -m
#	    Minimal install. Do not allow changes to anything outside the
#	    MATLAB root directory. Cannot be specified with -b option.
#	
#     -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.
#
#     -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
#		4 - license manager only
#
# Notes:
#
#	1. required commands: awk, chmod, cat, clear, cp, echo, expr, find,
#			      hostname, mkdir, more, mv, rm, sed, tar, umask,
#			      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_l.sh, intro_s.sh,
#		lm.sh, local.sh, netruser.sh, oldname.sh, options.sh,
#		perm.sh, ruser.sh, searchp.sh, verifyp.sh,
#		version.sh
#
#		ucleanpe.sh, update.sh
#
#		mapname.sh, arch.sh oscheck.sh* 
#
#	   * imbedded
#
#	5. batch scripts:
#
#		batch1.sh, batch4.sh
#
#	6. Flow of control for types of install
#
#==========================================================================
#
# Copyright (c) 1992-2000 The MathWorks, Inc.
# $Revision: 1.82 $  $Date: 2000/07/27 19:42:14 $
#--------------------------------------------------------------------------
#
    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 ()
#=======================================================================
    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
    }
#=======================================================================
#
#**************************************************************************
# 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 1997-2000 The MathWorks, Inc.
# $Revision: 1.8 $  $Date: 2000/06/16 16:08:59 $
#----------------------------------------------------------------------------
#
    ARCH_LIST='sol2 hpux hp700 alpha ibm_rs sgi glnx86'
#=======================================================================
# 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.16 $  $Date: 2000/08/31 21:58:11 $
#----------------------------------------------------------------------------
#
#=======================================================================
# 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)
		    if [ -e /lib/libc.so.6 ]; then
			ARCH_MSG=`realfilepath /lib/libc.so.6 | awk '
#-----------------------------------------------------------------------
	BEGIN { num = "0123456789" }
	{ n = split($1,path,"/")
	  file = path[n]
#
# Get the version by shaving off the front and back until a digit
# is found.
#
	  for (i = 1; i <= length(file); i = i + 1) {
	      ix = index(num,substr(file,i,1))
	      if (ix != 0) break
	  }
	  ix = i
	  for (i = length(file); i >= 1; i = i - 1) {
	      ix2 = index(num,substr(file,i,1))
	      if (ix2 != 0) break
	  }
	  ix2 = i
	  if (ix2 < ix) {
#-----------------------------------------------------------------------
print "Appears to be Linux: But libc.so.6 version could not be determined ..."
#-----------------------------------------------------------------------
	     exit
	  }
	  n = split(substr(file,ix,ix2 - ix + 1),ver,".")
#
# We must have version >= 2.1
#
	  if (ver[1] + 0 >= 2 && n >= 2 && ver[2] + 0 >= 1) exit
#
# Just libc.so.6 - Assume OK.
#
	  if (substr(file,1,ix-2) == "libc.so" && ver[1] + 0 >= 6 && n == 1) exit
#
#-----------------------------------------------------------------------
print "Appears to be Linux: But libc.so.6 version must be at least 2.1 ..." 
#-----------------------------------------------------------------------
	}'`
#-----------------------------------------------------------------------
			if [ "$ARCH_MSG" = "" ]; then
			    ARCH="glnx86"
			fi
		    else
#-----------------------------------------------------------------------
ARCH_MSG='Appears to be Linux: But a version using libc.so.6 is required ...'
#-----------------------------------------------------------------------
		    fi
		    ;;
	        *)
		    :
	            ;;
	    esac
	fi
	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.  The most likely cause is that /bin/uname or /bin/arch'
    echo '           are returning unexpected results.'
    echo ''
    echo '           If /bin/uname exists, we expect it to return either SunOS,'
    echo '           HP-UX, OSF1, AIX, IRIX, or Linux.  If /bin/uname does not'
    echo '           exist, we expect /bin/arch to produce either sol2, hpux,'
    echo '           hp700, alpha, ibm_rs, sgi, or glnx86. If the output of uname'
    echo '           or arch is incorrect, contact your OS vendor directly to help'
    echo '           fix this.'
    echo ''
    echo '           Another possibility is that you are attempting to install on an'
    echo "           unsupported OS.  For a list of supported OS's, refer to the "
    echo '           Mathworks website at: http://www.mathworks.com/'
    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 - 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 testing 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
#                  hp700:  uname -r          -> token(1)(3:end)
#		   hpux:   uname -r          -> token(1)(3:end)
#                  alpha:  uname -v -r       -> token(1)(2:end).token(2)
#                  ibm_rs: /usr/bin/oslevel  -> token
#                  sgi:    uname -r          -> token
#                  glnx86: uname -r          -> token                   
#                  
#               3. Cases to watch out for
#
#		   hp700:  B.11.00	- starts with a capital letter and
#					  a period.
#                  OSF1:   V4.0 1229    - first token starts with v or V. 
#
#               4. This requires at least the System V Bourne Shell since
#                  internal functions are used.
#
#               5. 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.
#
#               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.
#
#               9. Set oscheck_debug=1 to check for the consistency 
#                  of the data. Set oscheck_debug=0 for shipping.
#
# Copyright 1996-2000 The MathWorks, Inc.
# $Revision: 1.19 $  $Date: 2000/08/31 21:58:13 $
#----------------------------------------------------------------------------
#
    oscheck_status=0
#
#                   arch   OSprefix minimum_ver release_ver future_ver
#
    oslist="        sol2   SunOS    5.5.1       5.6         -"
    oslist="$oslist hp700  HP-UX    10.00       10.20       -"
    oslist="$oslist hpux   HP-UX    11.00       11.00       -"
    oslist="$oslist alpha  OSF1     4.0.1229    4.0.1229    -"
    oslist="$oslist ibm_rs AIX      4.3.3.0     4.3.3.0     -"
    oslist="$oslist sgi    IRIX     6.5         6.5         -"
    oslist="$oslist glnx86 Linux    2.2.1       2.2.15      -"
#
    if [ -f /bin/uname ]; then
        case $Arch in
            sol2|sgi|glnx86)
                ver=`/bin/uname -r`
                ;;
            hp700)  # Remove the leading capital letter and period
                ver=`/bin/uname -r | awk '{print substr($1,3)}'`
                ;;
            hpux)  # Remove the leading capital letter and period
                ver=`/bin/uname -r | awk '{print substr($1,3)}'`
                ;;
            alpha)  # Remove the leading V(v) from the first token and
		    # combine with the second token separated by a period
                ver=`/bin/uname -v -r | awk '{print substr($1,2) "." $2 }'`
                ;;
            ibm_rs)
		ver=`/usr/bin/oslevel`
                ;;
            *)
                ver=`/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 Operating System\n", arch, ver
printf "         %s %-10s - MATLAB built using this Operating System\n", arch, rver
print "----------------------------------------------------------------------------"
          }
          else if (errmode == 2) {
print " "   
print "----------------------------------------------------------------------------"
printf "Warning: %s %-10s - Your Operating System\n", arch, ver
printf "         %s %-10s - MATLAB built using this Operating System\n", arch, rver
print "----------------------------------------------------------------------------"
          }
          else if (errmode == 3) {
print " "   
print "----------------------------------------------------------------------------"
printf "Warning: %s %-10s - Unqualified Operating System\n", arch, ver
printf "         %s %-10s - MATLAB built using this Operating System\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 Operating System\n", arch, mver
printf "       %s %-10s - MATLAB built using this Operating System\n", arch, rver
printf "       %s %-10s - Maximum supported Operating System\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 Operating System APPEARS to be too OLD to run this MATLAB program!'
echo '----------------------------------------------------------------------------'
#---------------------------------------------------------------------------
                    ;;
                'Unqualified')
#---------------------------------------------------------------------------
echo '-> Your Operating System 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
	    OSCHECK_DONE=1; export OSCHECK_DONE
            sleep 3
	else
	    OSCHECK_DONE=1; export OSCHECK_DONE
	fi
    fi

#
#                       Augment path [all]
#                       ------------
    case "$ARCH" in
        sgi)
           PATH=$PATH:/usr/bsd:/usr/sbin
           export PATH
           ;;
        *) ;;
    esac
#
# Add $MATLAB/update/bin/$ARCH to get zcat unless called from
# CD-ROM. The PATH has already been fixed if called from the
# CD-ROM.
#
    if [ "$CD_ROOT" = "" ]; then
        PATH=$MATLAB/update/bin/$ARCH:$PATH
        export PATH
    fi
#
    if [ "$batch" = "" ]; then
	batch=0
    fi
#
    . $dir/update/install/scripts/mapname.sh
    dir=$dir/update/install/scripts
#
    . $dir/$main_sh
#
