installUtility 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #!/bin/sh
  2. ##
  3. ## Determine the platform and absolute path of the directory for the current script.
  4. ##
  5. case $OSTYPE in
  6. cygwin)
  7. uname=CYGWIN_NT
  8. # Determine the installation directory without forking if possible. Use
  9. # eval to hide ${var//find/replace}, ${var%suffix}, and ${var:first:length}
  10. # syntaxes from shells that can't parse them.
  11. eval '
  12. # cd to the install directory.
  13. savePWD=$PWD
  14. script=${0//\\/\/}
  15. unset CDPATH; cd "${script%/*}/../"
  16. # Convert the install (current working) directory to a Windows path.
  17. case $PWD in
  18. /cygdrive/?/*)
  19. # Use ${var:first:length} to avoid forking for cygpath.
  20. WLP_INSTALL_DIR=${PWD:10:1}:${PWD:11}
  21. ;;
  22. *)
  23. WLP_INSTALL_DIR=`cygpath -ma .`
  24. esac
  25. cd "$savePWD"
  26. '
  27. ;;
  28. *)
  29. uname=`uname`
  30. case $uname in
  31. CYGWIN_*)
  32. WLP_INSTALL_DIR=`cygpath -ma "${0}"/../../`
  33. ;;
  34. *)
  35. dirname=`dirname "$0"`
  36. WLP_INSTALL_DIR=`unset CDPATH; cd "$dirname/../" && pwd`
  37. esac
  38. esac
  39. ##
  40. ## Platform specific setup
  41. ##
  42. newline='
  43. '
  44. nativeEBCDIC=false
  45. case ${uname} in
  46. OS/390)
  47. defaultFileEncoding=iso8859-1
  48. # Auto-convert server.env/jvm.options from ASCII-to-EBCDIC, if necessary.
  49. nativeEBCDIC=true
  50. ;;
  51. esac
  52. ##
  53. ## safeEcho: Portable echo that can handle backslashes and leading dashes.
  54. safeEcho()
  55. {
  56. cat <<EOF
  57. $*
  58. EOF
  59. }
  60. # Define escapeForEval functions using ${var//find/replace} and ${var#suffix}
  61. # if possible since those constructs are significantly faster than safeEcho+sed
  62. # since they avoid forks. Use eval (to hide the syntax from shells that don't
  63. # support them) in a subshell (to avoid exiting the shell process on error) to
  64. # test if the shell has support.
  65. if (eval 'true ${1//b/c} ${1#*=}') 2> /dev/null; then
  66. # The shell has support. Define the functions using eval, again to hide the
  67. # syntax from shells that don't support it.
  68. eval "
  69. escapeForEval()
  70. {
  71. escapeForEvalResult=\\'\${1//\\'/\\'\\\"\\'\\\"\\'}\\'
  72. }
  73. extractValueAndEscapeForEval()
  74. {
  75. escapeForEval \"\${1#*=}\"
  76. }
  77. substitutePrefixVar()
  78. {
  79. case \$1 in
  80. @\$2@*) substitutePrefixVarResult=\$3\${1#@\$2@};;
  81. *) substitutePrefixVarResult=\$1
  82. esac
  83. }
  84. "
  85. else
  86. ##
  87. ## escapeForEval: Escape the first parameter to be safe for use in eval,
  88. ## and set escapeForEvalResult with the result.
  89. ##
  90. escapeForEval()
  91. {
  92. escapeForEvalResult=\'`safeEcho "$1" | sed s/\'/\'\"\'\"\'/g`\'
  93. }
  94. ##
  95. ## extractValueAndEscapeForEval: Extract the value of a var=value string,
  96. ## and set escapeForEvalResult with the result.
  97. ##
  98. extractValueAndEscapeForEval()
  99. {
  100. escapeForEvalResult=\'`safeEcho "$1" | sed -e 's/[^=]*=//' -e s/\'/\'\"\'\"\'/g`\'
  101. }
  102. ##
  103. ## substitutePrefixVar: If $1 has a prefix @$2@, set substitutePrefixVarResult
  104. ## to $1 with the prefix replaced by $3. Otherwise, set
  105. ## to $1.
  106. substitutePrefixVar()
  107. {
  108. case $1 in
  109. @$2@*) substitutePrefixVarResult=$3`safeEcho "$1" | sed -e "s/^@$2@//"`;;
  110. *) substitutePrefixVarResult=$1
  111. esac
  112. }
  113. fi
  114. ##
  115. ## Quote ${WLP_INSTALL_DIR} for eval.
  116. ##
  117. escapeForEval "${WLP_INSTALL_DIR}"
  118. WLP_INSTALL_DIR_QUOTED=${escapeForEvalResult}
  119. ##
  120. ## Detects the code page of the file and converts to EBCDIC,
  121. ## if necessary, before cat'ing.
  122. ##
  123. ## Only applicable if running in a native EBCDIC environment (z/OS).
  124. ##
  125. ## $1 the file name
  126. ## $2 pattern denoting the expected first char of file
  127. readNativeFile() {
  128. if ${nativeEBCDIC}; then
  129. # ASCII 'm' overlaps with EBCDIC '_', so strip it out before detecting the codepage.
  130. # Note: cat used here to handle ASCII-tagged files.
  131. filecontents=`cat "$1" | iconv -f ISO8859-1 -t IBM-1047 | tr -d 'm\r\n'`
  132. case $filecontents in
  133. # ASCII file.
  134. $2*) iconv -f ISO8859-1 -t IBM-1047 "$1";;
  135. # EBCDIC file or ASCII-tagged file.
  136. *) cat "$1"
  137. esac
  138. else
  139. cat "$1"
  140. fi
  141. }
  142. ##
  143. ## readServerEnv: Read server.env file and export environment variables.
  144. readServerEnv()
  145. {
  146. if [ -f "$1" ]; then
  147. saveIFS=$IFS
  148. IFS=$newline
  149. for line in `readNativeFile "$1" '[#_A-Za-z=]' | tr -d '\r'`; do
  150. case $line in
  151. \#*);;
  152. *=*)
  153. # Only accept alphanumeric variable names to avoid eval complexities.
  154. if var=`safeEcho "$line" | sed -e 's/^\([a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/'`; then
  155. extractValueAndEscapeForEval "${line}"
  156. eval "${var}=${escapeForEvalResult}; export ${var}"
  157. fi
  158. esac
  159. done
  160. IFS=$saveIFS
  161. fi
  162. }
  163. ##
  164. ## toolJavaCmd: Executes a java command for the tool JAR.
  165. toolJavaCmd()
  166. {
  167. eval "set -- ${JVM_ARGS} -jar ${WLP_INSTALL_DIR_QUOTED}/bin/tools/ws-installUtility.jar "'"$@"'
  168. "${JAVA_CMD}" "$@"
  169. }
  170. readServerEnv "${WLP_INSTALL_DIR}/java/java.env"
  171. readServerEnv "${WLP_INSTALL_DIR}/etc/default.env"
  172. readServerEnv "${WLP_INSTALL_DIR}/etc/server.env"
  173. if [ -z "${WLP_USER_DIR}" ]
  174. then
  175. if [ -z "${WLP_DEFAULT_USER_DIR}" ]
  176. then
  177. WLP_DEFAULT_USER_DIR=${WLP_INSTALL_DIR}/usr
  178. fi
  179. WLP_USER_DIR=${WLP_DEFAULT_USER_DIR}
  180. export WLP_USER_DIR
  181. fi
  182. if [ -z "${WLP_OUTPUT_DIR}" ]
  183. then
  184. if [ -z "${WLP_DEFAULT_OUTPUT_DIR}" ]
  185. then
  186. WLP_DEFAULT_OUTPUT_DIR=${WLP_USER_DIR}/servers
  187. fi
  188. WLP_OUTPUT_DIR=${WLP_DEFAULT_OUTPUT_DIR}
  189. export WLP_OUTPUT_DIR
  190. fi
  191. if [ -z "${JAVA_HOME}" ]
  192. then
  193. if [ -z "${JRE_HOME}" ]
  194. then
  195. if [ -z "${WLP_DEFAULT_JAVA_HOME}" ]
  196. then
  197. # Use whatever java is on the path
  198. JAVA_CMD=java
  199. else
  200. substitutePrefixVar "${WLP_DEFAULT_JAVA_HOME}" WLP_INSTALL_DIR "${WLP_INSTALL_DIR}"
  201. JAVA_CMD=${substitutePrefixVarResult}/bin/java
  202. fi
  203. else
  204. JAVA_CMD=${JRE_HOME}/bin/java
  205. fi
  206. else
  207. if [ -f "${JAVA_HOME}/jre/bin/java" ]
  208. then
  209. JAVA_HOME=${JAVA_HOME}/jre
  210. fi
  211. JAVA_CMD=${JAVA_HOME}/bin/java
  212. fi
  213. # Set a default file encoding if needed
  214. if [ -n "$defaultFileEncoding" ]; then
  215. if ! expr "${JVM_ARGS} ${IBM_JAVA_OPTIONS}" : '.*\(-Dfile\.encoding\=[^[:space:]]\)' > /dev/null; then
  216. JVM_ARGS="${JVM_ARGS} -Dfile.encoding=$defaultFileEncoding"
  217. fi
  218. fi
  219. # If this is a Java 9 JDK, add some JDK 9 workarounds to the JVM_ARGS
  220. if [ -f "${JAVA_HOME}/lib/modules" ]; then
  221. JVM_ARGS="--add-opens java.base/java.lang=ALL-UNNAMED --add-exports java.base/sun.security.action=ALL-UNNAMED ${JVM_ARGS}"
  222. fi
  223. # Prevent the Java invocation appearing as an application on a mac
  224. # Setting on all platforms to avoid cross platform bugs
  225. JVM_ARGS="-Djava.awt.headless=true ${JVM_ARGS}"
  226. # Do not create a SCC
  227. if [ -n "${IBM_JAVA_OPTIONS}" ]; then
  228. IBM_JAVA_OPTIONS="${IBM_JAVA_OPTIONS} -Xshareclasses:none"
  229. fi
  230. if [ -n "${OPENJ9_JAVA_OPTIONS}" ]; then
  231. OPENJ9_JAVA_OPTIONS="${OPENJ9_JAVA_OPTIONS} -Xshareclasses:none"
  232. fi
  233. # Execute the tool script or JAR.
  234. if [ -f "${WLP_INSTALL_DIR}"/lib/tools-internal/installUtility ]; then
  235. . "${WLP_INSTALL_DIR}"/lib/tools-internal/installUtility "$@"
  236. else
  237. toolJavaCmd "$@"
  238. fi