#!/bin/sh # # Name: # install - script file for invoking the Multi-platform installer on Linux. # # Usage: install [-h|help]" # [-javadir ] | [-root ] |" # [-test] | [-v|-verbose]" # -h|-help - Display arguments." # -test - Don't actually run the java # command (only useful with -v)." # -v|-verbose - Display settings." # -javadir - Override default java root directory." # -root - Override default DVD root directory." # # The default settings when no override inputs are supplied are: " # -root = " # -javadir = /sys/java/jre/$ARCH/jre' # # # Copyright 2009-2011 The MathWorks, Inc. #__________________________________________________________________________ # arg0_=$0 # # trap "exit 1" 1 2 3 15 # #========================= java_launcher (start) ============================ # #========================= 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-2007 The MathWorks, Inc. # $Revision: 1.1.6.3 $ $Date: 2007/11/12 22:52:47 $ #---------------------------------------------------------------------------- # ARCH_LIST='glnx86 glnxa64 mac maci maci64 sol2 sol64' #======================================================================= # 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) ============================== ARCH= #========================= 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-2007 The MathWorks, Inc. # $Revision: 1.1.6.6 $ $Date: 2010/09/20 14:06:43 $ #---------------------------------------------------------------------------- # #======================================================================= # Functions: # realfilepath () # matlab_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 } # #======================================================================= set_mac_arch() { # First check to see if maci64 is even possible on this hardware if [ "`/usr/sbin/sysctl -n hw.cpu64bit_capable`" = "0" ]; then # maci64 is not possible. So set the arch to maci. ARCH="maci" return fi # Now check to see if maci64 is asked for if [ "$MACI64" = "0" ]; then # only maci is wanted, so arch is maci. ARCH="maci" return fi # If we get to this point, maci64 is available and desired. So, check to # see if 64 bit binaries are available. First, if $MATLABROOT is NOT # set, we can't really check for anything else. if [ "$MATLABROOT" = "" ]; then ARCH="maci64"; return fi # if we get to this point, we need to check the binaries that we have to # find out if we have maci64 binaries if [ -d "$MATLABROOT/bin/maci64" ]; then ARCH="maci64" return fi # if we get to this point, even though maci64 is possible and desired, # the maci64 binaries aren't available, so fall back to maci ARCH="maci" } # #======================================================================= matlab_arch () { # Determine the architecture for MATLAB # 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: matlab_arch # ARCH="unknown" # if [ -f /bin/uname ]; then case "`/bin/uname`" in SunOS) # Solaris case "`/bin/uname -p`" in sparc) ARCH="sol64" ;; i386) ARCH="sola64" ;; esac ;; Linux) case "`/bin/uname -m`" in i*86) ARCH="glnx86" ;; 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 case "`/bin/uname -p`" in i386) set_mac_arch ;; esac ;; *) : ;; esac elif [ -f /usr/bin/uname ]; then case "`/usr/bin/uname`" in Darwin) # Mac OS X case "`/usr/bin/uname -p`" in i386) set_mac_arch ;; esac ;; esac fi return 0 } #======================================================================= # # The local shell function check_archlist is assumed 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 matlab_arch fi fi Arch=$ARCH #========================= arch.sh (end) ============================== setMac () { if [ "$ARCH" = "maci" -o "$ARCH" = "maci64" ]; then ISMAC=1 else ISMAC=0 fi export ISMAC } #======================================================================= setVMenvironment () { # Set up some variables for the VM environment # Augment with AWT Motif default locale resource files XFILESEARCHPATH="$JRE_LOC/lib/locale/%L/%T/%N%S:$XFILESEARCHPATH" export XFILESEARCHPATH # Determine for each platform # libraryPathsToAdd=$1 case "$ARCH" in glnx*) LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`" if [ "$LD_LIBRARY_PATH" != "" ]; then LD_LIBRARY_PATH="$libraryPathsToAdd":$LD_LIBRARY_PATH else LD_LIBRARY_PATH="$libraryPathsToAdd" fi export LD_LIBRARY_PATH ;; mac*) DYLD_LIBRARY_PATH="`eval echo $DYLD_LIBRARY_PATH`" if [ "$DYLD_LIBRARY_PATH" != "" ]; then DYLD_LIBRARY_PATH="$libraryPathsToAdd":$DYLD_LIBRARY_PATH else DYLD_LIBRARY_PATH="$libraryPathsToAdd" fi export DYLD_LIBRARY_PATH ;; *) LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`" if [ "$LD_LIBRARY_PATH" != "" ]; then LD_LIBRARY_PATH=$LD_LIBRARY_PATH else LD_LIBRARY_PATH= fi export LD_LIBRARY_PATH ;; esac } #======================================================================= setVMpath () { # # Determine the java vm path for each platform. # if [ $ISMAC -eq 1 ]; then JAVA_HOME_CMD=/usr/libexec/java_home # Newer Macs have the java_home command, # older ones (some 10.5 machines) might not. This check # can be removed once 10.5 is no longer supported if [ ! -f $JAVA_HOME_CMD ]; then DEFAULT_JRE_LOC=/Library/Java/Home else # Ask for a 64-bit Java 1.6 (or higher) VM DEFAULT_JRE_LOC=`$JAVA_HOME_CMD -v 1.6+ -d64 -F` if [ $? != 0 ]; then # java_home couldn't find what we want so error out echo "Error: Cannot locate Java Runtime Environment (JRE)." exit 1 fi fi else javaRoot=$1 DEFAULT_JRE_LOC=$javaRoot/jre/$ARCH/jre # If the JRE doesn't exist and we are on glnxa64, try to fall back to glnx86 if [ ! -d "$DEFAULT_JRE_LOC" ]; then if [ "$ARCH" = "glnxa64" ]; then echo "Could not find JRE for glnxa64. Trying glnx86." ARCH=glnx86 DEFAULT_JRE_LOC=$javaRoot/jre/$ARCH/jre fi fi fi if [ "$JRE_LOC" = "" ]; then JRE_LOC=$DEFAULT_JRE_LOC fi # # Look for JRE # if [ ! -d "$JRE_LOC" ]; then echo "---------------------------------------------------------------------------" echo "Error: Cannot locate Java Runtime Environment (JRE)." echo "The directory $JRE_LOC does not exist." echo "---------------------------------------------------------------------------" exit 1 fi } #======================================================================= getJarPaths () { # Get the full search path for our jar files # Echos the search path to stdout. JAVA_DIR="$1/java" JAR_LOC="$JAVA_DIR/jar" JAREXT_LOC="$JAVA_DIR/jarext" JAR_SEARCH_PATHtmp=$JRE_LOC/lib/ext:$JAR_LOC:$JAREXT_LOC # Get list of directories in JAREXT_LOC theDirList=`ls -1Ap $JAREXT_LOC | grep '/'` # Add all subdirectories of JAREXT_LOC (but not recursively) for aDir in $theDirList do JAR_SEARCH_PATHtmp=$JAR_SEARCH_PATHtmp:$JAREXT_LOC/$aDir done # If MW_LIB_EXT_DIRS env var set, append value to existing search path if [ "$MW_LIB_EXT_DIRS" != "" ]; then JAR_SEARCH_PATHtmp=$JAR_SEARCH_PATHtmp:$MW_LIB_EXT_DIRS fi echo $JAR_SEARCH_PATHtmp } #======================================================================= copyDirWritable() { # Copy an entire directory. This will create the destination # directory, do a recursive copy, and then make all the files and # directories writable. # usage: copyDirWritable src dest srcDir=$1 destDir=$2 mkdir -p "$destDir" (cd "$srcDir"; cp -RLf * "$destDir") chmod -R +w "$destDir" 2>/dev/null } #========================= java_launcher (end) ============================== copyJREAndJarsToTmp () { # # Copy JRE and Jars to tmp # echo "Preparing installation files ..." if [ $ISMAC -eq 0 ]; then NEW_JRE_LOC="$TEMP_DIR/sys/java/jre/$ARCH/jre" copyDirWritable "$JRE_LOC" $NEW_JRE_LOC JRE_LOC=$NEW_JRE_LOC fi JAVA_DIR="$TEMP_DIR/java" JAR_LOC="$JAVA_DIR/jar" JAREXT_LOC="$JAVA_DIR/jarext" copyDirWritable "$ROOT/java" "$JAVA_DIR" } #======================================================================= getJavaLaunchTarget () { # Find jar file to execute. # TODO: Consolidate this code with getClassName() from activation and # move to java_launcher_template MAIN_CLASS="com/mathworks/installwizard/Launcher" BOOTSTRAP_PROPERTIES=$ROOT/java/bootstrap.properties if [ -f "$BOOTSTRAP_PROPERTIES" ]; then MAIN_CLASS_OVERRIDE=`grep -i mainclass "$BOOTSTRAP_PROPERTIES" | awk -F= '{ print $2 }' | sed 's/ //g'` if [ "$MAIN_CLASS_OVERRIDE" != "" ]; then MAIN_CLASS=$MAIN_CLASS_OVERRIDE fi fi # By default, set launch target to main class JAVA_LAUNCH_TARGETtmp=$MAIN_CLASS # If MW_MAIN_CLASS env var set, set launch target to "$MW_MAIN_CLASS" if [ "$MW_MAIN_CLASS" != "" ]; then JAVA_LAUNCH_TARGETtmp=$MW_MAIN_CLASS fi echo $JAVA_LAUNCH_TARGETtmp } #======================================================================= # # Parse the arguments # stat="OK" JAR_LOC= JAREXT_LOC= JAR_SEARCH_PATH= VERBOSE=0 TEMP_DIR="/tmp/mathworks_$$"; JRE_LOC= XTRAFLAGS= TESTONLY=0 arglist= # Set default values for some variables if they are not set yet. if [ "$ROOT" = "" ]; then SETUP_FILE=`realfilepath "$0"` ROOT=`dirname "$SETUP_FILE"` fi SPLASH_OPTION="-splash:$ROOT/java/splash.png" while [ "$stat" = "OK" -a $# -gt 0 ]; do case "$1" in -h|-help) stat="" ;; -v|-verbose) VERBOSE=1; ;; -javadir) if [ $# -eq 1 ]; then echo "A JRE directory must be specified with -javadir." stat="" else shift JRE_LOC=$1; if [ ! -d "$JRE_LOC" ]; then echo "The directory $JRE_LOC does not exist." stat="" fi if [ ! -d "$JRE_LOC/lib" ]; then echo "$JRE_LOC does not appear to be a JRE directory." stat="" fi fi ;; -root) if [ $# -eq 1 ]; then echo "A DVD directory must be specified with -root." stat="" else shift ROOT=$1; if [ ! -d "$ROOT" ]; then echo "The directory $ROOT does not exist." stat="" else SPLASH_OPTION="-splash:$ROOT/java/splash.png" fi fi ;; -test) # Just run through script without actually running the java # command. Only useful with -v. TESTONLY=1 ;; -psn*) # Apple passes this in with things that are double clicked. Ignore. ;; -*) OPTION=$1 OPTION="$(echo ${OPTION} | tr '[:upper:]' '[:lower:]')" if [ $OPTION == "-mode" ]; then SPLASH_OPTION="" fi if [ $OPTION == "-inputfile" ]; then SPLASH_OPTION="" fi found=0 # Check for -arch arch=$ARCH check_archlist argument=$1 noprint if [ "$ARCH" != "" ]; then found=1 else ARCH=$arch fi if [ "$found" = "0" ]; then arglist="$arglist $1" fi ;; *) arglist="$arglist $1" ;; esac shift done setMac # # Check for errors # if [ "$stat" != "OK" ]; then # An error occurred. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo "" echo " Usage: install [-h|help]" echo " [-javadir ] | [-root ] |" echo " [-test] | [-v|-verbose]" echo "" echo " -h|-help - Display arguments." echo " -test - Don't actually run the java command (only useful with -v)." echo " -v|-verbose - Display settings." echo " -javadir - Override default java root directory." echo " -root - Override default DVD root directory." echo "" echo " The default settings when no override inputs are supplied are: " echo " -root = " echo ' -javadir = /sys/java/jre/$ARCH/jre' echo "" #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exit 1 fi # Determine the java vm path for each platform. setVMpath "$ROOT/sys/java" copyJREAndJarsToTmp # Set up some variables for the VM environment. setVMenvironment "$ROOT/bin/$ARCH" # Get the jar directories JAR_SEARCH_PATH=`getJarPaths "$TEMP_DIR"` # Get the java launch target JAVA_LAUNCH_TARGET=`getJavaLaunchTarget` # Set up java command to run. if [ $ISMAC -eq 1 ]; then XTRAFLAGS="-d64 -Xdock:name=\"Install MATLAB\" -Xdock:icon=\"$ROOT/InstallForMacOSX.app/Contents/Resources/membrane.icns\" -Xmx512m" fi java_exe=$JRE_LOC/bin/java java_cmd="$java_exe $XTRAFLAGS $SPLASH_OPTION -Djava.ext.dirs=$JAR_SEARCH_PATH $JAVA_LAUNCH_TARGET -root \"$ROOT\" $arglist" # if [ "$VERBOSE" = "1" ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo "-> DVD = $ROOT" echo "-> ARCH = $ARCH" echo "-> DISPLAY = $DISPLAY" echo "-> TESTONLY = $TESTONLY" echo "-> JRE_LOC = $JRE_LOC" # case "$ARCH" in mac*) echo "-> DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH" ;; *) echo "-> LD_LIBRARY_PATH = $LD_LIBRARY_PATH" ;; esac echo " " echo "Command to run:" echo "$java_cmd" echo " " #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fi # # # Run the java command to start the install app if [ "$TESTONLY" != "1" ]; then echo "Installing ..." eval $java_cmd fi # Clean up rm -rf $TEMP_DIR echo "Finished"