Update ooo320-m1
[ooovba.git] / setup_native / scripts / javaloader.sh
bloba81f6192af369c09fdf834f97362545f6aba5528
1 #!/bin/sh
3 jarfilename="JavaSetup.jar"
4 tempdir=/var/tmp/install_$$
5 java_runtime="java"
6 java_runtime_set="no"
7 java_runtime_found="no"
8 java_runtime_sufficient="no"
9 java_versions_supported="1.4 1.5 1.6"
10 rpm2cpio_found="no"
11 rpm_found="no"
12 sunjavahotspot="HotSpot"
13 errortext=""
14 errorcode=""
16 start_java()
18 umask 022
20 echo "Using $java_runtime"
21 echo `$java_runtime -version`
22 echo "Running installer"
24 # looking for environment variables
26 home=""
27 if [ "x" != "x$HOME" ]; then
28 home=-DHOME=$HOME
31 log_module_states=""
32 if [ "x" != "x$LOG_MODULE_STATES" ]; then
33 log_module_states=-DLOG_MODULE_STATES=$LOG_MODULE_STATES
36 getuid_path=""
37 if [ "x" != "x$GETUID_PATH" ]; then
38 getuid_path=-DGETUID_PATH=$GETUID_PATH
41 if [ "x" != "x$jrefile" ]; then
42 jrecopy=-DJRE_FILE=$jrefile
45 # run the installer class file
46 echo $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
47 $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
50 cleanup()
52 if [ "x$tempdir" != "x" -a -d "$tempdir" ]; then
53 rm -rf $tempdir
57 do_exit()
59 exitstring=$errortext
60 if [ "x" != "x$errorcode" ]; then
61 exitstring="$exitstring (exit code $errorcode)"
64 # simply echo the exitstring or open a xterm
65 # -> dependent from tty
67 if tty ; then
68 echo $exitstring
69 else
70 mkdir $tempdir
72 # creating error file
73 errorfile=$tempdir/error
75 cat > $errorfile << EOF
76 echo "$exitstring"
77 echo "Press return to continue ..."
78 read a
79 EOF
81 chmod 755 $errorfile
83 # searching for xterm in path
84 xtermname="xterm"
85 xtermfound="no";
86 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
87 if [ -x "$i/$xtermname" -a ! -d "$i/$xtermname" ]; then
88 xtermname="$i/$xtermname"
89 xtermfound="yes"
90 break
92 done
94 if [ $xtermfound = "no" -a "`uname -s`" = "SunOS" ]; then
95 if [ -x /usr/openwin/bin/xterm ]; then
96 xtermname=/usr/openwin/bin/xterm
97 xtermfound="yes"
98 fi
101 if [ $xtermfound = "yes" ]; then
102 $xtermname -e $errorfile
106 cleanup
108 exit $errorcode
111 set_jre_for_uninstall()
113 # if "uninstalldata" exists, this is not required
114 if [ ! -d "uninstalldata" ]; then
115 packagepath="RPMS"
116 jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
117 jrefile=`basename $jrefile`
118 if [ -z "$jrefile" ]; then
119 jrefile="notfound"
122 # check existence of jre rpm
123 if [ ! -f $packagepath/$jrefile ]; then
124 errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
125 errorcode="4"
126 do_exit
131 install_linux_rpm()
133 # Linux requires usage of rpm2cpio to install JRE with user privileges
134 # 1. --relocate /usr/java=/var/tmp does not work, because not all files are
135 # relocatable. Some are always installed into /etc
136 # 2. --root only works with root privileges. With user privileges only the
137 # database is shifted, but not the files.
139 # On Linux currently rpm2cpio is required (and rpm anyhow)
141 find_rpm2cpio()
143 if [ ! "$rpm2cpio_found" = "yes" ]; then
144 errortext="Error: Did not find rpm2cpio. rpm2cpio is currently required for installations on Linux."
145 errorcode="11"
146 do_exit
149 find_rpm()
151 if [ ! "$rpm_found" = "yes" ]; then
152 errortext="Error: Did not find rpm. rpm is currently required for installations on Linux."
153 errorcode="12"
154 do_exit
157 # jrefile=jre-6-linux-i586.rpm
158 # javahome=usr/java/jre1.6.0
160 packagepath="RPMS"
162 # using "uninstalldata" for uninstallation
163 if [ -d "uninstalldata" ]; then
164 packagepath="uninstalldata/jre"
167 jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
168 jrefile=`basename $jrefile`
169 if [ -z "$jrefile" ]; then
170 jrefile="notfound"
173 # check existence of jre rpm
174 if [ ! -f $packagepath/$jrefile ]; then
175 errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
176 errorcode="4"
177 do_exit
180 PACKED_JARS="lib/rt.jar lib/jsse.jar lib/charsets.jar lib/ext/localedata.jar lib/plugin.jar lib/javaws.jar lib/deploy.jar"
182 mkdir $tempdir
184 trap 'rm -rf $tempdir; exit 1' HUP INT QUIT TERM
186 tempjrefile=$tempdir/$jrefile
187 cp $packagepath/$jrefile $tempjrefile
189 if [ ! -f "$tempjrefile" ]; then
190 errortext="Error: Failed to copy Java Runtime Environment (JRE) temporarily."
191 errorcode="5"
192 do_exit
195 # check if copy was successful
196 if [ -x /usr/bin/sum ]; then
198 echo "Checksumming..."
200 sumA=`/usr/bin/sum $packagepath/$jrefile`
201 index=1
202 for s in $sumA; do
203 case $index in
205 sumA1=$s;
206 index=2;
209 sumA2=$s;
210 index=3;
212 esac
213 done
215 sumB=`/usr/bin/sum $tempjrefile`
216 index=1
217 for s in $sumB; do
218 case $index in
220 sumB1=$s;
221 index=2;
224 sumB2=$s;
225 index=3;
227 esac
228 done
230 # echo "Checksum 1: A1: $sumA1 B1: $sumB1"
231 # echo "Checksum 2: A2: $sumA2 B2: $sumB2"
233 if [ $sumA1 -ne $sumB1 ] || [ $sumA2 -ne $sumB2 ]; then
234 errortext="Error: Failed to install Java Runtime Environment (JRE) temporarily."
235 errorcode="6"
236 do_exit
238 else
239 echo "Can't find /usr/bin/sum to do checksum. Continuing anyway."
242 # start to install jre
243 echo "Extracting ..."
244 olddir=`pwd`
245 cd $tempdir
246 rpm2cpio $tempjrefile | cpio -i --make-directories
247 rm -f $tempjrefile # we do not need it anymore, so conserve discspace
249 javahomeparent=usr/java
250 javahomedir=`find $javahomeparent -maxdepth 1 -type d -name "jre*" -print`
251 javahomedir=`basename $javahomedir`
252 if [ -z "$javahomedir" ]; then
253 javahomedir="notfound"
256 javahome=$javahomeparent/$javahomedir
258 if [ ! -d ${javahome} ]; then
259 errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
260 errorcode="7"
261 do_exit
264 UNPACK_EXE=$javahome/bin/unpack200
265 if [ -f $UNPACK_EXE ]; then
266 chmod +x $UNPACK_EXE
267 packerror=""
268 for i in $PACKED_JARS; do
269 if [ -f $javahome/`dirname $i`/`basename $i .jar`.pack ]; then
270 # printf "Creating %s\n" $javahome/$i
271 $UNPACK_EXE $javahome/`dirname $i`/`basename $i .jar`.pack $javahome/$i
272 if [ $? -ne 0 ] || [ ! -f $javahome/$i ]; then
273 printf "ERROR: Failed to unpack JAR file:\n\n\t%s\n\n" $i
274 printf "Installation failed. Please refer to the Troubleshooting Section of\n"
275 printf "the Installation Instructions on the download page.\n"
276 packerror="1"
277 break
280 # remove the old pack file
281 rm -f $javahome/`dirname $i`/`basename $i .jar`.pack
283 done
284 if [ "$packerror" = "1" ]; then
285 if [ -d $javahome ]; then
286 /bin/rm -rf $javahome
289 errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
290 errorcode="8"
291 do_exit
295 PREFS_LOCATION="`echo \"${javahome}\" | sed -e 's/^jdk.*/&\/jre/'`/.systemPrefs"
297 if [ ! -d "${PREFS_LOCATION}" ]; then
298 mkdir -m 755 "${PREFS_LOCATION}"
300 if [ ! -f "${PREFS_LOCATION}/.system.lock" ]; then
301 touch "${PREFS_LOCATION}/.system.lock"
302 chmod 644 "${PREFS_LOCATION}/.system.lock"
304 if [ ! -f "${PREFS_LOCATION}/.systemRootModFile" ]; then
305 touch "${PREFS_LOCATION}/.systemRootModFile"
306 chmod 644 "${PREFS_LOCATION}/.systemRootModFile"
309 if [ x$ARCH = "x32" ] && [ -f "$javahome/bin/java" ]; then
310 "$javahome/bin/java" -client -Xshare:dump > /dev/null 2>&1
313 java_runtime=$tempdir/$javahome/bin/java
315 # Make symbolic links to all TrueType font files installed in the system
316 # to avoid garbles for Japanese, Korean or Chinese
317 language=`printenv LANG | cut -c 1-3`
318 if [ x$language = "xja_" -o x$language = "xko_" -o x$language = "xzh_" ]; then
319 font_fallback_dir=$javahome/lib/fonts/fallback
320 echo "Making symbolic links to TrueType font files into $font_fallback_dir."
321 mkdir -p $font_fallback_dir
322 ttf_files=`locate "*.ttf" | xargs`
323 if [ x$ttf_files = "x" ]; then
324 ttf_files=`find /usr/share/fonts/ -name "*ttf"`
325 if [ x$ttf_files = "x" ]; then
326 ttf_files=`find /usr/X11R6/lib/ -name "*ttf"`
329 ln -s $ttf_files $font_fallback_dir
332 echo "Done."
333 cd $olddir
336 find_rpm2cpio()
338 # searching for rpm2cpio in path
339 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
340 if [ -x "$i/rpm2cpio" -a ! -d "$i/$rpm2cpio" ]; then
341 rpm2cpio_found="yes"
342 break
344 done
347 find_rpm()
349 # searching for rpm in path
350 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
351 if [ -x "$i/rpm" -a ! -d "$i/$rpm" ]; then
352 rpm_found="yes"
353 break
355 done
358 check_architecture()
360 # Check, if system and installation set fit together (x86 and sparc).
361 # If not, throw a warning.
362 # Architecture of the installation set is saved in file "installdata/xpd/setup.xpd"
363 # <architecture>sparc</architecture> or <architecture>i386</architecture>
364 # Architecture of system is determined with "uname -p"
366 setupxpdfile="installdata/xpd/setup.xpd"
368 if [ -f $setupxpdfile ]; then
369 platform=`uname -p` # valid values are "sparc" or "i386"
370 searchstring="<architecture>$platform</architecture>"
371 match=`cat $setupxpdfile | grep $searchstring`
373 if [ -z "$match" ]; then
374 # architecture does not fit, warning required
375 if [ "$platform" = "sparc" ]; then
376 echo "Warning: This is an attempt to install Solaris x86 packages on Solaris Sparc."
377 else
378 echo "Warning: This is an attempt to install Solaris Sparc packages on Solaris x86."
384 find_solaris_jre()
386 # searching for java runtime in path
387 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
388 if [ -x "$i/$java_runtime" -a ! -d "$i/$java_runtime" ]; then
389 java_runtime="$i/$java_runtime"
390 java_runtime_found="yes"
391 break
393 done
396 check_jre_version()
398 # check version of an installed JRE
399 javaoutput=`$java_runtime -version 2>&1 | tail ${tail_args} -1`
400 hotspot=`echo $javaoutput | grep $sunjavahotspot`
401 if [ ! -z "$hotspot" ]; then
402 for i in $java_versions_supported; do
403 versionmatch=`echo $javaoutput | grep $i`
404 if [ ! -z "$versionmatch" ]; then
405 java_runtime_sufficient="yes"
406 break
408 done
410 # check new version format, where version number is not part of line 3 (1.6)
411 if [ ! "$java_runtime_sufficient" = "yes" ]; then
412 javaoutput=`$java_runtime -version 2>&1 | head ${tail_args} -3`
413 for i in $java_versions_supported; do
414 versionmatch=`echo $javaoutput | grep $i`
415 if [ ! -z "$versionmatch" ]; then
416 java_runtime_sufficient="yes"
417 break
419 done
424 # the user might want to specify java runtime on the commandline
425 USAGE="Usage: $0 [ -j <java_runtime> ]"
426 while getopts hj: opt; do
427 echo "Parameter: $opt"
428 case $opt in
429 j) java_runtime_set="yes";
430 java_runtime="${OPTARG}"
431 if [ ! -f "$java_runtime" ]; then
432 errortext="Error: Invalid java runtime $java_runtime, file does not exist."
433 errorcode="2"
434 do_exit
436 if [ ! -x "$java_runtime" ]; then
437 errortext="Error: Invalid java runtime $java_runtime, not an executable file."
438 errorcode="3"
439 do_exit
441 java_runtime_found="yes";
443 h) echo ${USAGE}
444 errortext=""
445 errorcode=""
446 do_exit
448 \?) echo ${USAGE}
449 errortext=""
450 errorcode=""
451 do_exit
453 esac
454 done
456 # changing into setup directory
457 cd "`dirname "$0"`"
459 # prepare jre, if not set on command line
460 if [ "$java_runtime_set" != "yes" ]; then
461 platform=`uname -s`
462 if [ "`uname -s`" = "Linux" ]; then
463 install_linux_rpm
464 elif [ "`uname -s`" = "SunOS" ]; then
465 check_architecture
466 find_solaris_jre
467 if [ "$java_runtime_found" = "yes" ]; then
468 check_jre_version
469 if [ ! "$java_runtime_sufficient" = "yes" ]; then
470 errortext="Error: Did not find a valid Java Runtime Environment (JRE). Required JRE versions: $java_versions_supported"
471 errorcode="9"
472 do_exit
474 else
475 errortext="Error: Did not find an installed Java Runtime Environment (JRE)."
476 errorcode="10"
477 do_exit
479 else
480 errortext="Error: Platform $platform not supported for Java Runtime Environment (JRE) installation."
481 errorcode="1"
482 do_exit
486 # jre for Linux is also required, if java runtime is set (for uninstallation mode)
487 if [ "$java_runtime_set" = "yes" ]; then
488 platform=`uname -s`
489 if [ "`uname -s`" = "Linux" ]; then
490 set_jre_for_uninstall
494 start_java
496 cleanup
498 exit 0