ControlPanel 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  4. # ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  5. #
  6. # Shell Script to run the Java Plug-in control panel.
  7. #
  8. # Parse the command-line options
  9. # -r means make associate with the container (i.e browser)
  10. # -u means remove the association with the container
  11. # -c provides the location of the container install
  12. # -j provides the location of the jre install
  13. # if neither -r or -u are specified, run the ControlPanel UI
  14. USAGE='usage: ControlPanel [ (-u scheme | -r scheme) -c cpath -j jrepath ]'
  15. JLERROR='ControlPanel: Error: Invalid JRE location: '
  16. CLERROR='ControlPanel: Error: Invalid container location: '
  17. IPERROR='ControlPanel: Error: Insufficient permission'
  18. ISERROR='ControlPanel: Error: Invalid scheme: '
  19. XLERROR='ControlPanel: Error: Invalid link or copy: '
  20. check_container_dir() {
  21. if [ ! -d ${1} ]; then
  22. echo "${CLERROR}${2}"
  23. exit 1
  24. fi
  25. if [ ! -w ${1} ]; then
  26. echo "${IPERROR}"
  27. exit 1
  28. fi
  29. }
  30. link_logic() {
  31. if [ ${mode} = "reg" ]; then
  32. ln -s ${1} ${2}
  33. else
  34. rm -f ${2}
  35. fi
  36. }
  37. #
  38. # Get the absolute path to a symbolic link's reference.
  39. #
  40. # Parameters:
  41. # $* : path - the path to the file (link) to dereference (can have spaces in
  42. # the path).
  43. #
  44. # Output:
  45. # This function writes the path to the link reference to stdout.
  46. #
  47. #
  48. dereference() {
  49. path="$*"
  50. result=
  51. #
  52. # Make sure the path is absolute
  53. #
  54. parent="`cd \`dirname \"${path}\"\`; pwd -P`"
  55. child="`basename \"${path}\"`"
  56. #
  57. # if parent == child, then path == /, and is already absolute
  58. #
  59. if [ "${parent}" != "${child}" ]; then
  60. path="${parent}/${child}"
  61. fi
  62. if [ -h "${path}" ]; then
  63. path=`ls -l "${path}" | sed -e "s#^.*${path} -> ##"`
  64. # make sure the path is still absolute (starts with '/')
  65. if expr "${path}" : '[^/]' > /dev/null; then
  66. path="${parent}/${path}"
  67. fi
  68. fi
  69. echo ${path}
  70. }
  71. #
  72. # Check for all the parts required to launch the control panel relative to the
  73. # given path.
  74. #
  75. #
  76. # Parameters:
  77. # $* : path - the path to examine, presumably the resolved path to this
  78. # script (can have spaces in the path).
  79. #
  80. # Output:
  81. # If successful, this function outputs the absolute path to a directory
  82. # containing the Java binary, and ../lib/deploy.jar; otherwise it outputs
  83. # an empty string. (Output is to stdout.)
  84. #
  85. # Note: the assumption is that this function returns either:
  86. #
  87. # <jdk-root>/jre/bin, or
  88. # <jre-root>/bin
  89. #
  90. # However, as long as the directory pointed by the path returned by this
  91. # function contains:
  92. #
  93. # ./java
  94. # ../lib/deploy.jar
  95. #
  96. # it should be possible to successfully launch the JCP from the given
  97. # information.
  98. #
  99. check_parts() {
  100. result="`cd \`dirname \"$*\"\`; pwd -P`"
  101. # if this is a JDK, we need the JRE subdir
  102. if [ -d "${result}/../jre/bin" ]; then
  103. result="`cd \`dirname \"$*\"\`/../jre/bin; pwd -P`"
  104. fi
  105. if [ ! -x "${result}/java" ] || [ ! -f "${result}/../lib/deploy.jar" ]; then
  106. result=
  107. fi
  108. echo ${result}
  109. }
  110. #
  111. # Launch the Java Control Panel.
  112. #
  113. # Parameters:
  114. # $* : path - the path of this script (can have spaces in the path).
  115. #
  116. launch_jcp() {
  117. path="$*"
  118. while [ -h ${path} ]; do
  119. path="`dereference ${path}`"
  120. done
  121. java_home="`check_parts ${path}`"
  122. if [ -n "${java_home}" ]; then
  123. # launch the JCP using paths relative to
  124. ${java_home}/java -Djavaplugin.user.profile=${USER_JPI_PROFILE} \
  125. -Xbootclasspath/a:${java_home}/../lib/deploy.jar \
  126. ${_JAVA_VM_OPTIONS} \
  127. com.sun.deploy.panel.ControlPanel
  128. else
  129. echo "${XLERROR}${java_home}"
  130. exit 1
  131. fi
  132. }
  133. #
  134. # Manage the process of registering/unregistering the Java Plug-in with a given
  135. # container (browser).
  136. #
  137. manage_container() {
  138. # Do the "right" thing based on the provided scheme.
  139. plugin_stem=${java_home}/plugin/${proc}
  140. if [ ! -d ${plugin_stem} ]; then
  141. echo "${JLERROR}${java_home}"
  142. exit 1
  143. fi
  144. case ${scheme} in
  145. ns4 | ns4E )
  146. plugin_location="${plugin_stem}/ns4"
  147. if [ ${mode} = "reg" ]; then
  148. echo "${plugin_location}"
  149. fi
  150. ;;
  151. ns4L )
  152. plugin_location="${plugin_stem}/ns4"
  153. filename=`ls ${plugin_location}`
  154. container_target="${container_home}/plugins"
  155. check_container_dir ${container_target} ${container_home}
  156. link_logic ${plugin_location}/${filename} ${container_target}/${filename}
  157. ;;
  158. ns610 | ns610L )
  159. plugin_location="${plugin_stem}/ns610"
  160. filename=`ls ${plugin_location}`
  161. container_target="${container_home}/plugins"
  162. check_container_dir ${container_target} ${container_home}
  163. link_logic ${plugin_location}/${filename} ${container_target}/${filename}
  164. ;;
  165. * )
  166. echo ${ISERROR}${scheme}
  167. exit 1
  168. esac
  169. }
  170. while getopts ":r:u:c:j:" opt; do
  171. case $opt in
  172. r ) mode="reg";scheme=${OPTARG}
  173. ;;
  174. u ) mode="unreg";scheme=${OPTARG}
  175. ;;
  176. c ) container_home=${OPTARG}
  177. ;;
  178. j ) java_home=${OPTARG}
  179. ;;
  180. : ) echo ${USAGE}
  181. exit 1
  182. ;;
  183. \? ) echo ${USAGE}
  184. exit 1
  185. ;;
  186. esac
  187. done
  188. os=`uname -s`
  189. if [ "${os}" = "Linux" ]; then
  190. case "`uname -m`" in
  191. i[3-9]86 | ia32 | ia64 | x86_64)
  192. proc=i386
  193. ;;
  194. sparc*)
  195. proc=sparc
  196. ;;
  197. arm*)
  198. proc=arm
  199. ;;
  200. ppc*)
  201. proc=ppc
  202. ;;
  203. *)
  204. proc="`uname -m`"
  205. ;;
  206. esac
  207. else
  208. proc=`uname -p`
  209. fi
  210. if [ -z "${scheme}" ] &&
  211. [ -z "${java_home}" ] && [ -z "${container_home}" ]
  212. then
  213. # just run the control panel
  214. launch_jcp $0
  215. elif [ -n "${scheme}" ] &&
  216. [ -n "${java_home}" ] && [ -n "${container_home}" ]
  217. then
  218. # try to register/unregister the plugin
  219. manage_container
  220. else
  221. # one or more missing args
  222. echo ${USAGE}
  223. exit 1
  224. fi