Guest User

Untitled

a guest
Jan 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.95 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Name:
  4. # install - script file for invoking the Multi-platform installer on Linux.
  5. #
  6. # Usage: install [-h|help]"
  7. # [-javadir <directory>] | [-root <directory>] |"
  8. # [-test] | [-v|-verbose]"
  9. # -h|-help - Display arguments."
  10. # -test - Don't actually run the java
  11. # command (only useful with -v)."
  12. # -v|-verbose - Display settings."
  13. # -javadir <directory> - Override default java root directory."
  14. # -root <directory> - Override default DVD root directory."
  15. #
  16. # The default settings when no override inputs are supplied are: "
  17. # -root = <directory containing this script>"
  18. # -javadir = <root>/sys/java/jre/$ARCH/jre'
  19. #
  20. #
  21. # Copyright 2009-2011 The MathWorks, Inc.
  22. #__________________________________________________________________________
  23. #
  24. arg0_=$0
  25. #
  26. #
  27. trap "exit 1" 1 2 3 15
  28. #
  29. #========================= java_launcher (start) ============================
  30. #
  31. #========================= archlist.sh (start) ============================
  32. #
  33. # usage: archlist.sh
  34. #
  35. # abstract: This Bourne Shell script creates the variable ARCH_LIST.
  36. #
  37. # note(s): 1. This file is always imbedded in another script
  38. #
  39. # Copyright 1997-2007 The MathWorks, Inc.
  40. # $Revision: 1.1.6.3 $ $Date: 2007/11/12 22:52:47 $
  41. #----------------------------------------------------------------------------
  42. #
  43. ARCH_LIST='glnx86 glnxa64 mac maci maci64 sol2 sol64'
  44. #=======================================================================
  45. # Functions:
  46. # check_archlist ()
  47. #=======================================================================
  48. check_archlist () { # Sets ARCH. If first argument contains a valid
  49. # arch then ARCH is set to that value else
  50. # an empty string. If there is a second argument
  51. # do not output any warning message. The most
  52. # common forms of the first argument are:
  53. #
  54. # ARCH=arch
  55. # MATLAB_ARCH=arch
  56. # argument=-arch
  57. #
  58. # Always returns a 0 status.
  59. #
  60. # usage: check_archlist arch=[-]value [noprint]
  61. #
  62. if [ $# -gt 0 ]; then
  63. arch_in=`expr "$1" : '.*=\(.*\)'`
  64. if [ "$arch_in" != "" ]; then
  65. ARCH=`echo "$ARCH_LIST EOF $arch_in" | awk '
  66. #-----------------------------------------------------------------------
  67. { for (i = 1; i <= NF; i = i + 1)
  68. if ($i == "EOF")
  69. narch = i - 1
  70. for (i = 1; i <= narch; i = i + 1)
  71. if ($i == $NF || "-" $i == $NF) {
  72. print $i
  73. exit
  74. }
  75. }'`
  76. #-----------------------------------------------------------------------
  77. if [ "$ARCH" = "" -a $# -eq 1 ]; then
  78. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79. echo ' '
  80. echo " Warning: $1 does not specify a valid architecture - ignored . . ."
  81. echo ' '
  82. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  83. fi
  84. else
  85. ARCH=""
  86. fi
  87. else
  88. ARCH=""
  89. fi
  90. #
  91. return 0
  92. }
  93. #=======================================================================
  94. #========================= archlist.sh (end) ==============================
  95. ARCH=
  96. #========================= arch.sh (start) ============================
  97. #!/bin/sh
  98. #
  99. # usage: arch.sh
  100. #
  101. # abstract: This Bourne Shell script determines the architecture
  102. # of the the current machine.
  103. #
  104. # ARCH - Machine architecture
  105. #
  106. # IMPORTANT: The shell function 'check_archlist' is used
  107. # by this routine and MUST be loaded first.
  108. # This can be done by sourcing the file,
  109. #
  110. # archlist.sh
  111. #
  112. # before using this routine.
  113. #
  114. # note(s): 1. This routine must be called using a . (period)
  115. #
  116. # 2. Also returns ARCH_MSG which may contain additional
  117. # information when ARCH returns 'unknown'.
  118. #
  119. # Copyright 1986-2007 The MathWorks, Inc.
  120. # $Revision: 1.1.6.6 $ $Date: 2010/09/20 14:06:43 $
  121. #----------------------------------------------------------------------------
  122. #
  123. #=======================================================================
  124. # Functions:
  125. # realfilepath ()
  126. # matlab_arch ()
  127. #=======================================================================
  128. realfilepath () { # Returns the actual path in the file system
  129. # of a file. It follows links. It returns an
  130. # empty path if an error occurs.
  131. #
  132. # Returns a 1 status if the file does not exist
  133. # or appears to be a circular link. Otherwise,
  134. # a 0 status is returned.
  135. #
  136. # usage: realfilepath filepath
  137. #
  138. file=$1
  139. n=1
  140. #
  141. dir=`dirname "$file"`
  142. dir=`(cd "$dir"; /bin/pwd)`
  143. file=`basename "$file"`
  144. #
  145. # Try up to 8 links
  146. #
  147. while [ $n -le 8 ]
  148. do
  149. (cd "$dir") >/dev/null 2>&1
  150. if [ $? -eq 0 ]; then
  151. lscmd=`(cd "$dir"; ls -l "$file" 2>/dev/null)`
  152. #
  153. # Check for link portably
  154. #
  155. if [ `expr "//$lscmd" : '//.*->.*'` -ne 0 ]; then
  156. link=`echo "$lscmd" | awk '{ print $NF }'`
  157. dirnext=`dirname "$link"`
  158. dir=`(cd "$dir"; cd "$dirnext"; /bin/pwd)`
  159. file=`basename "$link"`
  160. elif [ "$lscmd" != "" ]; then
  161. echo `(cd "$dir"; /bin/pwd)`/$file
  162. return 0
  163. else
  164. return 1
  165. fi
  166. else
  167. return 1
  168. fi
  169. n=`expr $n + 1`
  170. done
  171. return 1
  172. }
  173.  
  174. #
  175. #=======================================================================
  176. set_mac_arch() {
  177. # First check to see if maci64 is even possible on this hardware
  178. if [ "`/usr/sbin/sysctl -n hw.cpu64bit_capable`" = "0" ]; then
  179. # maci64 is not possible. So set the arch to maci.
  180. ARCH="maci"
  181. return
  182. fi
  183.  
  184. # Now check to see if maci64 is asked for
  185. if [ "$MACI64" = "0" ]; then
  186. # only maci is wanted, so arch is maci.
  187. ARCH="maci"
  188. return
  189. fi
  190.  
  191. # If we get to this point, maci64 is available and desired. So, check to
  192. # see if 64 bit binaries are available. First, if $MATLABROOT is NOT
  193. # set, we can't really check for anything else.
  194. if [ "$MATLABROOT" = "" ]; then
  195. ARCH="maci64";
  196. return
  197. fi
  198.  
  199.  
  200. # if we get to this point, we need to check the binaries that we have to
  201. # find out if we have maci64 binaries
  202. if [ -d "$MATLABROOT/bin/maci64" ]; then
  203. ARCH="maci64"
  204. return
  205. fi
  206.  
  207. # if we get to this point, even though maci64 is possible and desired,
  208. # the maci64 binaries aren't available, so fall back to maci
  209. ARCH="maci"
  210. }
  211.  
  212. #
  213. #=======================================================================
  214. matlab_arch () { # Determine the architecture for MATLAB
  215. # It returns the value in the ARCH variable.
  216. # If 'unknown' is returned then sometimes a
  217. # diagnostic message is returned in ARCH_MSG.
  218. #
  219. # Always returns a 0 status.
  220. #
  221. # usage: matlab_arch
  222. #
  223. ARCH="unknown"
  224. #
  225. if [ -f /bin/uname ]; then
  226. case "`/bin/uname`" in
  227. SunOS) # Solaris
  228. case "`/bin/uname -p`" in
  229. sparc)
  230. ARCH="sol64"
  231. ;;
  232. i386)
  233. ARCH="sola64"
  234. ;;
  235. esac
  236. ;;
  237. Linux)
  238. case "`/bin/uname -m`" in
  239. i*86)
  240. ARCH="glnx86"
  241. ;;
  242. x86_64)
  243. ARCH="glnxa64"
  244. ;;
  245. esac
  246. ;;
  247. # Usually uname lives in /usr/bin on the Mac, but sometimes people
  248. # have links in /bin that link uname to /usr/bin. Because of this
  249. # Mac needs to be listed in the checks for both /bin/uname and /usr/bin/uname
  250. Darwin) # Mac OS X
  251. case "`/bin/uname -p`" in
  252. i386)
  253. set_mac_arch
  254. ;;
  255. esac
  256. ;;
  257. *)
  258. :
  259. ;;
  260. esac
  261. elif [ -f /usr/bin/uname ]; then
  262. case "`/usr/bin/uname`" in
  263. Darwin) # Mac OS X
  264. case "`/usr/bin/uname -p`" in
  265. i386)
  266. set_mac_arch
  267. ;;
  268. esac
  269. ;;
  270. esac
  271. fi
  272. return 0
  273. }
  274. #=======================================================================
  275. #
  276. # The local shell function check_archlist is assumed to be loaded before this
  277. # function is sourced.
  278. #
  279. ARCH_MSG=''
  280. check_archlist ARCH=$ARCH
  281. if [ "$ARCH" = "" ]; then
  282. if [ "$MATLAB_ARCH" != "" ]; then
  283. check_archlist MATLAB_ARCH=$MATLAB_ARCH
  284. fi
  285. if [ "$ARCH" = "" ]; then
  286. matlab_arch
  287. fi
  288. fi
  289. Arch=$ARCH
  290. #========================= arch.sh (end) ==============================
  291. setMac () {
  292. if [ "$ARCH" = "maci" -o "$ARCH" = "maci64" ]; then
  293. ISMAC=1
  294. else
  295. ISMAC=0
  296. fi
  297. export ISMAC
  298.  
  299. }
  300. #=======================================================================
  301. setVMenvironment () {
  302. # Set up some variables for the VM environment
  303.  
  304. # Augment with AWT Motif default locale resource files
  305. XFILESEARCHPATH="$JRE_LOC/lib/locale/%L/%T/%N%S:$XFILESEARCHPATH"
  306. export XFILESEARCHPATH
  307.  
  308. # Determine <final_load_library_path> for each platform
  309. #
  310. libraryPathsToAdd=$1
  311.  
  312. case "$ARCH" in
  313. glnx*)
  314. LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`"
  315. if [ "$LD_LIBRARY_PATH" != "" ]; then
  316. LD_LIBRARY_PATH="$libraryPathsToAdd":$LD_LIBRARY_PATH
  317. else
  318. LD_LIBRARY_PATH="$libraryPathsToAdd"
  319. fi
  320. export LD_LIBRARY_PATH
  321. ;;
  322. mac*)
  323. DYLD_LIBRARY_PATH="`eval echo $DYLD_LIBRARY_PATH`"
  324. if [ "$DYLD_LIBRARY_PATH" != "" ]; then
  325. DYLD_LIBRARY_PATH="$libraryPathsToAdd":$DYLD_LIBRARY_PATH
  326. else
  327. DYLD_LIBRARY_PATH="$libraryPathsToAdd"
  328. fi
  329. export DYLD_LIBRARY_PATH
  330. ;;
  331. *)
  332. LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`"
  333. if [ "$LD_LIBRARY_PATH" != "" ]; then
  334. LD_LIBRARY_PATH=$LD_LIBRARY_PATH
  335. else
  336. LD_LIBRARY_PATH=
  337. fi
  338. export LD_LIBRARY_PATH
  339. ;;
  340. esac
  341.  
  342. }
  343. #=======================================================================
  344. setVMpath () {
  345. #
  346. # Determine the java vm path for each platform.
  347. #
  348.  
  349. if [ $ISMAC -eq 1 ]; then
  350. JAVA_HOME_CMD=/usr/libexec/java_home
  351. # Newer Macs have the java_home command,
  352. # older ones (some 10.5 machines) might not. This check
  353. # can be removed once 10.5 is no longer supported
  354. if [ ! -f $JAVA_HOME_CMD ]; then
  355. DEFAULT_JRE_LOC=/Library/Java/Home
  356. else
  357. # Ask for a 64-bit Java 1.6 (or higher) VM
  358. DEFAULT_JRE_LOC=`$JAVA_HOME_CMD -v 1.6+ -d64 -F`
  359. if [ $? != 0 ]; then
  360. # java_home couldn't find what we want so error out
  361. echo "Error: Cannot locate Java Runtime Environment (JRE)."
  362. exit 1
  363. fi
  364. fi
  365. else
  366. javaRoot=$1
  367. DEFAULT_JRE_LOC=$javaRoot/jre/$ARCH/jre
  368. # If the JRE doesn't exist and we are on glnxa64, try to fall back to glnx86
  369. if [ ! -d "$DEFAULT_JRE_LOC" ]; then
  370. if [ "$ARCH" = "glnxa64" ]; then
  371. echo "Could not find JRE for glnxa64. Trying glnx86."
  372. ARCH=glnx86
  373. DEFAULT_JRE_LOC=$javaRoot/jre/$ARCH/jre
  374. fi
  375. fi
  376. fi
  377.  
  378. if [ "$JRE_LOC" = "" ]; then
  379. JRE_LOC=$DEFAULT_JRE_LOC
  380. fi
  381. #
  382. # Look for JRE
  383. #
  384. if [ ! -d "$JRE_LOC" ]; then
  385. echo "---------------------------------------------------------------------------"
  386. echo "Error: Cannot locate Java Runtime Environment (JRE)."
  387. echo "The directory $JRE_LOC does not exist."
  388. echo "---------------------------------------------------------------------------"
  389. exit 1
  390. fi
  391. }
  392. #=======================================================================
  393. getJarPaths () {
  394. # Get the full search path for our jar files
  395. # Echos the search path to stdout.
  396.  
  397. JAVA_DIR="$1/java"
  398. JAR_LOC="$JAVA_DIR/jar"
  399. JAREXT_LOC="$JAVA_DIR/jarext"
  400. JAR_SEARCH_PATHtmp=$JRE_LOC/lib/ext:$JAR_LOC:$JAREXT_LOC
  401.  
  402. # Get list of directories in JAREXT_LOC
  403. theDirList=`ls -1Ap $JAREXT_LOC | grep '/'`
  404. # Add all subdirectories of JAREXT_LOC (but not recursively)
  405. for aDir in $theDirList
  406. do
  407. JAR_SEARCH_PATHtmp=$JAR_SEARCH_PATHtmp:$JAREXT_LOC/$aDir
  408. done
  409.  
  410. # If MW_LIB_EXT_DIRS env var set, append value to existing search path
  411. if [ "$MW_LIB_EXT_DIRS" != "" ]; then
  412. JAR_SEARCH_PATHtmp=$JAR_SEARCH_PATHtmp:$MW_LIB_EXT_DIRS
  413. fi
  414.  
  415. echo $JAR_SEARCH_PATHtmp
  416. }
  417. #=======================================================================
  418. copyDirWritable() {
  419. # Copy an entire directory. This will create the destination
  420. # directory, do a recursive copy, and then make all the files and
  421. # directories writable.
  422. # usage: copyDirWritable src dest
  423. srcDir=$1
  424. destDir=$2
  425.  
  426. mkdir -p "$destDir"
  427. (cd "$srcDir"; cp -RLf * "$destDir")
  428. chmod -R +w "$destDir" 2>/dev/null
  429.  
  430. }
  431. #========================= java_launcher (end) ==============================
  432. copyJREAndJarsToTmp () {
  433. #
  434. # Copy JRE and Jars to tmp
  435. #
  436. echo "Preparing installation files ..."
  437. if [ $ISMAC -eq 0 ]; then
  438. NEW_JRE_LOC="$TEMP_DIR/sys/java/jre/$ARCH/jre"
  439. copyDirWritable "$JRE_LOC" $NEW_JRE_LOC
  440. JRE_LOC=$NEW_JRE_LOC
  441. fi
  442. JAVA_DIR="$TEMP_DIR/java"
  443. JAR_LOC="$JAVA_DIR/jar"
  444. JAREXT_LOC="$JAVA_DIR/jarext"
  445. copyDirWritable "$ROOT/java" "$JAVA_DIR"
  446. }
  447. #=======================================================================
  448. getJavaLaunchTarget () {
  449. # Find jar file to execute.
  450. # TODO: Consolidate this code with getClassName() from activation and
  451. # move to java_launcher_template
  452.  
  453. MAIN_CLASS="com/mathworks/installwizard/Launcher"
  454.  
  455. BOOTSTRAP_PROPERTIES=$ROOT/java/bootstrap.properties
  456.  
  457. if [ -f "$BOOTSTRAP_PROPERTIES" ]; then
  458. MAIN_CLASS_OVERRIDE=`grep -i mainclass "$BOOTSTRAP_PROPERTIES" | awk -F= '{ print $2 }' | sed 's/ //g'`
  459. if [ "$MAIN_CLASS_OVERRIDE" != "" ]; then
  460. MAIN_CLASS=$MAIN_CLASS_OVERRIDE
  461. fi
  462. fi
  463.  
  464. # By default, set launch target to main class
  465. JAVA_LAUNCH_TARGETtmp=$MAIN_CLASS
  466.  
  467. # If MW_MAIN_CLASS env var set, set launch target to "$MW_MAIN_CLASS"
  468. if [ "$MW_MAIN_CLASS" != "" ]; then
  469. JAVA_LAUNCH_TARGETtmp=$MW_MAIN_CLASS
  470. fi
  471.  
  472. echo $JAVA_LAUNCH_TARGETtmp
  473. }
  474. #=======================================================================
  475. #
  476. # Parse the arguments
  477. #
  478. stat="OK"
  479. JAR_LOC=
  480. JAREXT_LOC=
  481. JAR_SEARCH_PATH=
  482. VERBOSE=0
  483. TEMP_DIR="/tmp/mathworks_$$";
  484. JRE_LOC=
  485. XTRAFLAGS=
  486. TESTONLY=0
  487. arglist=
  488.  
  489. # Set default values for some variables if they are not set yet.
  490. if [ "$ROOT" = "" ]; then
  491. SETUP_FILE=`realfilepath "$0"`
  492. ROOT=`dirname "$SETUP_FILE"`
  493. fi
  494.  
  495. SPLASH_OPTION="-splash:$ROOT/java/splash.png"
  496.  
  497. while [ "$stat" = "OK" -a $# -gt 0 ]; do
  498. case "$1" in
  499. -h|-help)
  500. stat=""
  501. ;;
  502. -v|-verbose)
  503. VERBOSE=1;
  504. ;;
  505. -javadir)
  506. if [ $# -eq 1 ]; then
  507. echo "A JRE directory must be specified with -javadir."
  508. stat=""
  509. else
  510. shift
  511. JRE_LOC=$1;
  512.  
  513. if [ ! -d "$JRE_LOC" ]; then
  514. echo "The directory $JRE_LOC does not exist."
  515. stat=""
  516. fi
  517. if [ ! -d "$JRE_LOC/lib" ]; then
  518. echo "$JRE_LOC does not appear to be a JRE directory."
  519. stat=""
  520. fi
  521. fi
  522. ;;
  523. -root)
  524. if [ $# -eq 1 ]; then
  525. echo "A DVD directory must be specified with -root."
  526. stat=""
  527. else
  528. shift
  529. ROOT=$1;
  530. if [ ! -d "$ROOT" ]; then
  531. echo "The directory $ROOT does not exist."
  532. stat=""
  533. else
  534. SPLASH_OPTION="-splash:$ROOT/java/splash.png"
  535. fi
  536. fi
  537. ;;
  538. -test)
  539. # Just run through script without actually running the java
  540. # command. Only useful with -v.
  541. TESTONLY=1
  542. ;;
  543. -psn*)
  544. # Apple passes this in with things that are double clicked. Ignore.
  545. ;;
  546. -*)
  547. OPTION=$1
  548. OPTION="$(echo ${OPTION} | tr '[:upper:]' '[:lower:]')"
  549. if [ $OPTION == "-mode" ]; then
  550. SPLASH_OPTION=""
  551. fi
  552. if [ $OPTION == "-inputfile" ]; then
  553. SPLASH_OPTION=""
  554. fi
  555. found=0
  556. # Check for -arch
  557. arch=$ARCH
  558. check_archlist argument=$1 noprint
  559. if [ "$ARCH" != "" ]; then
  560. found=1
  561. else
  562. ARCH=$arch
  563. fi
  564. if [ "$found" = "0" ]; then
  565. arglist="$arglist $1"
  566. fi
  567. ;;
  568. *)
  569. arglist="$arglist $1"
  570. ;;
  571. esac
  572. shift
  573. done
  574. setMac
  575. #
  576. # Check for errors
  577. #
  578. if [ "$stat" != "OK" ]; then # An error occurred.
  579. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  580. echo ""
  581. echo " Usage: install [-h|help]"
  582. echo " [-javadir <directory>] | [-root <directory>] |"
  583. echo " [-test] | [-v|-verbose]"
  584. echo ""
  585. echo " -h|-help - Display arguments."
  586. echo " -test - Don't actually run the java command (only useful with -v)."
  587. echo " -v|-verbose - Display settings."
  588. echo " -javadir <directory> - Override default java root directory."
  589. echo " -root <directory> - Override default DVD root directory."
  590. echo ""
  591. echo " The default settings when no override inputs are supplied are: "
  592. echo " -root = <directory containing this script>"
  593. echo ' -javadir = <root>/sys/java/jre/$ARCH/jre'
  594. echo ""
  595. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  596. exit 1
  597. fi
  598.  
  599. # Determine the java vm path for each platform.
  600. setVMpath "$ROOT/sys/java"
  601. copyJREAndJarsToTmp
  602.  
  603. # Set up some variables for the VM environment.
  604. setVMenvironment "$ROOT/bin/$ARCH"
  605.  
  606. # Get the jar directories
  607. JAR_SEARCH_PATH=`getJarPaths "$TEMP_DIR"`
  608.  
  609. # Get the java launch target
  610. JAVA_LAUNCH_TARGET=`getJavaLaunchTarget`
  611.  
  612. # Set up java command to run.
  613. if [ $ISMAC -eq 1 ]; then
  614. XTRAFLAGS="-d64 -Xdock:name=\"Install MATLAB\" -Xdock:icon=\"$ROOT/InstallForMacOSX.app/Contents/Resources/membrane.icns\" -Xmx512m"
  615. fi
  616. java_exe=$JRE_LOC/bin/java
  617. java_cmd="$java_exe $XTRAFLAGS $SPLASH_OPTION -Djava.ext.dirs=$JAR_SEARCH_PATH $JAVA_LAUNCH_TARGET -root \"$ROOT\" $arglist"
  618.  
  619. #
  620. if [ "$VERBOSE" = "1" ]; then
  621. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  622. echo "-> DVD = $ROOT"
  623. echo "-> ARCH = $ARCH"
  624. echo "-> DISPLAY = $DISPLAY"
  625. echo "-> TESTONLY = $TESTONLY"
  626. echo "-> JRE_LOC = $JRE_LOC"
  627. #
  628. case "$ARCH" in
  629. mac*)
  630. echo "-> DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH"
  631. ;;
  632. *)
  633. echo "-> LD_LIBRARY_PATH = $LD_LIBRARY_PATH"
  634. ;;
  635. esac
  636.  
  637. echo " "
  638. echo "Command to run:"
  639. echo "$java_cmd"
  640. echo " "
  641. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  642. fi
  643. #
  644. #
  645. # Run the java command to start the install app
  646. if [ "$TESTONLY" != "1" ]; then
  647. echo "Installing ..."
  648. eval $java_cmd
  649. fi
  650.  
  651. # Clean up
  652. rm -rf $TEMP_DIR
  653. echo "Finished"
Add Comment
Please, Sign In to add comment