OSDN Git Service

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