bump product version to 4.1.6.2
[LibreOffice.git] / setup_native / scripts / javaloader.sh
blob1b20899e9f4fae5f5fb7ded52625cfba92146714
1 #!/bin/sh
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 jarfilename="JavaSetup.jar"
21 tempdir=/var/tmp/install_$$
22 java_runtime="java"
23 java_runtime_set="no"
24 java_runtime_found="no"
25 java_runtime_sufficient="no"
26 java_versions_supported="1.4 1.5 1.6"
27 rpm2cpio_found="no"
28 rpm_found="no"
29 is_64bit_arch="no"
30 arch64string="x86_64"
31 arch64string2="64-bit"
32 sunjavahotspot="HotSpot"
33 errortext=""
34 errorcode=""
36 start_java()
38 umask 022
40 echo "Using $java_runtime"
41 echo `$java_runtime -version`
42 echo "Running installer"
44 # looking for environment variables
46 home=""
47 if [ "x" != "x$HOME" ]; then
48 home=-DHOME=$HOME
51 log_module_states=""
52 if [ "x" != "x$LOG_MODULE_STATES" ]; then
53 log_module_states=-DLOG_MODULE_STATES=$LOG_MODULE_STATES
56 getuid_path=""
57 if [ "x" != "x$GETUID_PATH" ]; then
58 getuid_path=-DGETUID_PATH=$GETUID_PATH
61 if [ "x" != "x$jrefile" ]; then
62 jrecopy=-DJRE_FILE=$jrefile
65 # run the installer class file
66 echo $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
67 $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
70 cleanup()
72 if [ "x$tempdir" != "x" -a -d "$tempdir" ]; then
73 rm -rf $tempdir
77 do_exit()
79 exitstring=$errortext
80 if [ "x" != "x$errorcode" ]; then
81 exitstring="$exitstring (exit code $errorcode)"
84 # simply echo the exitstring or open a xterm
85 # -> dependent from tty
87 if tty ; then
88 echo $exitstring
89 else
90 mkdir $tempdir
92 # creating error file
93 errorfile=$tempdir/error
95 cat > $errorfile << EOF
96 echo "$exitstring"
97 echo "Press return to continue ..."
98 read a
99 EOF
101 chmod 755 $errorfile
103 # searching for xterm in path
104 xtermname="xterm"
105 xtermfound="no";
106 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
107 if [ -x "$i/$xtermname" -a ! -d "$i/$xtermname" ]; then
108 xtermname="$i/$xtermname"
109 xtermfound="yes"
110 break
112 done
114 if [ $xtermfound = "no" -a "`uname -s`" = "SunOS" ]; then
115 if [ -x /usr/openwin/bin/xterm ]; then
116 xtermname=/usr/openwin/bin/xterm
117 xtermfound="yes"
121 if [ $xtermfound = "yes" ]; then
122 $xtermname -e $errorfile
126 cleanup
128 exit $errorcode
131 set_jre_for_uninstall()
133 # if "uninstalldata" exists, this is not required
134 if [ ! -d "uninstalldata" ]; then
135 packagepath="RPMS"
136 jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
137 jrefile=`basename $jrefile`
138 if [ -z "$jrefile" ]; then
139 jrefile="notfound"
142 # check existence of jre rpm
143 if [ ! -f $packagepath/$jrefile ]; then
144 errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
145 errorcode="4"
146 do_exit
151 install_linux_rpm()
153 # Linux requires usage of rpm2cpio to install JRE with user privileges
154 # 1. --relocate /usr/java=/var/tmp does not work, because not all files are
155 # relocatable. Some are always installed into /etc
156 # 2. --root only works with root privileges. With user privileges only the
157 # database is shifted, but not the files.
159 # On Linux currently rpm2cpio is required (and rpm anyhow)
161 find_rpm2cpio()
163 if [ ! "$rpm2cpio_found" = "yes" ]; then
164 errortext="Error: Did not find rpm2cpio. rpm2cpio is currently required for installations on Linux."
165 errorcode="11"
166 do_exit
169 find_rpm()
171 if [ ! "$rpm_found" = "yes" ]; then
172 errortext="Error: Did not find rpm. rpm is currently required for installations on Linux."
173 errorcode="12"
174 do_exit
177 # jrefile=jre-6-linux-i586.rpm
178 # javahome=usr/java/jre1.6.0
180 packagepath="RPMS"
182 # using "uninstalldata" for uninstallation
183 if [ -d "uninstalldata" ]; then
184 packagepath="uninstalldata/jre"
187 jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
188 jrefile=`basename $jrefile`
189 if [ -z "$jrefile" ]; then
190 jrefile="notfound"
193 # check existence of jre rpm
194 if [ ! -f $packagepath/$jrefile ]; then
195 errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
196 errorcode="4"
197 do_exit
200 PACKED_JARS="lib/rt.jar lib/jsse.jar lib/charsets.jar lib/ext/localedata.jar lib/plugin.jar lib/javaws.jar lib/deploy.jar"
202 mkdir $tempdir
204 trap 'rm -rf $tempdir; exit 1' HUP INT QUIT TERM
206 tempjrefile=$tempdir/$jrefile
207 cp $packagepath/$jrefile $tempjrefile
209 if [ ! -f "$tempjrefile" ]; then
210 errortext="Error: Failed to copy Java Runtime Environment (JRE) temporarily."
211 errorcode="5"
212 do_exit
215 # check if copy was successful
216 if [ -x /usr/bin/sum ]; then
218 echo "Checksumming..."
220 sumA=`/usr/bin/sum $packagepath/$jrefile`
221 index=1
222 for s in $sumA; do
223 case $index in
225 sumA1=$s;
226 index=2;
229 sumA2=$s;
230 index=3;
232 esac
233 done
235 sumB=`/usr/bin/sum $tempjrefile`
236 index=1
237 for s in $sumB; do
238 case $index in
240 sumB1=$s;
241 index=2;
244 sumB2=$s;
245 index=3;
247 esac
248 done
250 # echo "Checksum 1: A1: $sumA1 B1: $sumB1"
251 # echo "Checksum 2: A2: $sumA2 B2: $sumB2"
253 if [ $sumA1 -ne $sumB1 ] || [ $sumA2 -ne $sumB2 ]; then
254 errortext="Error: Failed to install Java Runtime Environment (JRE) temporarily."
255 errorcode="6"
256 do_exit
258 else
259 echo "Can't find /usr/bin/sum to do checksum. Continuing anyway."
262 # start to install jre
263 echo "Extracting ..."
264 olddir=`pwd`
265 cd "$tempdir"
266 rpm2cpio $tempjrefile | cpio -i --make-directories
267 rm -f $tempjrefile # we do not need it anymore, so conserve discspace
269 javahomeparent=usr/java
270 javahomedir=`find $javahomeparent -maxdepth 1 -type d -name "jre*" -print`
271 javahomedir=`basename $javahomedir`
272 if [ -z "$javahomedir" ]; then
273 javahomedir="notfound"
276 javahome=$javahomeparent/$javahomedir
278 if [ ! -d ${javahome} ]; then
279 errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
280 errorcode="7"
281 do_exit
284 UNPACK_EXE=$javahome/bin/unpack200
285 if [ -f $UNPACK_EXE ]; then
286 chmod +x $UNPACK_EXE
287 packerror=""
288 for i in $PACKED_JARS; do
289 if [ -f $javahome/`dirname $i`/`basename $i .jar`.pack ]; then
290 # printf "Creating %s\n" $javahome/$i
291 $UNPACK_EXE $javahome/`dirname $i`/`basename $i .jar`.pack $javahome/$i
292 if [ $? -ne 0 ] || [ ! -f $javahome/$i ]; then
293 printf "ERROR: Failed to unpack JAR file:\n\n\t%s\n\n" $i
294 printf "Installation failed. Please refer to the Troubleshooting Section of\n"
295 printf "the Installation Instructions on the download page.\n"
296 packerror="1"
297 break
300 # remove the old pack file
301 rm -f $javahome/`dirname $i`/`basename $i .jar`.pack
303 done
304 if [ "$packerror" = "1" ]; then
305 if [ -d $javahome ]; then
306 /bin/rm -rf $javahome
309 errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
310 errorcode="8"
311 do_exit
315 PREFS_LOCATION="`echo \"${javahome}\" | sed -e 's/^jdk.*/&\/jre/'`/.systemPrefs"
317 if [ ! -d "${PREFS_LOCATION}" ]; then
318 mkdir -m 755 "${PREFS_LOCATION}"
320 if [ ! -f "${PREFS_LOCATION}/.system.lock" ]; then
321 touch "${PREFS_LOCATION}/.system.lock"
322 chmod 644 "${PREFS_LOCATION}/.system.lock"
324 if [ ! -f "${PREFS_LOCATION}/.systemRootModFile" ]; then
325 touch "${PREFS_LOCATION}/.systemRootModFile"
326 chmod 644 "${PREFS_LOCATION}/.systemRootModFile"
329 if [ x$ARCH = "x32" ] && [ -f "$javahome/bin/java" ]; then
330 "$javahome/bin/java" -client -Xshare:dump > /dev/null 2>&1
333 java_runtime=$tempdir/$javahome/bin/java
335 # Make symbolic links to all TrueType font files installed in the system
336 # to avoid garbles for Japanese, Korean or Chinese
337 language=`printenv LANG | cut -c 1-3`
338 if [ x$language = "xja_" -o x$language = "xko_" -o x$language = "xzh_" ]; then
339 font_fallback_dir=$javahome/lib/fonts/fallback
340 echo "Making symbolic links to TrueType font files into $font_fallback_dir."
341 mkdir -p $font_fallback_dir
342 ttf_files=`locate "*.ttf" | xargs`
343 if [ x$ttf_files = "x" ]; then
344 ttf_files=`find /usr/share/fonts/ -name "*ttf"`
345 if [ x$ttf_files = "x" ]; then
346 ttf_files=`find /usr/X11R6/lib/ -name "*ttf"`
349 ln -s $ttf_files $font_fallback_dir
352 echo "Done."
353 cd "$olddir"
356 find_rpm2cpio()
358 # searching for rpm2cpio in path
359 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
360 if [ -x "$i/rpm2cpio" -a ! -d "$i/$rpm2cpio" ]; then
361 rpm2cpio_found="yes"
362 break
364 done
367 find_rpm()
369 # searching for rpm in path
370 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
371 if [ -x "$i/rpm" -a ! -d "$i/$rpm" ]; then
372 rpm_found="yes"
373 break
375 done
378 check_architecture()
380 # Check, if system and installation set fit together (x86 and sparc).
381 # If not, throw a warning.
382 # Architecture of the installation set is saved in file "installdata/xpd/setup.xpd"
383 # <architecture>sparc</architecture> or <architecture>i386</architecture>
384 # Architecture of system is determined with "uname -p"
386 setupxpdfile="installdata/xpd/setup.xpd"
388 if [ -f $setupxpdfile ]; then
389 platform=`uname -p` # valid values are "sparc" or "i386"
390 searchstring="<architecture>$platform</architecture>"
391 match=`cat $setupxpdfile | grep $searchstring`
393 if [ -z "$match" ]; then
394 # architecture does not fit, warning required
395 if [ "$platform" = "sparc" ]; then
396 echo "Warning: This is an attempt to install Solaris x86 packages on Solaris Sparc."
397 else
398 echo "Warning: This is an attempt to install Solaris Sparc packages on Solaris x86."
404 find_jre_in_path()
406 # searching for java runtime in path
407 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
408 if [ -x "$i/$java_runtime" -a ! -d "$i/$java_runtime" ]; then
409 java_runtime="$i/$java_runtime"
410 java_runtime_found="yes"
411 break
413 done
416 check_jre_version()
418 # check version of an installed JRE
419 javaoutput=`$java_runtime -version 2>&1 | tail ${tail_args} -1`
420 hotspot=`echo $javaoutput | grep $sunjavahotspot`
421 if [ ! -z "$hotspot" ]; then
422 for i in $java_versions_supported; do
423 versionmatch=`echo $javaoutput | grep $i`
424 if [ ! -z "$versionmatch" ]; then
425 java_runtime_sufficient="yes"
426 break
428 done
430 # check new version format, where version number is not part of line 3 (1.6)
431 if [ ! "$java_runtime_sufficient" = "yes" ]; then
432 javaoutput=`$java_runtime -version 2>&1 | head ${tail_args} -3`
433 for i in $java_versions_supported; do
434 versionmatch=`echo $javaoutput | grep $i`
435 if [ ! -z "$versionmatch" ]; then
436 java_runtime_sufficient="yes"
437 break
439 done
444 check_linux_jre_version()
446 # check version of an installed JRE
447 javaoutput=`$java_runtime -version 2>&1 | head -1`
449 for i in $java_versions_supported; do
450 versionmatch=`echo $javaoutput | grep $i`
451 if [ ! -z "$versionmatch" ]; then
452 java_runtime_sufficient="yes"
453 break
455 done
458 check_64bit_architecture()
460 # check system architecture using "uname -m"
461 # unameoutput=`uname -m 2>&1`
462 # x64str=`echo $unameoutput | grep $arch64string`
464 # check system architecture using "file /usr/bin/file"
465 fileoutput=`file /usr/bin/file 2>&1`
466 x64str=`echo $fileoutput | grep $arch64string2`
468 if [ ! -z "$x64str" ]; then
469 is_64bit_arch="yes"
470 echo "64-bit Linux"
474 # the user might want to specify java runtime on the commandline
475 USAGE="Usage: $0 [ -j <java_runtime> ]"
476 while getopts hj: opt; do
477 echo "Parameter: $opt"
478 case $opt in
479 j) java_runtime_set="yes";
480 java_runtime="${OPTARG}"
481 if [ ! -f "$java_runtime" ]; then
482 errortext="Error: Invalid java runtime $java_runtime, file does not exist."
483 errorcode="2"
484 do_exit
486 if [ ! -x "$java_runtime" ]; then
487 errortext="Error: Invalid java runtime $java_runtime, not an executable file."
488 errorcode="3"
489 do_exit
491 java_runtime_found="yes";
493 h) echo ${USAGE}
494 errortext=""
495 errorcode=""
496 do_exit
498 \?) echo ${USAGE}
499 errortext=""
500 errorcode=""
501 do_exit
503 esac
504 done
506 # changing into setup directory
507 cd "`dirname "$0"`"
509 # prepare jre, if not set on command line
510 if [ "$java_runtime_set" != "yes" ]; then
511 platform=`uname -s`
512 if [ "`uname -s`" = "Linux" ]; then
513 check_64bit_architecture
514 if [ "$is_64bit_arch" = "no" ]; then
515 install_linux_rpm
516 else
517 find_jre_in_path
518 if [ "$java_runtime_found" = "yes" ]; then
519 check_linux_jre_version
520 if [ ! "$java_runtime_sufficient" = "yes" ]; then
521 errortext="Error: Did not find a valid Java Runtime Environment (JRE). Required JRE versions: $java_versions_supported"
522 errorcode="14"
523 do_exit
525 else
526 errortext="Error: Did not find an installed Java Runtime Environment (JRE)."
527 errorcode="15"
528 do_exit
531 elif [ "`uname -s`" = "SunOS" ]; then
532 check_architecture
533 find_jre_in_path
534 if [ "$java_runtime_found" = "yes" ]; then
535 check_jre_version
536 if [ ! "$java_runtime_sufficient" = "yes" ]; then
537 errortext="Error: Did not find a valid Java Runtime Environment (JRE). Required JRE versions: $java_versions_supported"
538 errorcode="9"
539 do_exit
541 else
542 errortext="Error: Did not find an installed Java Runtime Environment (JRE)."
543 errorcode="10"
544 do_exit
546 else
547 errortext="Error: Platform $platform not supported for Java Runtime Environment (JRE) installation."
548 errorcode="1"
549 do_exit
553 # jre for Linux is also required, if java runtime is set (for uninstallation mode)
554 if [ "$java_runtime_set" = "yes" ]; then
555 platform=`uname -s`
556 if [ "`uname -s`" = "Linux" ]; then
557 set_jre_for_uninstall
561 start_java
563 cleanup
565 exit 0