PageRenderTime 78ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/nbi/engine/native/launcher/unix/src/launcher.sh

https://bitbucket.org/openesb/openesb-installers
Shell | 1646 lines | 1382 code | 175 blank | 89 comment | 226 complexity | 72ce116756de19de1c1a2d2685de646c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. #!/bin/sh
  2. #
  3. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  4. #
  5. # Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
  6. #
  7. # The contents of this file are subject to the terms of either the GNU General Public
  8. # License Version 2 only ("GPL") or the Common Development and Distribution
  9. # License("CDDL") (collectively, the "License"). You may not use this file except in
  10. # compliance with the License. You can obtain a copy of the License at
  11. # http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
  12. # License for the specific language governing permissions and limitations under the
  13. # License. When distributing the software, include this License Header Notice in
  14. # each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
  15. # designates this particular file as subject to the "Classpath" exception as provided
  16. # by Sun in the GPL Version 2 section of the License file that accompanied this code.
  17. # If applicable, add the following below the License Header, with the fields enclosed
  18. # by brackets [] replaced by your own identifying information:
  19. # "Portions Copyrighted [year] [name of copyright owner]"
  20. #
  21. # Contributor(s):
  22. #
  23. # The Original Software is NetBeans. The Initial Developer of the Original Software
  24. # is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
  25. # Rights Reserved.
  26. #
  27. # If you wish your version of this file to be governed by only the CDDL or only the
  28. # GPL Version 2, indicate your decision by adding "[Contributor] elects to include
  29. # this software in this distribution under the [CDDL or GPL Version 2] license." If
  30. # you do not indicate a single choice of license, a recipient has the option to
  31. # distribute your version of this file under either the CDDL, the GPL Version 2 or
  32. # to extend the choice of license to its licensees as provided above. However, if you
  33. # add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the
  34. # option applies only if the new code is made subject to such option by the copyright
  35. # holder.
  36. #
  37. ARG_JAVAHOME="--javahome"
  38. ARG_VERBOSE="--verbose"
  39. ARG_OUTPUT="--output"
  40. ARG_EXTRACT="--extract"
  41. ARG_JAVA_ARG_PREFIX="-J"
  42. ARG_TEMPDIR="--tempdir"
  43. ARG_CLASSPATHA="--classpath-append"
  44. ARG_CLASSPATHP="--classpath-prepend"
  45. ARG_RECORD="--record"
  46. ARG_STATE="--state"
  47. ARG_HELP="--help"
  48. ARG_SILENT="--silent"
  49. ARG_NOSPACECHECK="--nospacecheck"
  50. ARG_LOCALE="--locale"
  51. USE_DEBUG_OUTPUT=0
  52. PERFORM_FREE_SPACE_CHECK=1
  53. SILENT_MODE=0
  54. EXTRACT_ONLY=0
  55. SHOW_HELP_ONLY=0
  56. LOCAL_OVERRIDDEN=0
  57. APPEND_CP=
  58. PREPEND_CP=
  59. LAUNCHER_APP_ARGUMENTS=
  60. LAUNCHER_JVM_ARGUMENTS=
  61. ERROR_OK=0
  62. ERROR_TEMP_DIRECTORY=2
  63. ERROR_TEST_JVM_FILE=3
  64. ERROR_JVM_NOT_FOUND=4
  65. ERROR_JVM_UNCOMPATIBLE=5
  66. ERROR_EXTRACT_ONLY=6
  67. ERROR_INPUTOUPUT=7
  68. ERROR_FREESPACE=8
  69. ERROR_INTEGRITY=9
  70. ERROR_MISSING_RESOURCES=10
  71. ERROR_JVM_EXTRACTION=11
  72. ERROR_JVM_UNPACKING=12
  73. ERROR_VERIFY_BUNDLED_JVM=13
  74. VERIFY_OK=1
  75. VERIFY_NOJAVA=2
  76. VERIFY_UNCOMPATIBLE=3
  77. MSG_ERROR_JVM_NOT_FOUND="nlu.jvm.notfoundmessage"
  78. MSG_ERROR_USER_ERROR="nlu.jvm.usererror"
  79. MSG_ERROR_JVM_UNCOMPATIBLE="nlu.jvm.uncompatible"
  80. MSG_ERROR_INTEGRITY="nlu.integrity"
  81. MSG_ERROR_FREESPACE="nlu.freespace"
  82. MSG_ERROP_MISSING_RESOURCE="nlu.missing.external.resource"
  83. MSG_ERROR_TMPDIR="nlu.cannot.create.tmpdir"
  84. MSG_ERROR_EXTRACT_JVM="nlu.cannot.extract.bundled.jvm"
  85. MSG_ERROR_UNPACK_JVM_FILE="nlu.cannot.unpack.jvm.file"
  86. MSG_ERROR_VERIFY_BUNDLED_JVM="nlu.error.verify.bundled.jvm"
  87. MSG_RUNNING="nlu.running"
  88. MSG_STARTING="nlu.starting"
  89. MSG_EXTRACTING="nlu.extracting"
  90. MSG_PREPARE_JVM="nlu.prepare.jvm"
  91. MSG_JVM_SEARCH="nlu.jvm.search"
  92. MSG_ARG_JAVAHOME="nlu.arg.javahome"
  93. MSG_ARG_VERBOSE="nlu.arg.verbose"
  94. MSG_ARG_OUTPUT="nlu.arg.output"
  95. MSG_ARG_EXTRACT="nlu.arg.extract"
  96. MSG_ARG_TEMPDIR="nlu.arg.tempdir"
  97. MSG_ARG_CPA="nlu.arg.cpa"
  98. MSG_ARG_CPP="nlu.arg.cpp"
  99. MSG_ARG_RECORD="nlu.arg.record"
  100. MSG_ARG_STATE="nlu.arg.state"
  101. MSG_ARG_DISABLE_FREE_SPACE_CHECK="nlu.arg.disable.space.check"
  102. MSG_ARG_LOCALE="nlu.arg.locale"
  103. MSG_ARG_SILENT="nlu.arg.silent"
  104. MSG_ARG_HELP="nlu.arg.help"
  105. MSG_USAGE="nlu.msg.usage"
  106. isSymlink=
  107. entryPoint() {
  108. initSymlinkArgument
  109. CURRENT_DIRECTORY=`pwd`
  110. LAUNCHER_NAME=`echo $0`
  111. parseCommandLineArguments "$@"
  112. initializeVariables
  113. setLauncherLocale
  114. debugLauncherArguments "$@"
  115. if [ 1 -eq $SHOW_HELP_ONLY ] ; then
  116. showHelp
  117. fi
  118. message "$MSG_STARTING"
  119. createTempDirectory
  120. checkFreeSpace "$TOTAL_BUNDLED_FILES_SIZE" "$LAUNCHER_EXTRACT_DIR"
  121. extractJVMData
  122. if [ 0 -eq $EXTRACT_ONLY ] ; then
  123. searchJava
  124. fi
  125. extractBundledData
  126. verifyIntegrity
  127. if [ 0 -eq $EXTRACT_ONLY ] ; then
  128. executeMainClass
  129. else
  130. exitProgram $ERROR_OK
  131. fi
  132. }
  133. initSymlinkArgument() {
  134. testSymlinkErr=`test -L / 2>&1 > /dev/null`
  135. if [ -z "$testSymlinkErr" ] ; then
  136. isSymlink=-L
  137. else
  138. isSymlink=-h
  139. fi
  140. }
  141. debugLauncherArguments() {
  142. debug "Launcher Command : $0"
  143. argCounter=1
  144. while [ $# != 0 ] ; do
  145. debug "... argument [$argCounter] = $1"
  146. argCounter=`expr "$argCounter" + 1`
  147. shift
  148. done
  149. }
  150. isLauncherCommandArgument() {
  151. case "$1" in
  152. $ARG_VERBOSE | $ARG_NOSPACECHECK | $ARG_OUTPUT | $ARG_HELP | $ARG_JAVAHOME | $ARG_TEMPDIR | $ARG_EXTRACT | $ARG_SILENT | $ARG_LOCALE | $ARG_CLASSPATHP | $ARG_CLASSPATHA | $ARG_RECORD | $ARG_STATE)
  153. echo 1
  154. ;;
  155. *)
  156. echo 0
  157. ;;
  158. esac
  159. }
  160. parseCommandLineArguments() {
  161. while [ $# != 0 ]
  162. do
  163. case "$1" in
  164. $ARG_VERBOSE)
  165. USE_DEBUG_OUTPUT=1;;
  166. $ARG_NOSPACECHECK)
  167. PERFORM_FREE_SPACE_CHECK=0
  168. parseJvmAppArgument "$1"
  169. ;;
  170. $ARG_OUTPUT)
  171. if [ -n "$2" ] ; then
  172. OUTPUT_FILE="$2"
  173. if [ -f "$OUTPUT_FILE" ] ; then
  174. # clear output file first
  175. rm -f "$OUTPUT_FILE" > /dev/null 2>&1
  176. touch "$OUTPUT_FILE"
  177. fi
  178. shift
  179. fi
  180. ;;
  181. $ARG_HELP)
  182. SHOW_HELP_ONLY=1
  183. ;;
  184. $ARG_JAVAHOME)
  185. if [ -n "$2" ] ; then
  186. LAUNCHER_JAVA="$2"
  187. shift
  188. fi
  189. ;;
  190. $ARG_TEMPDIR)
  191. if [ -n "$2" ] ; then
  192. LAUNCHER_JVM_TEMP_DIR="$2"
  193. shift
  194. fi
  195. ;;
  196. $ARG_EXTRACT)
  197. EXTRACT_ONLY=1
  198. if [ -n "$2" ] && [ `isLauncherCommandArgument "$2"` -eq 0 ] ; then
  199. LAUNCHER_EXTRACT_DIR="$2"
  200. shift
  201. else
  202. LAUNCHER_EXTRACT_DIR="$CURRENT_DIRECTORY"
  203. fi
  204. ;;
  205. $ARG_SILENT)
  206. SILENT_MODE=1
  207. parseJvmAppArgument "$1"
  208. ;;
  209. $ARG_LOCALE)
  210. SYSTEM_LOCALE="$2"
  211. LOCAL_OVERRIDDEN=1
  212. parseJvmAppArgument "$1"
  213. ;;
  214. $ARG_CLASSPATHP)
  215. if [ -n "$2" ] ; then
  216. if [ -z "$PREPEND_CP" ] ; then
  217. PREPEND_CP="$2"
  218. else
  219. PREPEND_CP="$2":"$PREPEND_CP"
  220. fi
  221. shift
  222. fi
  223. ;;
  224. $ARG_CLASSPATHA)
  225. if [ -n "$2" ] ; then
  226. if [ -z "$APPEND_CP" ] ; then
  227. APPEND_CP="$2"
  228. else
  229. APPEND_CP="$APPEND_CP":"$2"
  230. fi
  231. shift
  232. fi
  233. ;;
  234. *)
  235. parseJvmAppArgument "$1"
  236. esac
  237. shift
  238. done
  239. }
  240. setLauncherLocale() {
  241. if [ 0 -eq $LOCAL_OVERRIDDEN ] ; then
  242. SYSTEM_LOCALE="$LANG"
  243. debug "Setting initial launcher locale from the system : $SYSTEM_LOCALE"
  244. else
  245. debug "Setting initial launcher locale using command-line argument : $SYSTEM_LOCALE"
  246. fi
  247. LAUNCHER_LOCALE="$SYSTEM_LOCALE"
  248. if [ -n "$LAUNCHER_LOCALE" ] ; then
  249. # check if $LAUNCHER_LOCALE is in UTF-8
  250. if [ 0 -eq $LOCAL_OVERRIDDEN ] ; then
  251. removeUTFsuffix=`echo "$LAUNCHER_LOCALE" | sed "s/\.UTF-8//"`
  252. isUTF=`ifEquals "$removeUTFsuffix" "$LAUNCHER_LOCALE"`
  253. if [ 1 -eq $isUTF ] ; then
  254. #set launcher locale to the default if the system locale name doesn`t containt UTF-8
  255. LAUNCHER_LOCALE=""
  256. fi
  257. fi
  258. localeChanged=0
  259. localeCounter=0
  260. while [ $localeCounter -lt $LAUNCHER_LOCALES_NUMBER ] ; do
  261. localeVar="$""LAUNCHER_LOCALE_NAME_$localeCounter"
  262. arg=`eval "echo \"$localeVar\""`
  263. if [ -n "$arg" ] ; then
  264. # if not a default locale
  265. # $comp length shows the difference between $SYSTEM_LOCALE and $arg
  266. # the less the length the less the difference and more coincedence
  267. comp=`echo "$SYSTEM_LOCALE" | sed -e "s/^${arg}//"`
  268. length1=`getStringLength "$comp"`
  269. length2=`getStringLength "$LAUNCHER_LOCALE"`
  270. if [ $length1 -lt $length2 ] ; then
  271. # more coincidence between $SYSTEM_LOCALE and $arg than between $SYSTEM_LOCALE and $arg
  272. compare=`ifLess "$comp" "$LAUNCHER_LOCALE"`
  273. if [ 1 -eq $compare ] ; then
  274. LAUNCHER_LOCALE="$arg"
  275. localeChanged=1
  276. debug "... setting locale to $arg"
  277. fi
  278. if [ -z "$comp" ] ; then
  279. # means that $SYSTEM_LOCALE equals to $arg
  280. break
  281. fi
  282. fi
  283. else
  284. comp="$SYSTEM_LOCALE"
  285. fi
  286. localeCounter=`expr "$localeCounter" + 1`
  287. done
  288. if [ $localeChanged -eq 0 ] ; then
  289. #set default
  290. LAUNCHER_LOCALE=""
  291. fi
  292. fi
  293. debug "Final Launcher Locale : $LAUNCHER_LOCALE"
  294. }
  295. escapeBackslash() {
  296. echo "$1" | sed "s/\\\/\\\\\\\/g"
  297. }
  298. ifLess() {
  299. arg1=`escapeBackslash "$1"`
  300. arg2=`escapeBackslash "$2"`
  301. compare=`awk 'END { if ( a < b ) { print 1 } else { print 0 } }' a="$arg1" b="$arg2" < /dev/null`
  302. echo $compare
  303. }
  304. formatVersion() {
  305. formatted=`echo "$1" | sed "s/-ea//g;s/-rc[0-9]*//g;s/-beta[0-9]*//g;s/-preview[0-9]*//g;s/-dp[0-9]*//g;s/-alpha[0-9]*//g;s/-fcs//g;s/_/./g;s/-/\./g"`
  306. formatted=`echo "$formatted" | sed "s/^\(\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)\)\.b\([0-9][0-9]*\)/\1\.0\.\5/g"`
  307. formatted=`echo "$formatted" | sed "s/\.b\([0-9][0-9]*\)/\.\1/g"`
  308. echo "$formatted"
  309. }
  310. compareVersions() {
  311. current1=`formatVersion "$1"`
  312. current2=`formatVersion "$2"`
  313. compresult=
  314. #0 - equals
  315. #-1 - less
  316. #1 - more
  317. while [ -z "$compresult" ] ; do
  318. value1=`echo "$current1" | sed "s/\..*//g"`
  319. value2=`echo "$current2" | sed "s/\..*//g"`
  320. removeDots1=`echo "$current1" | sed "s/\.//g"`
  321. removeDots2=`echo "$current2" | sed "s/\.//g"`
  322. if [ 1 -eq `ifEquals "$current1" "$removeDots1"` ] ; then
  323. remainder1=""
  324. else
  325. remainder1=`echo "$current1" | sed "s/^$value1\.//g"`
  326. fi
  327. if [ 1 -eq `ifEquals "$current2" "$removeDots2"` ] ; then
  328. remainder2=""
  329. else
  330. remainder2=`echo "$current2" | sed "s/^$value2\.//g"`
  331. fi
  332. current1="$remainder1"
  333. current2="$remainder2"
  334. if [ -z "$value1" ] || [ 0 -eq `ifNumber "$value1"` ] ; then
  335. value1=0
  336. fi
  337. if [ -z "$value2" ] || [ 0 -eq `ifNumber "$value2"` ] ; then
  338. value2=0
  339. fi
  340. if [ "$value1" -gt "$value2" ] ; then
  341. compresult=1
  342. break
  343. elif [ "$value2" -gt "$value1" ] ; then
  344. compresult=-1
  345. break
  346. fi
  347. if [ -z "$current1" ] && [ -z "$current2" ] ; then
  348. compresult=0
  349. break
  350. fi
  351. done
  352. echo $compresult
  353. }
  354. ifVersionLess() {
  355. compareResult=`compareVersions "$1" "$2"`
  356. if [ -1 -eq $compareResult ] ; then
  357. echo 1
  358. else
  359. echo 0
  360. fi
  361. }
  362. ifVersionGreater() {
  363. compareResult=`compareVersions "$1" "$2"`
  364. if [ 1 -eq $compareResult ] ; then
  365. echo 1
  366. else
  367. echo 0
  368. fi
  369. }
  370. ifGreater() {
  371. arg1=`escapeBackslash "$1"`
  372. arg2=`escapeBackslash "$2"`
  373. compare=`awk 'END { if ( a > b ) { print 1 } else { print 0 } }' a="$arg1" b="$arg2" < /dev/null`
  374. echo $compare
  375. }
  376. ifEquals() {
  377. arg1=`escapeBackslash "$1"`
  378. arg2=`escapeBackslash "$2"`
  379. compare=`awk 'END { if ( a == b ) { print 1 } else { print 0 } }' a="$arg1" b="$arg2" < /dev/null`
  380. echo $compare
  381. }
  382. ifNumber()
  383. {
  384. result=0
  385. if [ -n "$1" ] ; then
  386. num=`echo "$1" | sed 's/[0-9]*//g' 2>/dev/null`
  387. if [ -z "$num" ] ; then
  388. result=1
  389. fi
  390. fi
  391. echo $result
  392. }
  393. getStringLength() {
  394. strlength=`awk 'END{ print length(a) }' a="$1" < /dev/null`
  395. echo $strlength
  396. }
  397. resolveRelativity() {
  398. if [ 1 -eq `ifPathRelative "$1"` ] ; then
  399. echo "$CURRENT_DIRECTORY"/"$1" | sed 's/\"//g' 2>/dev/null
  400. else
  401. echo "$1"
  402. fi
  403. }
  404. ifPathRelative() {
  405. param="$1"
  406. removeRoot=`echo "$param" | sed "s/^\\\///" 2>/dev/null`
  407. echo `ifEquals "$param" "$removeRoot"` 2>/dev/null
  408. }
  409. initializeVariables() {
  410. debug "Launcher name is $LAUNCHER_NAME"
  411. systemName=`uname`
  412. debug "System name is $systemName"
  413. isMacOSX=`ifEquals "$systemName" "Darwin"`
  414. isSolaris=`ifEquals "$systemName" "SunOS"`
  415. if [ 1 -eq $isSolaris ] ; then
  416. POSSIBLE_JAVA_EXE_SUFFIX="$POSSIBLE_JAVA_EXE_SUFFIX_SOLARIS"
  417. else
  418. POSSIBLE_JAVA_EXE_SUFFIX="$POSSIBLE_JAVA_EXE_SUFFIX_COMMON"
  419. fi
  420. systemInfo=`uname -a 2>/dev/null`
  421. debug "System Information:"
  422. debug "$systemInfo"
  423. debug ""
  424. DEFAULT_DISK_BLOCK_SIZE=512
  425. LAUNCHER_TRACKING_SIZE=$LAUNCHER_STUB_SIZE
  426. LAUNCHER_TRACKING_SIZE_BYTES=`expr "$LAUNCHER_STUB_SIZE" \* "$FILE_BLOCK_SIZE"`
  427. getLauncherLocation
  428. }
  429. parseJvmAppArgument() {
  430. param="$1"
  431. arg=`echo "$param" | sed "s/^-J//"`
  432. argEscaped=`escapeString "$arg"`
  433. if [ "$param" = "$arg" ] ; then
  434. LAUNCHER_APP_ARGUMENTS="$LAUNCHER_APP_ARGUMENTS $argEscaped"
  435. else
  436. LAUNCHER_JVM_ARGUMENTS="$LAUNCHER_JVM_ARGUMENTS $argEscaped"
  437. fi
  438. }
  439. getLauncherLocation() {
  440. # if file path is relative then prepend it with current directory
  441. LAUNCHER_FULL_PATH=`resolveRelativity "$LAUNCHER_NAME"`
  442. debug "... normalizing full path"
  443. LAUNCHER_FULL_PATH=`normalizePath "$LAUNCHER_FULL_PATH"`
  444. debug "... getting dirname"
  445. LAUNCHER_DIR=`dirname "$LAUNCHER_FULL_PATH"`
  446. debug "Full launcher path = $LAUNCHER_FULL_PATH"
  447. debug "Launcher directory = $LAUNCHER_DIR"
  448. }
  449. getLauncherSize() {
  450. lsOutput=`ls -l --block-size=1 "$LAUNCHER_FULL_PATH" 2>/dev/null`
  451. if [ $? -ne 0 ] ; then
  452. #default block size
  453. lsOutput=`ls -l "$LAUNCHER_FULL_PATH" 2>/dev/null`
  454. fi
  455. echo "$lsOutput" | awk ' { print $5 }' 2>/dev/null
  456. }
  457. verifyIntegrity() {
  458. size=`getLauncherSize`
  459. extractedSize=$LAUNCHER_TRACKING_SIZE_BYTES
  460. if [ 1 -eq `ifNumber "$size"` ] ; then
  461. debug "... check integrity"
  462. debug "... minimal size : $extractedSize"
  463. debug "... real size : $size"
  464. if [ $size -lt $extractedSize ] ; then
  465. debug "... integration check FAILED"
  466. message "$MSG_ERROR_INTEGRITY" `normalizePath "$LAUNCHER_FULL_PATH"`
  467. exitProgram $ERROR_INTEGRITY
  468. fi
  469. debug "... integration check OK"
  470. fi
  471. }
  472. showHelp() {
  473. msg0=`message "$MSG_USAGE"`
  474. msg1=`message "$MSG_ARG_JAVAHOME $ARG_JAVAHOME"`
  475. msg2=`message "$MSG_ARG_TEMPDIR $ARG_TEMPDIR"`
  476. msg3=`message "$MSG_ARG_EXTRACT $ARG_EXTRACT"`
  477. msg4=`message "$MSG_ARG_OUTPUT $ARG_OUTPUT"`
  478. msg5=`message "$MSG_ARG_VERBOSE $ARG_VERBOSE"`
  479. msg6=`message "$MSG_ARG_CPA $ARG_CLASSPATHA"`
  480. msg7=`message "$MSG_ARG_CPP $ARG_CLASSPATHP"`
  481. msg8=`message "$MSG_ARG_DISABLE_FREE_SPACE_CHECK $ARG_NOSPACECHECK"`
  482. msg9=`message "$MSG_ARG_LOCALE $ARG_LOCALE"`
  483. msg10=`message "$MSG_ARG_SILENT $ARG_SILENT"`
  484. msg11=`message "$MSG_ARG_RECORD $ARG_RECORD"`
  485. msg12=`message "$MSG_ARG_STATE $ARG_STATE"`
  486. msg13=`message "$MSG_ARG_HELP $ARG_HELP"`
  487. out "$msg0"
  488. out "$msg1"
  489. out "$msg2"
  490. out "$msg3"
  491. out "$msg4"
  492. out "$msg5"
  493. out "$msg6"
  494. out "$msg7"
  495. out "$msg8"
  496. out "$msg9"
  497. out "$msg10"
  498. out "$msg11"
  499. out "$msg12"
  500. out "$msg13"
  501. exitProgram $ERROR_OK
  502. }
  503. exitProgram() {
  504. if [ 0 -eq $EXTRACT_ONLY ] ; then
  505. if [ -n "$LAUNCHER_EXTRACT_DIR" ] && [ -d "$LAUNCHER_EXTRACT_DIR" ]; then
  506. debug "Removing directory $LAUNCHER_EXTRACT_DIR"
  507. rm -rf "$LAUNCHER_EXTRACT_DIR" > /dev/null 2>&1
  508. fi
  509. fi
  510. debug "exitCode = $1"
  511. exit $1
  512. }
  513. debug() {
  514. if [ $USE_DEBUG_OUTPUT -eq 1 ] ; then
  515. timestamp=`date '+%Y-%m-%d %H:%M:%S'`
  516. out "[$timestamp]> $1"
  517. fi
  518. }
  519. out() {
  520. if [ -n "$OUTPUT_FILE" ] ; then
  521. printf "%s\n" "$@" >> "$OUTPUT_FILE"
  522. elif [ 0 -eq $SILENT_MODE ] ; then
  523. printf "%s\n" "$@"
  524. fi
  525. }
  526. message() {
  527. msg=`getMessage "$@"`
  528. out "$msg"
  529. }
  530. createTempDirectory() {
  531. if [ 0 -eq $EXTRACT_ONLY ] ; then
  532. if [ -z "$LAUNCHER_JVM_TEMP_DIR" ] ; then
  533. if [ 0 -eq $EXTRACT_ONLY ] ; then
  534. if [ -n "$TEMP" ] && [ -d "$TEMP" ] ; then
  535. debug "TEMP var is used : $TEMP"
  536. LAUNCHER_JVM_TEMP_DIR="$TEMP"
  537. elif [ -n "$TMP" ] && [ -d "$TMP" ] ; then
  538. debug "TMP var is used : $TMP"
  539. LAUNCHER_JVM_TEMP_DIR="$TMP"
  540. elif [ -n "$TEMPDIR" ] && [ -d "$TEMPDIR" ] ; then
  541. debug "TEMPDIR var is used : $TEMPDIR"
  542. LAUNCHER_JVM_TEMP_DIR="$TEMPDIR"
  543. elif [ -d "/tmp" ] ; then
  544. debug "Using /tmp for temp"
  545. LAUNCHER_JVM_TEMP_DIR="/tmp"
  546. else
  547. debug "Using home dir for temp"
  548. LAUNCHER_JVM_TEMP_DIR="$HOME"
  549. fi
  550. else
  551. #extract only : to the curdir
  552. LAUNCHER_JVM_TEMP_DIR="$CURRENT_DIRECTORY"
  553. fi
  554. fi
  555. # if temp dir does not exist then try to create it
  556. if [ ! -d "$LAUNCHER_JVM_TEMP_DIR" ] ; then
  557. mkdir -p "$LAUNCHER_JVM_TEMP_DIR" > /dev/null 2>&1
  558. if [ $? -ne 0 ] ; then
  559. message "$MSG_ERROR_TMPDIR" "$LAUNCHER_JVM_TEMP_DIR"
  560. exitProgram $ERROR_TEMP_DIRECTORY
  561. fi
  562. fi
  563. debug "Launcher TEMP ROOT = $LAUNCHER_JVM_TEMP_DIR"
  564. subDir=`date '+%u%m%M%S'`
  565. subDir=`echo ".nbi-$subDir.tmp"`
  566. LAUNCHER_EXTRACT_DIR="$LAUNCHER_JVM_TEMP_DIR/$subDir"
  567. else
  568. #extracting to the $LAUNCHER_EXTRACT_DIR
  569. debug "Launcher Extracting ROOT = $LAUNCHER_EXTRACT_DIR"
  570. fi
  571. if [ ! -d "$LAUNCHER_EXTRACT_DIR" ] ; then
  572. mkdir -p "$LAUNCHER_EXTRACT_DIR" > /dev/null 2>&1
  573. if [ $? -ne 0 ] ; then
  574. message "$MSG_ERROR_TMPDIR" "$LAUNCHER_EXTRACT_DIR"
  575. exitProgram $ERROR_TEMP_DIRECTORY
  576. fi
  577. else
  578. debug "$LAUNCHER_EXTRACT_DIR is directory and exist"
  579. fi
  580. debug "Using directory $LAUNCHER_EXTRACT_DIR for extracting data"
  581. }
  582. extractJVMData() {
  583. debug "Extracting testJVM file data..."
  584. extractTestJVMFile
  585. debug "Extracting bundled JVMs ..."
  586. extractJVMFiles
  587. debug "Extracting JVM data done"
  588. }
  589. extractBundledData() {
  590. message "$MSG_EXTRACTING"
  591. debug "Extracting bundled jars data..."
  592. extractJars
  593. debug "Extracting other data..."
  594. extractOtherData
  595. debug "Extracting bundled data finished..."
  596. }
  597. setTestJVMClasspath() {
  598. testjvmname=`basename "$TEST_JVM_PATH"`
  599. removeClassSuffix=`echo "$testjvmname" | sed 's/\.class$//'`
  600. notClassFile=`ifEquals "$testjvmname" "$removeClassSuffix"`
  601. if [ -d "$TEST_JVM_PATH" ] ; then
  602. TEST_JVM_CLASSPATH="$TEST_JVM_PATH"
  603. debug "... testJVM path is a directory"
  604. elif [ $isSymlink "$TEST_JVM_PATH" ] && [ $notClassFile -eq 1 ] ; then
  605. TEST_JVM_CLASSPATH="$TEST_JVM_PATH"
  606. debug "... testJVM path is a link but not a .class file"
  607. else
  608. if [ $notClassFile -eq 1 ] ; then
  609. debug "... testJVM path is a jar/zip file"
  610. TEST_JVM_CLASSPATH="$TEST_JVM_PATH"
  611. else
  612. debug "... testJVM path is a .class file"
  613. TEST_JVM_CLASSPATH=`dirname "$TEST_JVM_PATH"`
  614. fi
  615. fi
  616. debug "... testJVM classpath is : $TEST_JVM_CLASSPATH"
  617. }
  618. extractTestJVMFile() {
  619. TEST_JVM_PATH=`resolveResourcePath "TEST_JVM_FILE"`
  620. extractResource "TEST_JVM_FILE"
  621. setTestJVMClasspath
  622. }
  623. installJVM() {
  624. message "$MSG_PREPARE_JVM"
  625. jvmFile=`resolveRelativity "$1"`
  626. jvmDir=`dirname "$jvmFile"`/_jvm
  627. debug "JVM Directory : $jvmDir"
  628. mkdir "$jvmDir" > /dev/null 2>&1
  629. if [ $? != 0 ] ; then
  630. message "$MSG_ERROR_EXTRACT_JVM"
  631. exitProgram $ERROR_JVM_EXTRACTION
  632. fi
  633. chmod +x "$jvmFile" > /dev/null 2>&1
  634. jvmFileEscaped=`escapeString "$jvmFile"`
  635. jvmDirEscaped=`escapeString "$jvmDir"`
  636. cd "$jvmDir"
  637. runCommand "$jvmFileEscaped"
  638. ERROR_CODE=$?
  639. cd "$CURRENT_DIRECTORY"
  640. if [ $ERROR_CODE != 0 ] ; then
  641. message "$MSG_ERROR_EXTRACT_JVM"
  642. exitProgram $ERROR_JVM_EXTRACTION
  643. fi
  644. files=`find "$jvmDir" -name "*.jar.pack.gz" -print`
  645. debug "Packed files : $files"
  646. f="$files"
  647. fileCounter=1;
  648. while [ -n "$f" ] ; do
  649. f=`echo "$files" | sed -n "${fileCounter}p" 2>/dev/null`
  650. debug "... next file is $f"
  651. if [ -n "$f" ] ; then
  652. debug "... packed file = $f"
  653. unpacked=`echo "$f" | sed s/\.pack\.gz//`
  654. debug "... unpacked file = $unpacked"
  655. fEsc=`escapeString "$f"`
  656. uEsc=`escapeString "$unpacked"`
  657. cmd="$jvmDirEscaped/bin/unpack200 $fEsc $uEsc"
  658. runCommand "$cmd"
  659. if [ $? != 0 ] ; then
  660. message "$MSG_ERROR_UNPACK_JVM_FILE" "$f"
  661. exitProgram $ERROR_JVM_UNPACKING
  662. fi
  663. fi
  664. fileCounter=`expr "$fileCounter" + 1`
  665. done
  666. verifyJVM "$jvmDir"
  667. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  668. message "$MSG_ERROR_VERIFY_BUNDLED_JVM"
  669. exitProgram $ERROR_VERIFY_BUNDLED_JVM
  670. fi
  671. }
  672. resolveResourcePath() {
  673. resourcePrefix="$1"
  674. resourceVar="$""$resourcePrefix""_PATH"
  675. resourceName=`eval "echo \"$resourceVar\""`
  676. resourcePath=`resolveString "$resourceName"`
  677. echo "$resourcePath"
  678. }
  679. resolveResourceSize() {
  680. resourcePrefix="$1"
  681. resourceVar="$""$resourcePrefix""_SIZE"
  682. resourceSize=`eval "echo \"$resourceVar\""`
  683. echo "$resourceSize"
  684. }
  685. resolveResourceMd5() {
  686. resourcePrefix="$1"
  687. resourceVar="$""$resourcePrefix""_MD5"
  688. resourceMd5=`eval "echo \"$resourceVar\""`
  689. echo "$resourceMd5"
  690. }
  691. resolveResourceType() {
  692. resourcePrefix="$1"
  693. resourceVar="$""$resourcePrefix""_TYPE"
  694. resourceType=`eval "echo \"$resourceVar\""`
  695. echo "$resourceType"
  696. }
  697. extractResource() {
  698. debug "... extracting resource"
  699. resourcePrefix="$1"
  700. debug "... resource prefix id=$resourcePrefix"
  701. resourceType=`resolveResourceType "$resourcePrefix"`
  702. debug "... resource type=$resourceType"
  703. if [ $resourceType -eq 0 ] ; then
  704. resourceSize=`resolveResourceSize "$resourcePrefix"`
  705. debug "... resource size=$resourceSize"
  706. resourcePath=`resolveResourcePath "$resourcePrefix"`
  707. debug "... resource path=$resourcePath"
  708. extractFile "$resourceSize" "$resourcePath"
  709. resourceMd5=`resolveResourceMd5 "$resourcePrefix"`
  710. debug "... resource md5=$resourceMd5"
  711. checkMd5 "$resourcePath" "$resourceMd5"
  712. debug "... done"
  713. fi
  714. debug "... extracting resource finished"
  715. }
  716. extractJars() {
  717. counter=0
  718. while [ $counter -lt $JARS_NUMBER ] ; do
  719. extractResource "JAR_$counter"
  720. counter=`expr "$counter" + 1`
  721. done
  722. }
  723. extractOtherData() {
  724. counter=0
  725. while [ $counter -lt $OTHER_RESOURCES_NUMBER ] ; do
  726. extractResource "OTHER_RESOURCE_$counter"
  727. counter=`expr "$counter" + 1`
  728. done
  729. }
  730. extractJVMFiles() {
  731. javaCounter=0
  732. debug "... total number of JVM files : $JAVA_LOCATION_NUMBER"
  733. while [ $javaCounter -lt $JAVA_LOCATION_NUMBER ] ; do
  734. extractResource "JAVA_LOCATION_$javaCounter"
  735. javaCounter=`expr "$javaCounter" + 1`
  736. done
  737. }
  738. processJarsClasspath() {
  739. JARS_CLASSPATH=""
  740. jarsCounter=0
  741. while [ $jarsCounter -lt $JARS_NUMBER ] ; do
  742. resolvedFile=`resolveResourcePath "JAR_$jarsCounter"`
  743. debug "... adding jar to classpath : $resolvedFile"
  744. if [ ! -f "$resolvedFile" ] && [ ! -d "$resolvedFile" ] && [ ! $isSymlink "$resolvedFile" ] ; then
  745. message "$MSG_ERROP_MISSING_RESOURCE" "$resolvedFile"
  746. exitProgram $ERROR_MISSING_RESOURCES
  747. else
  748. if [ -z "$JARS_CLASSPATH" ] ; then
  749. JARS_CLASSPATH="$resolvedFile"
  750. else
  751. JARS_CLASSPATH="$JARS_CLASSPATH":"$resolvedFile"
  752. fi
  753. fi
  754. jarsCounter=`expr "$jarsCounter" + 1`
  755. done
  756. debug "Jars classpath : $JARS_CLASSPATH"
  757. }
  758. extractFile() {
  759. start=$LAUNCHER_TRACKING_SIZE
  760. size=$1 #absolute size
  761. name="$2" #relative part
  762. fullBlocks=`expr $size / $FILE_BLOCK_SIZE`
  763. fullBlocksSize=`expr "$FILE_BLOCK_SIZE" \* "$fullBlocks"`
  764. oneBlocks=`expr $size - $fullBlocksSize`
  765. oneBlocksStart=`expr "$start" + "$fullBlocks"`
  766. checkFreeSpace $size "$name"
  767. LAUNCHER_TRACKING_SIZE_BYTES=`expr "$LAUNCHER_TRACKING_SIZE" \* "$FILE_BLOCK_SIZE"`
  768. if [ 0 -eq $diskSpaceCheck ] ; then
  769. dir=`dirname "$name"`
  770. message "$MSG_ERROR_FREESPACE" "$size" "$ARG_TEMPDIR"
  771. exitProgram $ERROR_FREESPACE
  772. fi
  773. if [ 0 -lt "$fullBlocks" ] ; then
  774. # file is larger than FILE_BLOCK_SIZE
  775. dd if="$LAUNCHER_FULL_PATH" of="$name" \
  776. bs="$FILE_BLOCK_SIZE" count="$fullBlocks" skip="$start"\
  777. > /dev/null 2>&1
  778. LAUNCHER_TRACKING_SIZE=`expr "$LAUNCHER_TRACKING_SIZE" + "$fullBlocks"`
  779. LAUNCHER_TRACKING_SIZE_BYTES=`expr "$LAUNCHER_TRACKING_SIZE" \* "$FILE_BLOCK_SIZE"`
  780. fi
  781. if [ 0 -lt "$oneBlocks" ] ; then
  782. dd if="$LAUNCHER_FULL_PATH" of="$name.tmp.tmp" bs="$FILE_BLOCK_SIZE" count=1\
  783. skip="$oneBlocksStart"\
  784. > /dev/null 2>&1
  785. dd if="$name.tmp.tmp" of="$name" bs=1 count="$oneBlocks" seek="$fullBlocksSize"\
  786. > /dev/null 2>&1
  787. rm -f "$name.tmp.tmp"
  788. LAUNCHER_TRACKING_SIZE=`expr "$LAUNCHER_TRACKING_SIZE" + 1`
  789. LAUNCHER_TRACKING_SIZE_BYTES=`expr "$LAUNCHER_TRACKING_SIZE_BYTES" + "$oneBlocks"`
  790. fi
  791. }
  792. md5_program=""
  793. no_md5_program_id="no_md5_program"
  794. initMD5program() {
  795. if [ -z "$md5_program" ] ; then
  796. type digest >> /dev/null 2>&1
  797. if [ 0 -eq $? ] ; then
  798. md5_program="digest -a md5"
  799. else
  800. type md5sum >> /dev/null 2>&1
  801. if [ 0 -eq $? ] ; then
  802. md5_program="md5sum"
  803. else
  804. type gmd5sum >> /dev/null 2>&1
  805. if [ 0 -eq $? ] ; then
  806. md5_program="gmd5sum"
  807. else
  808. type md5 >> /dev/null 2>&1
  809. if [ 0 -eq $? ] ; then
  810. md5_program="md5 -q"
  811. else
  812. md5_program="$no_md5_program_id"
  813. fi
  814. fi
  815. fi
  816. fi
  817. debug "... program to check: $md5_program"
  818. fi
  819. }
  820. checkMd5() {
  821. name="$1"
  822. md5="$2"
  823. if [ 32 -eq `getStringLength "$md5"` ] ; then
  824. #do MD5 check
  825. initMD5program
  826. if [ 0 -eq `ifEquals "$md5_program" "$no_md5_program_id"` ] ; then
  827. debug "... check MD5 of file : $name"
  828. debug "... expected md5: $md5"
  829. realmd5=`$md5_program "$name" 2>/dev/null | sed "s/ .*//g"`
  830. debug "... real md5 : $realmd5"
  831. if [ 32 -eq `getStringLength "$realmd5"` ] ; then
  832. if [ 0 -eq `ifEquals "$md5" "$realmd5"` ] ; then
  833. debug "... integration check FAILED"
  834. message "$MSG_ERROR_INTEGRITY" `normalizePath "$LAUNCHER_FULL_PATH"`
  835. exitProgram $ERROR_INTEGRITY
  836. fi
  837. else
  838. debug "... looks like not the MD5 sum"
  839. fi
  840. fi
  841. fi
  842. }
  843. searchJavaEnvironment() {
  844. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  845. # search java in the environment
  846. ptr="$POSSIBLE_JAVA_ENV"
  847. while [ -n "$ptr" ] && [ -z "$LAUNCHER_JAVA_EXE" ] ; do
  848. argJavaHome=`echo "$ptr" | sed "s/:.*//"`
  849. back=`echo "$argJavaHome" | sed "s/\\\//\\\\\\\\\//g"`
  850. end=`echo "$ptr" | sed "s/${back}://"`
  851. argJavaHome=`echo "$back" | sed "s/\\\\\\\\\//\\\//g"`
  852. ptr="$end"
  853. eval evaluated=`echo \\$$argJavaHome` > /dev/null
  854. if [ -n "$evaluated" ] ; then
  855. debug "EnvVar $argJavaHome=$evaluated"
  856. verifyJVM "$evaluated"
  857. fi
  858. done
  859. fi
  860. }
  861. installBundledJVMs() {
  862. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  863. # search bundled java in the common list
  864. javaCounter=0
  865. while [ $javaCounter -lt $JAVA_LOCATION_NUMBER ] && [ -z "$LAUNCHER_JAVA_EXE" ] ; do
  866. fileType=`resolveResourceType "JAVA_LOCATION_$javaCounter"`
  867. if [ $fileType -eq 0 ] ; then # bundled->install
  868. argJavaHome=`resolveResourcePath "JAVA_LOCATION_$javaCounter"`
  869. installJVM "$argJavaHome"
  870. fi
  871. javaCounter=`expr "$javaCounter" + 1`
  872. done
  873. fi
  874. }
  875. searchJavaSystemDefault() {
  876. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  877. debug "... check default java in the path"
  878. java_bin=`which java 2>&1`
  879. if [ $? -eq 0 ] && [ -n "$java_bin" ] ; then
  880. remove_no_java_in=`echo "$java_bin" | sed "s/no java in//g"`
  881. if [ 1 -eq `ifEquals "$remove_no_java_in" "$java_bin"` ] && [ -f "$java_bin" ] ; then
  882. debug "... java in path found: $java_bin"
  883. # java is in path
  884. java_bin=`resolveSymlink "$java_bin"`
  885. debug "... java real path: $java_bin"
  886. parentDir=`dirname "$java_bin"`
  887. if [ -n "$parentDir" ] ; then
  888. parentDir=`dirname "$parentDir"`
  889. if [ -n "$parentDir" ] ; then
  890. debug "... java home path: $parentDir"
  891. parentDir=`resolveSymlink "$parentDir"`
  892. debug "... java home real path: $parentDir"
  893. verifyJVM "$parentDir"
  894. fi
  895. fi
  896. fi
  897. fi
  898. fi
  899. }
  900. searchJavaSystemPaths() {
  901. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  902. # search java in the common system paths
  903. javaCounter=0
  904. while [ $javaCounter -lt $JAVA_LOCATION_NUMBER ] && [ -z "$LAUNCHER_JAVA_EXE" ] ; do
  905. fileType=`resolveResourceType "JAVA_LOCATION_$javaCounter"`
  906. argJavaHome=`resolveResourcePath "JAVA_LOCATION_$javaCounter"`
  907. debug "... next location $argJavaHome"
  908. if [ $fileType -ne 0 ] ; then # bundled JVMs have already been proceeded
  909. argJavaHome=`escapeString "$argJavaHome"`
  910. locations=`ls -d -1 $argJavaHome 2>/dev/null`
  911. nextItem="$locations"
  912. itemCounter=1
  913. while [ -n "$nextItem" ] && [ -z "$LAUNCHER_JAVA_EXE" ] ; do
  914. nextItem=`echo "$locations" | sed -n "${itemCounter}p" 2>/dev/null`
  915. debug "... next item is $nextItem"
  916. nextItem=`removeEndSlashes "$nextItem"`
  917. if [ -n "$nextItem" ] ; then
  918. if [ -d "$nextItem" ] || [ $isSymlink "$nextItem" ] ; then
  919. debug "... checking item : $nextItem"
  920. verifyJVM "$nextItem"
  921. fi
  922. fi
  923. itemCounter=`expr "$itemCounter" + 1`
  924. done
  925. fi
  926. javaCounter=`expr "$javaCounter" + 1`
  927. done
  928. fi
  929. }
  930. searchJavaUserDefined() {
  931. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  932. if [ -n "$LAUNCHER_JAVA" ] ; then
  933. verifyJVM "$LAUNCHER_JAVA"
  934. if [ $VERIFY_UNCOMPATIBLE -eq $verifyResult ] ; then
  935. message "$MSG_ERROR_JVM_UNCOMPATIBLE" "$LAUNCHER_JAVA" "$ARG_JAVAHOME"
  936. exitProgram $ERROR_JVM_UNCOMPATIBLE
  937. elif [ $VERIFY_NOJAVA -eq $verifyResult ] ; then
  938. message "$MSG_ERROR_USER_ERROR" "$LAUNCHER_JAVA"
  939. exitProgram $ERROR_JVM_NOT_FOUND
  940. fi
  941. fi
  942. fi
  943. }
  944. searchJava() {
  945. message "$MSG_JVM_SEARCH"
  946. if [ ! -f "$TEST_JVM_CLASSPATH" ] && [ ! $isSymlink "$TEST_JVM_CLASSPATH" ] && [ ! -d "$TEST_JVM_CLASSPATH" ]; then
  947. debug "Cannot find file for testing JVM at $TEST_JVM_CLASSPATH"
  948. message "$MSG_ERROR_JVM_NOT_FOUND" "$ARG_JAVAHOME"
  949. exitProgram $ERROR_TEST_JVM_FILE
  950. else
  951. searchJavaUserDefined
  952. installBundledJVMs
  953. searchJavaEnvironment
  954. searchJavaSystemDefault
  955. searchJavaSystemPaths
  956. fi
  957. if [ -z "$LAUNCHER_JAVA_EXE" ] ; then
  958. message "$MSG_ERROR_JVM_NOT_FOUND" "$ARG_JAVAHOME"
  959. exitProgram $ERROR_JVM_NOT_FOUND
  960. fi
  961. }
  962. normalizePath() {
  963. argument="$1"
  964. # replace XXX/../YYY to 'dirname XXX'/YYY
  965. while [ 0 -eq 0 ] ; do
  966. beforeDotDot=`echo "$argument" | sed "s/\/\.\.\/.*//g" 2> /dev/null`
  967. if [ 0 -eq `ifEquals "$beforeDotDot" "$argument"` ] && [ 0 -eq `ifEquals "$beforeDotDot" "."` ] && [ 0 -eq `ifEquals "$beforeDotDot" ".."` ] ; then
  968. esc=`echo "$beforeDotDot" | sed "s/\\\//\\\\\\\\\//g"`
  969. afterDotDot=`echo "$argument" | sed "s/^$esc\/\.\.//g" 2> /dev/null`
  970. parent=`dirname "$beforeDotDot"`
  971. argument=`echo "$parent""$afterDotDot"`
  972. else
  973. break
  974. fi
  975. done
  976. # replace XXX/.. to 'dirname XXX'
  977. while [ 0 -eq 0 ] ; do
  978. beforeDotDot=`echo "$argument" | sed "s/\/\.\.$//g" 2> /dev/null`
  979. if [ 0 -eq `ifEquals "$beforeDotDot" "$argument"` ] && [ 0 -eq `ifEquals "$beforeDotDot" "."` ] && [ 0 -eq `ifEquals "$beforeDotDot" ".."` ] ; then
  980. argument=`dirname "$beforeDotDot"`
  981. else
  982. break
  983. fi
  984. done
  985. # replace all /./ to /
  986. while [ 0 -eq 0 ] ; do
  987. testArgument=`echo "$argument" | sed 's/\/\.\//\//g' 2> /dev/null`
  988. if [ -n "$testArgument" ] && [ 0 -eq `ifEquals "$argument" "$testArgument"` ] ; then
  989. # something changed
  990. argument="$testArgument"
  991. else
  992. break
  993. fi
  994. done
  995. # remove /. a the end (if the resulting string is not zero)
  996. testArgument=`echo "$argument" | sed 's/\/\.$//' 2> /dev/null`
  997. if [ -n "$testArgument" ] ; then
  998. argument="$testArgument"
  999. fi
  1000. # replace more than 2 separators to 1
  1001. testArgument=`echo "$argument" | sed 's/\/\/*/\//g' 2> /dev/null`
  1002. if [ -n "$testArgument" ] ; then
  1003. argument="$testArgument"
  1004. fi
  1005. echo "$argument"
  1006. }
  1007. resolveSymlink() {
  1008. pathArg="$1"
  1009. while [ $isSymlink "$pathArg" ] ; do
  1010. ls=`ls -ld "$pathArg"`
  1011. link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
  1012. if expr "$link" : '^/' 2> /dev/null >/dev/null; then
  1013. pathArg="$link"
  1014. else
  1015. pathArg="`dirname "$pathArg"`"/"$link"
  1016. fi
  1017. pathArg=`normalizePath "$pathArg"`
  1018. done
  1019. echo "$pathArg"
  1020. }
  1021. verifyJVM() {
  1022. javaTryPath=`normalizePath "$1"`
  1023. verifyJavaHome "$javaTryPath"
  1024. if [ $VERIFY_OK -ne $verifyResult ] ; then
  1025. savedResult=$verifyResult
  1026. if [ 0 -eq $isMacOSX ] ; then
  1027. #check private jre
  1028. javaTryPath="$javaTryPath""/jre"
  1029. verifyJavaHome "$javaTryPath"
  1030. else
  1031. #check MacOSX Home dir
  1032. javaTryPath="$javaTryPath""/Home"
  1033. verifyJavaHome "$javaTryPath"
  1034. fi
  1035. if [ $VERIFY_NOJAVA -eq $verifyResult ] ; then
  1036. verifyResult=$savedResult
  1037. fi
  1038. fi
  1039. }
  1040. removeEndSlashes() {
  1041. arg="$1"
  1042. tryRemove=`echo "$arg" | sed 's/\/\/*$//' 2>/dev/null`
  1043. if [ -n "$tryRemove" ] ; then
  1044. arg="$tryRemove"
  1045. fi
  1046. echo "$arg"
  1047. }
  1048. checkJavaHierarchy() {
  1049. # return 0 on no java
  1050. # return 1 on jre
  1051. # return 2 on jdk
  1052. tryJava="$1"
  1053. javaHierarchy=0
  1054. if [ -n "$tryJava" ] ; then
  1055. if [ -d "$tryJava" ] || [ $isSymlink "$tryJava" ] ; then # existing directory or a isSymlink
  1056. javaLib="$tryJava"/"lib"
  1057. if [ -d "$javaLib" ] || [ $isSymlink "$javaLib" ] ; then
  1058. javaLibDtjar="$javaLib"/"dt.jar"
  1059. if [ -f "$javaLibDtjar" ] || [ -f "$javaLibDtjar" ] ; then
  1060. #definitely JDK as the JRE doesn`t have dt.jar
  1061. javaHierarchy=2
  1062. else
  1063. #check if we inside JRE
  1064. javaLibJce="$javaLib"/"jce.jar"
  1065. javaLibCharsets="$javaLib"/"charsets.jar"
  1066. javaLibRt="$javaLib"/"rt.jar"
  1067. if [ -f "$javaLibJce" ] || [ $isSymlink "$javaLibJce" ] || [ -f "$javaLibCharsets" ] || [ $isSymlink "$javaLibCharsets" ] || [ -f "$javaLibRt" ] || [ $isSymlink "$javaLibRt" ] ; then
  1068. javaHierarchy=1
  1069. fi
  1070. fi
  1071. fi
  1072. fi
  1073. fi
  1074. if [ 0 -eq $javaHierarchy ] ; then
  1075. debug "... no java there"
  1076. elif [ 1 -eq $javaHierarchy ] ; then
  1077. debug "... JRE there"
  1078. elif [ 2 -eq $javaHierarchy ] ; then
  1079. debug "... JDK there"
  1080. fi
  1081. }
  1082. verifyJavaHome() {
  1083. verifyResult=$VERIFY_NOJAVA
  1084. java=`removeEndSlashes "$1"`
  1085. debug "... verify : $java"
  1086. java=`resolveSymlink "$java"`
  1087. debug "... real path : $java"
  1088. checkJavaHierarchy "$java"
  1089. if [ 0 -ne $javaHierarchy ] ; then
  1090. testJVMclasspath=`escapeString "$TEST_JVM_CLASSPATH"`
  1091. testJVMclass=`escapeString "$TEST_JVM_CLASS"`
  1092. pointer="$POSSIBLE_JAVA_EXE_SUFFIX"
  1093. while [ -n "$pointer" ] && [ -z "$LAUNCHER_JAVA_EXE" ]; do
  1094. arg=`echo "$pointer" | sed "s/:.*//"`
  1095. back=`echo "$arg" | sed "s/\\\//\\\\\\\\\//g"`
  1096. end=`echo "$pointer" | sed "s/${back}://"`
  1097. arg=`echo "$back" | sed "s/\\\\\\\\\//\\\//g"`
  1098. pointer="$end"
  1099. javaExe="$java/$arg"
  1100. if [ -x "$javaExe" ] ; then
  1101. javaExeEscaped=`escapeString "$javaExe"`
  1102. command="$javaExeEscaped -classpath $testJVMclasspath $testJVMclass"
  1103. debug "Executing java verification command..."
  1104. debug "$command"
  1105. output=`eval "$command" 2>/dev/null`
  1106. javaVersion=`echo "$output" | sed "2d;3d;4d;5d"`
  1107. javaVmVersion=`echo "$output" | sed "1d;3d;4d;5d"`
  1108. vendor=`echo "$output" | sed "1d;2d;4d;5d"`
  1109. osname=`echo "$output" | sed "1d;2d;3d;5d"`
  1110. osarch=`echo "$output" | sed "1d;2d;3d;4d"`
  1111. debug "Java :"
  1112. debug " executable = {$javaExe}"
  1113. debug " javaVersion = {$javaVersion}"
  1114. debug " javaVmVersion = {$javaVmVersion}"
  1115. debug " vendor = {$vendor}"
  1116. debug " osname = {$osname}"
  1117. debug " osarch = {$osarch}"
  1118. comp=0
  1119. if [ -n "$javaVersion" ] && [ -n "$javaVmVersion" ] && [ -n "$vendor" ] && [ -n "$osname" ] && [ -n "$osarch" ] ; then
  1120. debug "... seems to be java indeed"
  1121. javaVersionEsc=`escapeBackslash "$javaVersion"`
  1122. javaVmVersionEsc=`escapeBackslash "$javaVmVersion"`
  1123. javaVersion=`awk 'END { idx = index(b,a); if(idx!=0) { print substr(b,idx,length(b)) } else { print a } }' a="$javaVersionEsc" b="$javaVmVersionEsc" < /dev/null`
  1124. #remove build number
  1125. javaVersion=`echo "$javaVersion" | sed 's/-.*$//;s/\ .*//'`
  1126. verifyResult=$VERIFY_UNCOMPATIBLE
  1127. if [ -n "$javaVersion" ] ; then
  1128. debug " checking java version = {$javaVersion}"
  1129. javaCompCounter=0
  1130. while [ $javaCompCounter -lt $JAVA_COMPATIBLE_PROPERTIES_NUMBER ] && [ -z "$LAUNCHER_JAVA_EXE" ] ; do
  1131. comp=1
  1132. setJavaCompatibilityProperties_$javaCompCounter
  1133. debug "Min Java Version : $JAVA_COMP_VERSION_MIN"
  1134. debug "Max Java Version : $JAVA_COMP_VERSION_MAX"
  1135. debug "Java Vendor : $JAVA_COMP_VENDOR"
  1136. debug "Java OS Name : $JAVA_COMP_OSNAME"
  1137. debug "Java OS Arch : $JAVA_COMP_OSARCH"
  1138. if [ -n "$JAVA_COMP_VERSION_MIN" ] ; then
  1139. compMin=`ifVersionLess "$javaVersion" "$JAVA_COMP_VERSION_MIN"`
  1140. if [ 1 -eq $compMin ] ; then
  1141. comp=0
  1142. fi
  1143. fi
  1144. if [ -n "$JAVA_COMP_VERSION_MAX" ] ; then
  1145. compMax=`ifVersionGreater "$javaVersion" "$JAVA_COMP_VERSION_MAX"`
  1146. if [ 1 -eq $compMax ] ; then
  1147. comp=0
  1148. fi
  1149. fi
  1150. if [ -n "$JAVA_COMP_VENDOR" ] ; then
  1151. debug " checking vendor = {$vendor}, {$JAVA_COMP_VENDOR}"
  1152. subs=`echo "$vendor" | sed "s/${JAVA_COMP_VENDOR}//"`
  1153. if [ `ifEquals "$subs" "$vendor"` -eq 1 ] ; then
  1154. comp=0
  1155. debug "... vendor incompatible"
  1156. fi
  1157. fi
  1158. if [ -n "$JAVA_COMP_OSNAME" ] ; then
  1159. debug " checking osname = {$osname}, {$JAVA_COMP_OSNAME}"
  1160. subs=`echo "$osname" | sed "s/${JAVA_COMP_OSNAME}//"`
  1161. if [ `ifEquals "$subs" "$osname"` -eq 1 ] ; then
  1162. comp=0
  1163. debug "... osname incompatible"
  1164. fi
  1165. fi
  1166. if [ -n "$JAVA_COMP_OSARCH" ] ; then
  1167. debug " checking osarch = {$osarch}, {$JAVA_COMP_OSARCH}"
  1168. subs=`echo "$osarch" | sed "s/${JAVA_COMP_OSARCH}//"`
  1169. if [ `ifEquals "$subs" "$osarch"` -eq 1 ] ; then
  1170. comp=0
  1171. debug "... osarch incompatible"
  1172. fi
  1173. fi
  1174. if [ $comp -eq 1 ] ; then
  1175. LAUNCHER_JAVA_EXE="$javaExe"
  1176. LAUNCHER_JAVA="$java"
  1177. verifyResult=$VERIFY_OK
  1178. fi
  1179. debug " compatible = [$comp]"
  1180. javaCompCounter=`expr "$javaCompCounter" + 1`
  1181. done
  1182. fi
  1183. fi
  1184. fi
  1185. done
  1186. fi
  1187. }
  1188. checkFreeSpace() {
  1189. size="$1"
  1190. path="$2"
  1191. if [ ! -d "$path" ] && [ ! $isSymlink "$path" ] ; then
  1192. # if checking path is not an existing directory - check its parent dir
  1193. path=`dirname "$path"`
  1194. fi
  1195. diskSpaceCheck=0
  1196. if [ 0 -eq $PERFORM_FREE_SPACE_CHECK ] ; then
  1197. diskSpaceCheck=1
  1198. else
  1199. # get size of the atomic entry (directory)
  1200. freeSpaceDirCheck="$path"/freeSpaceCheckDir
  1201. debug "Checking space in $path (size = $size)"
  1202. mkdir -p "$freeSpaceDirCheck"
  1203. # POSIX compatible du return size in 1024 blocks
  1204. du --block-size=$DEFAULT_DISK_BLOCK_SIZE "$freeSpaceDirCheck" 1>/dev/null 2>&1
  1205. if [ $? -eq 0 ] ; then
  1206. debug " getting POSIX du with 512 bytes blocks"
  1207. atomicBlock=`du --block-size=$DEFAULT_DISK_BLOCK_SIZE "$freeSpaceDirCheck" | awk ' { print $A }' A=1 2>/dev/null`
  1208. else
  1209. debug " getting du with default-size blocks"
  1210. atomicBlock=`du "$freeSpaceDirCheck" | awk ' { print $A }' A=1 2>/dev/null`
  1211. fi
  1212. rm -rf "$freeSpaceDirCheck"
  1213. debug " atomic block size : [$atomicBlock]"
  1214. isBlockNumber=`ifNumber "$atomicBlock"`
  1215. if [ 0 -eq $isBlockNumber ] ; then
  1216. out "Can\`t get disk block size"
  1217. exitProgram $ERROR_INPUTOUPUT
  1218. fi
  1219. requiredBlocks=`expr \( "$1" / $DEFAULT_DISK_BLOCK_SIZE \) + $atomicBlock` 1>/dev/null 2>&1
  1220. if [ `ifNumber $1` -eq 0 ] ; then
  1221. out "Can\`t calculate required blocks size"
  1222. exitProgram $ERROR_INPUTOUPUT
  1223. fi
  1224. # get free block size
  1225. column=4
  1226. df -P --block-size="$DEFAULT_DISK_BLOCK_SIZE" "$path" 1>/dev/null 2>&1
  1227. if [ $? -eq 0 ] ; then
  1228. # gnu df, use POSIX output
  1229. debug " getting GNU POSIX df with specified block size $DEFAULT_DISK_BLOCK_SIZE"
  1230. availableBlocks=`df -P --block-size="$DEFAULT_DISK_BLOCK_SIZE" "$path" | sed "1d" | awk ' { print $A }' A=$column 2>/dev/null`
  1231. else
  1232. # try POSIX output
  1233. df -P "$path" 1>/dev/null 2>&1
  1234. if [ $? -eq 0 ] ; then
  1235. debug " getting POSIX df with 512 bytes blocks"
  1236. availableBlocks=`df -P "$path" | sed "1d" | awk ' { print $A }' A=$column 2>/dev/null`
  1237. # try Solaris df from xpg4
  1238. elif [ -x /usr/xpg4/bin/df ] ; then
  1239. debug " getting xpg4 df with default-size blocks"
  1240. availableBlocks=`/usr/xpg4/bin/df -P "$path" | sed "1d" | awk ' { print $A }' A=$column 2>/dev/null`
  1241. # last chance to get free space
  1242. else
  1243. debug " getting df with default-size blocks"
  1244. availableBlocks=`df "$path" | sed "1d" | awk ' { print $A }' A=$column 2>/dev/null`
  1245. fi
  1246. fi
  1247. debug " available blocks : [$availableBlocks]"
  1248. if [ `ifNumber "$availableBlocks"` -eq 0 ] ; then
  1249. out "Can\`t get the number of the available blocks on the system"
  1250. exitProgram $ERROR_INPUTOUTPUT
  1251. fi
  1252. # compare
  1253. debug " required blocks : [$requiredBlocks]"
  1254. if [ $availableBlocks -gt $requiredBlocks ] ; then
  1255. debug "... disk space check OK"
  1256. diskSpaceCheck=1
  1257. else
  1258. debug "... disk space check FAILED"
  1259. fi
  1260. fi
  1261. if [ 0 -eq $diskSpaceCheck ] ; then
  1262. mbDownSize=`expr "$size" / 1024 / 1024`
  1263. mbUpSize=`expr "$size" / 1024 / 1024 + 1`
  1264. mbSize=`expr "$mbDownSize" \* 1024 \* 1024`
  1265. if [ $size -ne $mbSize ] ; then
  1266. mbSize="$mbUpSize"
  1267. else
  1268. mbSize="$mbDownSize"
  1269. fi
  1270. message "$MSG_ERROR_FREESPACE" "$mbSize" "$ARG_TEMPDIR"
  1271. exitProgram $ERROR_FREESPACE
  1272. fi
  1273. }
  1274. prepareClasspath() {
  1275. debug "Processing external jars ..."
  1276. processJarsClasspath
  1277. LAUNCHER_CLASSPATH=""
  1278. if [ -n "$JARS_CLASSPATH" ] ; then
  1279. if [ -z "$LAUNCHER_CLASSPATH" ] ; then
  1280. LAUNCHER_CLASSPATH="$JARS_CLASSPATH"
  1281. else
  1282. LAUNCHER_CLASSPATH="$LAUNCHER_CLASSPATH":"$JARS_CLASSPATH"
  1283. fi
  1284. fi
  1285. if [ -n "$PREPEND_CP" ] ; then
  1286. debug "Appending classpath with [$PREPEND_CP]"
  1287. PREPEND_CP=`resolveString "$PREPEND_CP"`
  1288. if [ -z "$LAUNCHER_CLASSPATH" ] ; then
  1289. LAUNCHER_CLASSPATH="$PREPEND_CP"
  1290. else
  1291. LAUNCHER_CLASSPATH="$PREPEND_CP":"$LAUNCHER_CLASSPATH"
  1292. fi
  1293. fi
  1294. if [ -n "$APPEND_CP" ] ; then
  1295. debug "Appending classpath with [$APPEND_CP]"
  1296. APPEND_CP=`resolveString "$APPEND_CP"`
  1297. if [ -z "$LAUNCHER_CLASSPATH" ] ; then
  1298. LAUNCHER_CLASSPATH="$APPEND_CP"
  1299. else
  1300. LAUNCHER_CLASSPATH="$LAUNCHER_CLASSPATH":"$APPEND_CP"
  1301. fi
  1302. fi
  1303. debug "Launcher Classpath : $LAUNCHER_CLASSPATH"
  1304. }
  1305. resolvePropertyStrings() {
  1306. args="$1"
  1307. escapeReplacedString="$2"
  1308. propertyStart=`echo "$args" | sed "s/^.*\\$P{//"`
  1309. propertyValue=""
  1310. propertyName=""
  1311. #Resolve i18n strings and properties
  1312. if [ 0 -eq `ifEquals "$propertyStart" "$args"` ] ; then
  1313. propertyName=`echo "$propertyStart" | sed "s/}.*//" 2>/dev/null`
  1314. if [ -n "$propertyName" ] ; then
  1315. propertyValue=`getMessage "$propertyName"`
  1316. if [ 0 -eq `ifEquals "$propertyValue" "$propertyName"` ] ; then
  1317. propertyName="\$P{$propertyName}"
  1318. args=`replaceString "$args" "$propertyName" "$propertyValue" "$escapeReplacedString"`
  1319. fi
  1320. fi
  1321. fi
  1322. echo "$args"
  1323. }
  1324. resolveLauncherSpecialProperties() {
  1325. args="$1"
  1326. escapeReplacedString="$2"
  1327. propertyValue=""
  1328. propertyName=""
  1329. propertyStart=`echo "$args" | sed "s/^.*\\$L{//"`
  1330. if [ 0 -eq `ifEquals "$propertyStart" "$args"` ] ; then
  1331. propertyName=`echo "$propertyStart" | sed "s/}.*//" 2>/dev/null`
  1332. if [ -n "$propertyName" ] ; then
  1333. case "$propertyName" in
  1334. "nbi.launcher.tmp.dir")
  1335. propertyValue="$LAUNCHER_EXTRACT_DIR"
  1336. ;;
  1337. "nbi.launcher.java.home")
  1338. propertyValue="$LAUNCHER_JAVA"
  1339. ;;
  1340. "nbi.launcher.user.home")
  1341. propertyValue="$HOME"
  1342. ;;
  1343. "nbi.launcher.parent.dir")
  1344. propertyValue="$LAUNCHER_DIR"
  1345. ;;
  1346. *)
  1347. propertyValue="$propertyName"
  1348. ;;
  1349. esac
  1350. if [ 0 -eq `ifEquals "$propertyValue" "$propertyName"` ] ; then
  1351. propertyName="\$L{$propertyName}"
  1352. args=`replaceString "$args" "$propertyName" "$propertyValue" "$escapeReplacedString"`
  1353. fi
  1354. fi
  1355. fi
  1356. echo "$args"
  1357. }
  1358. resolveString() {
  1359. args="$1"
  1360. escapeReplacedString="$2"
  1361. last="$args"
  1362. repeat=1
  1363. while [ 1 -eq $repeat ] ; do
  1364. repeat=1
  1365. args=`resolvePropertyStrings "$args" "$escapeReplacedString"`
  1366. args=`resolveLauncherSpecialProperties "$args" "$escapeReplacedString"`
  1367. if [ 1 -eq `ifEquals "$last" "$args"` ] ; then
  1368. repeat=0
  1369. fi
  1370. last="$args"
  1371. done
  1372. echo "$args"
  1373. }
  1374. replaceString() {
  1375. initialString="$1"
  1376. fromString="$2"
  1377. toString="$3"
  1378. if [ -n "$4" ] && [ 0 -eq `ifEquals "$4" "false"` ] ; then
  1379. toString=`escapeString "$toString"`
  1380. fi
  1381. fromString=`echo "$fromString" | sed "s/\\\//\\\\\\\\\//g" 2>/dev/null`
  1382. toString=`echo "$toString" | sed "s/\\\//\\\\\\\\\//g" 2>/dev/null`
  1383. replacedString=`echo "$initialString" | sed "s/${fromString}/${toString}/g" 2>/dev/null`
  1384. echo "$replacedString"
  1385. }
  1386. prepareJVMArguments() {
  1387. debug "Prepare JVM arguments... "
  1388. jvmArgCounter=0
  1389. debug "... resolving string : $LAUNCHER_JVM_ARGUMENTS"
  1390. LAUNCHER_JVM_ARGUMENTS=`resolveString "$LAUNCHER_JVM_ARGUMENTS" true`
  1391. debug "... resolved string : $LAUNCHER_JVM_ARGUMENTS"
  1392. while [ $jvmArgCounter -lt $JVM_ARGUMENTS_NUMBER ] ; do
  1393. argumentVar="$""JVM_ARGUMENT_$jvmArgCounter"
  1394. arg=`eval "echo \"$argumentVar\""`
  1395. debug "... jvm argument [$jvmArgCounter] [initial] : $arg"
  1396. arg=`resolveString "$arg"`
  1397. debug "... jvm argument [$jvmArgCounter] [resolved] : $arg"
  1398. arg=`escapeString "$arg"`
  1399. debug "... jvm argument [$jvmArgCounter] [escaped] : $arg"
  1400. LAUNCHER_JVM_ARGUMENTS="$LAUNCHER_JVM_ARGUMENTS $arg"
  1401. jvmArgCounter=`expr "$jvmArgCounter" + 1`
  1402. done
  1403. debug "Final JVM arguments : $LAUNCHER_JVM_ARGUMENTS"
  1404. }
  1405. prepareAppArguments() {
  1406. debug "Prepare Application arguments... "
  1407. appArgCounter=0
  1408. debug "... resolving string : $LAUNCHER_APP_ARGUMENTS"
  1409. LAUNCHER_APP_ARGUMENTS=`resolveString "$LAUNCHER_APP_ARGUMENTS" true`
  1410. debug "... resolved string : $LAUNCHER_APP_ARGUMENTS"
  1411. while [ $appArgCounter -lt $APP_ARGU

Large files files are truncated, but you can click here to view the full file