1cdf0e10cSrcweir#!/bin/sh
2*9f22d7c2SAndrew Rist# *************************************************************
3*9f22d7c2SAndrew Rist#
4*9f22d7c2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*9f22d7c2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*9f22d7c2SAndrew Rist#  distributed with this work for additional information
7*9f22d7c2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*9f22d7c2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*9f22d7c2SAndrew Rist#  "License"); you may not use this file except in compliance
10*9f22d7c2SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*9f22d7c2SAndrew Rist#
12*9f22d7c2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*9f22d7c2SAndrew Rist#
14*9f22d7c2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*9f22d7c2SAndrew Rist#  software distributed under the License is distributed on an
16*9f22d7c2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*9f22d7c2SAndrew Rist#  KIND, either express or implied.  See the License for the
18*9f22d7c2SAndrew Rist#  specific language governing permissions and limitations
19*9f22d7c2SAndrew Rist#  under the License.
20*9f22d7c2SAndrew Rist#
21*9f22d7c2SAndrew Rist# *************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweirjarfilename="JavaSetup.jar"
24cdf0e10cSrcweirtempdir=/var/tmp/install_$$
25cdf0e10cSrcweirjava_runtime="java"
26cdf0e10cSrcweirjava_runtime_set="no"
27cdf0e10cSrcweirjava_runtime_found="no"
28cdf0e10cSrcweirjava_runtime_sufficient="no"
29cdf0e10cSrcweirjava_versions_supported="1.4 1.5 1.6"
30cdf0e10cSrcweirrpm2cpio_found="no"
31cdf0e10cSrcweirrpm_found="no"
32638711acSEike Rathkeis_64bit_arch="no"
33638711acSEike Rathkearch64string="x86_64"
34638711acSEike Rathkearch64string2="64-bit"
35cdf0e10cSrcweirsunjavahotspot="HotSpot"
36cdf0e10cSrcweirerrortext=""
37cdf0e10cSrcweirerrorcode=""
38cdf0e10cSrcweir
39cdf0e10cSrcweirstart_java()
40cdf0e10cSrcweir{
41cdf0e10cSrcweir    umask 022
42cdf0e10cSrcweir
43cdf0e10cSrcweir    echo "Using $java_runtime"
44cdf0e10cSrcweir    echo `$java_runtime -version`
45cdf0e10cSrcweir    echo "Running installer"
46cdf0e10cSrcweir
47cdf0e10cSrcweir    # looking for environment variables
48cdf0e10cSrcweir
49cdf0e10cSrcweir    home=""
50cdf0e10cSrcweir    if [ "x" != "x$HOME" ]; then
51cdf0e10cSrcweir        home=-DHOME=$HOME
52cdf0e10cSrcweir    fi
53cdf0e10cSrcweir
54cdf0e10cSrcweir    log_module_states=""
55cdf0e10cSrcweir    if [ "x" != "x$LOG_MODULE_STATES" ]; then
56cdf0e10cSrcweir        log_module_states=-DLOG_MODULE_STATES=$LOG_MODULE_STATES
57cdf0e10cSrcweir    fi
58cdf0e10cSrcweir
59cdf0e10cSrcweir    getuid_path=""
60cdf0e10cSrcweir    if [ "x" != "x$GETUID_PATH" ]; then
61cdf0e10cSrcweir        getuid_path=-DGETUID_PATH=$GETUID_PATH
62cdf0e10cSrcweir    fi
63cdf0e10cSrcweir
64cdf0e10cSrcweir    if [ "x" != "x$jrefile" ]; then
65cdf0e10cSrcweir        jrecopy=-DJRE_FILE=$jrefile
66cdf0e10cSrcweir    fi
67cdf0e10cSrcweir
68cdf0e10cSrcweir    # run the installer class file
69cdf0e10cSrcweir    echo $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
70cdf0e10cSrcweir    $java_runtime $home $log_module_states $getuid_path $jrecopy -jar $jarfilename
71cdf0e10cSrcweir}
72cdf0e10cSrcweir
73cdf0e10cSrcweircleanup()
74cdf0e10cSrcweir{
75cdf0e10cSrcweir    if [ "x$tempdir" != "x" -a -d "$tempdir" ]; then
76cdf0e10cSrcweir        rm -rf $tempdir
77cdf0e10cSrcweir    fi
78cdf0e10cSrcweir}
79cdf0e10cSrcweir
80cdf0e10cSrcweirdo_exit()
81cdf0e10cSrcweir{
82cdf0e10cSrcweir    exitstring=$errortext
83cdf0e10cSrcweir    if [ "x" != "x$errorcode" ]; then
84cdf0e10cSrcweir        exitstring="$exitstring (exit code $errorcode)"
85cdf0e10cSrcweir    fi
86cdf0e10cSrcweir
87cdf0e10cSrcweir    # simply echo the exitstring or open a xterm
88cdf0e10cSrcweir    # -> dependent from tty
89cdf0e10cSrcweir
90cdf0e10cSrcweir    if tty ; then
91cdf0e10cSrcweir        echo $exitstring
92cdf0e10cSrcweir    else
93cdf0e10cSrcweir        mkdir $tempdir
94cdf0e10cSrcweir
95cdf0e10cSrcweir        # creating error file
96cdf0e10cSrcweir        errorfile=$tempdir/error
97cdf0e10cSrcweir
98cdf0e10cSrcweir        cat > $errorfile << EOF
99cdf0e10cSrcweirecho "$exitstring"
100cdf0e10cSrcweirecho "Press return to continue ..."
101cdf0e10cSrcweirread a
102cdf0e10cSrcweirEOF
103cdf0e10cSrcweir
104cdf0e10cSrcweir        chmod 755 $errorfile
105cdf0e10cSrcweir
106cdf0e10cSrcweir        # searching for xterm in path
107cdf0e10cSrcweir        xtermname="xterm"
108cdf0e10cSrcweir        xtermfound="no";
109cdf0e10cSrcweir        for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
110cdf0e10cSrcweir            if [ -x "$i/$xtermname" -a ! -d "$i/$xtermname" ]; then
111cdf0e10cSrcweir                xtermname="$i/$xtermname"
112cdf0e10cSrcweir                xtermfound="yes"
113cdf0e10cSrcweir                break
114cdf0e10cSrcweir            fi
115cdf0e10cSrcweir        done
116cdf0e10cSrcweir
117cdf0e10cSrcweir        if [ $xtermfound = "no" -a "`uname -s`" = "SunOS" ]; then
118cdf0e10cSrcweir            if [ -x /usr/openwin/bin/xterm ]; then
119cdf0e10cSrcweir                xtermname=/usr/openwin/bin/xterm
120cdf0e10cSrcweir                xtermfound="yes"
121cdf0e10cSrcweir            fi
122cdf0e10cSrcweir        fi
123cdf0e10cSrcweir
124cdf0e10cSrcweir        if [ $xtermfound = "yes" ]; then
125cdf0e10cSrcweir            $xtermname -e $errorfile
126cdf0e10cSrcweir        fi
127cdf0e10cSrcweir    fi
128cdf0e10cSrcweir
129cdf0e10cSrcweir    cleanup
130cdf0e10cSrcweir
131cdf0e10cSrcweir    exit $errorcode
132cdf0e10cSrcweir}
133cdf0e10cSrcweir
134cdf0e10cSrcweirset_jre_for_uninstall()
135cdf0e10cSrcweir{
136cdf0e10cSrcweir    # if "uninstalldata" exists, this is not required
137cdf0e10cSrcweir    if [ ! -d "uninstalldata" ]; then
138cdf0e10cSrcweir        packagepath="RPMS"
139cdf0e10cSrcweir        jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
140cdf0e10cSrcweir        jrefile=`basename $jrefile`
141cdf0e10cSrcweir        if [ -z "$jrefile" ]; then
142cdf0e10cSrcweir            jrefile="notfound"
143cdf0e10cSrcweir        fi
144cdf0e10cSrcweir
145cdf0e10cSrcweir        # check existence of jre rpm
146cdf0e10cSrcweir        if [ ! -f $packagepath/$jrefile ]; then
147cdf0e10cSrcweir            errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
148cdf0e10cSrcweir            errorcode="4"
149cdf0e10cSrcweir            do_exit
150cdf0e10cSrcweir        fi
151cdf0e10cSrcweir    fi
152cdf0e10cSrcweir}
153cdf0e10cSrcweir
154cdf0e10cSrcweirinstall_linux_rpm()
155cdf0e10cSrcweir{
156cdf0e10cSrcweir    # Linux requires usage of rpm2cpio to install JRE with user privileges
157cdf0e10cSrcweir    # 1. --relocate /usr/java=/var/tmp does not work, because not all files are
158cdf0e10cSrcweir    #    relocatable. Some are always installed into /etc
159cdf0e10cSrcweir    # 2. --root only works with root privileges. With user privileges only the
160cdf0e10cSrcweir    #    database is shifted, but not the files.
161cdf0e10cSrcweir
162cdf0e10cSrcweir    # On Linux currently rpm2cpio is required (and rpm anyhow)
163cdf0e10cSrcweir
164cdf0e10cSrcweir    find_rpm2cpio()
165cdf0e10cSrcweir
166cdf0e10cSrcweir    if [ ! "$rpm2cpio_found" = "yes" ]; then
167cdf0e10cSrcweir        errortext="Error: Did not find rpm2cpio. rpm2cpio is currently required for installations on Linux."
168cdf0e10cSrcweir        errorcode="11"
169cdf0e10cSrcweir        do_exit
170cdf0e10cSrcweir    fi
171cdf0e10cSrcweir
172cdf0e10cSrcweir    find_rpm()
173cdf0e10cSrcweir
174cdf0e10cSrcweir    if [ ! "$rpm_found" = "yes" ]; then
175cdf0e10cSrcweir        errortext="Error: Did not find rpm. rpm is currently required for installations on Linux."
176cdf0e10cSrcweir        errorcode="12"
177cdf0e10cSrcweir        do_exit
178cdf0e10cSrcweir    fi
179cdf0e10cSrcweir
180cdf0e10cSrcweir    # jrefile=jre-6-linux-i586.rpm
181cdf0e10cSrcweir    # javahome=usr/java/jre1.6.0
182cdf0e10cSrcweir
183cdf0e10cSrcweir    packagepath="RPMS"
184cdf0e10cSrcweir
185cdf0e10cSrcweir    # using "uninstalldata" for uninstallation
186cdf0e10cSrcweir    if [ -d "uninstalldata" ]; then
187cdf0e10cSrcweir        packagepath="uninstalldata/jre"
188cdf0e10cSrcweir    fi
189cdf0e10cSrcweir
190cdf0e10cSrcweir    jrefile=`find $packagepath -type f -name "jre*.rpm" -print`
191cdf0e10cSrcweir    jrefile=`basename $jrefile`
192cdf0e10cSrcweir    if [ -z "$jrefile" ]; then
193cdf0e10cSrcweir        jrefile="notfound"
194cdf0e10cSrcweir    fi
195cdf0e10cSrcweir
196cdf0e10cSrcweir    # check existence of jre rpm
197cdf0e10cSrcweir    if [ ! -f $packagepath/$jrefile ]; then
198cdf0e10cSrcweir        errortext="Error: Java Runtime Environment (JRE) not found in directory: $packagepath"
199cdf0e10cSrcweir        errorcode="4"
200cdf0e10cSrcweir        do_exit
201cdf0e10cSrcweir    fi
202cdf0e10cSrcweir
203cdf0e10cSrcweir    PACKED_JARS="lib/rt.jar lib/jsse.jar lib/charsets.jar  lib/ext/localedata.jar lib/plugin.jar lib/javaws.jar lib/deploy.jar"
204cdf0e10cSrcweir
205cdf0e10cSrcweir    mkdir $tempdir
206cdf0e10cSrcweir
207cdf0e10cSrcweir    trap 'rm -rf $tempdir; exit 1' HUP INT QUIT TERM
208cdf0e10cSrcweir
209cdf0e10cSrcweir    tempjrefile=$tempdir/$jrefile
210cdf0e10cSrcweir    cp $packagepath/$jrefile $tempjrefile
211cdf0e10cSrcweir
212cdf0e10cSrcweir    if [ ! -f "$tempjrefile" ]; then
213cdf0e10cSrcweir        errortext="Error: Failed to copy Java Runtime Environment (JRE) temporarily."
214cdf0e10cSrcweir        errorcode="5"
215cdf0e10cSrcweir        do_exit
216cdf0e10cSrcweir    fi
217cdf0e10cSrcweir
218cdf0e10cSrcweir    # check if copy was successful
219cdf0e10cSrcweir    if [ -x /usr/bin/sum ]; then
220cdf0e10cSrcweir
221cdf0e10cSrcweir        echo "Checksumming..."
222cdf0e10cSrcweir
223cdf0e10cSrcweir        sumA=`/usr/bin/sum $packagepath/$jrefile`
224cdf0e10cSrcweir        index=1
225cdf0e10cSrcweir        for s in $sumA; do
226cdf0e10cSrcweir            case $index in
227cdf0e10cSrcweir                1)
228cdf0e10cSrcweir                    sumA1=$s;
229cdf0e10cSrcweir                    index=2;
230cdf0e10cSrcweir                    ;;
231cdf0e10cSrcweir                2)
232cdf0e10cSrcweir                    sumA2=$s;
233cdf0e10cSrcweir                    index=3;
234cdf0e10cSrcweir                    ;;
235cdf0e10cSrcweir            esac
236cdf0e10cSrcweir        done
237cdf0e10cSrcweir
238cdf0e10cSrcweir        sumB=`/usr/bin/sum $tempjrefile`
239cdf0e10cSrcweir        index=1
240cdf0e10cSrcweir        for s in $sumB; do
241cdf0e10cSrcweir            case $index in
242cdf0e10cSrcweir                1)
243cdf0e10cSrcweir                    sumB1=$s;
244cdf0e10cSrcweir                    index=2;
245cdf0e10cSrcweir                    ;;
246cdf0e10cSrcweir                2)
247cdf0e10cSrcweir                    sumB2=$s;
248cdf0e10cSrcweir                    index=3;
249cdf0e10cSrcweir                    ;;
250cdf0e10cSrcweir            esac
251cdf0e10cSrcweir        done
252cdf0e10cSrcweir
253cdf0e10cSrcweir        # echo "Checksum 1: A1: $sumA1 B1: $sumB1"
254cdf0e10cSrcweir        # echo "Checksum 2: A2: $sumA2 B2: $sumB2"
255cdf0e10cSrcweir
256cdf0e10cSrcweir        if [ $sumA1 -ne $sumB1 ] || [ $sumA2 -ne $sumB2 ]; then
257cdf0e10cSrcweir            errortext="Error: Failed to install Java Runtime Environment (JRE) temporarily."
258cdf0e10cSrcweir            errorcode="6"
259cdf0e10cSrcweir            do_exit
260cdf0e10cSrcweir        fi
261cdf0e10cSrcweir    else
262cdf0e10cSrcweir        echo "Can't find /usr/bin/sum to do checksum. Continuing anyway."
263cdf0e10cSrcweir    fi
264cdf0e10cSrcweir
265cdf0e10cSrcweir    # start to install jre
266cdf0e10cSrcweir    echo "Extracting ..."
267cdf0e10cSrcweir    olddir=`pwd`
268cdf0e10cSrcweir    cd "$tempdir"
269cdf0e10cSrcweir    rpm2cpio $tempjrefile | cpio -i --make-directories
270cdf0e10cSrcweir    rm -f $tempjrefile # we do not need it anymore, so conserve discspace
271cdf0e10cSrcweir
272cdf0e10cSrcweir    javahomeparent=usr/java
273cdf0e10cSrcweir    javahomedir=`find $javahomeparent -maxdepth 1 -type d -name "jre*" -print`
274cdf0e10cSrcweir    javahomedir=`basename $javahomedir`
275cdf0e10cSrcweir    if [ -z "$javahomedir" ]; then
276cdf0e10cSrcweir        javahomedir="notfound"
277cdf0e10cSrcweir    fi
278cdf0e10cSrcweir
279cdf0e10cSrcweir    javahome=$javahomeparent/$javahomedir
280cdf0e10cSrcweir
281cdf0e10cSrcweir    if [ ! -d ${javahome} ]; then
282cdf0e10cSrcweir        errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
283cdf0e10cSrcweir        errorcode="7"
284cdf0e10cSrcweir        do_exit
285cdf0e10cSrcweir    fi
286cdf0e10cSrcweir
287cdf0e10cSrcweir    UNPACK_EXE=$javahome/bin/unpack200
288cdf0e10cSrcweir    if [ -f $UNPACK_EXE ]; then
289cdf0e10cSrcweir        chmod +x $UNPACK_EXE
290cdf0e10cSrcweir        packerror=""
291cdf0e10cSrcweir        for i in $PACKED_JARS; do
292cdf0e10cSrcweir            if [ -f $javahome/`dirname $i`/`basename $i .jar`.pack ]; then
293cdf0e10cSrcweir                # printf "Creating %s\n" $javahome/$i
294cdf0e10cSrcweir                $UNPACK_EXE $javahome/`dirname $i`/`basename $i .jar`.pack $javahome/$i
295cdf0e10cSrcweir                if [ $? -ne 0 ] || [ ! -f $javahome/$i ]; then
296cdf0e10cSrcweir                    printf "ERROR: Failed to unpack JAR file:\n\n\t%s\n\n" $i
297cdf0e10cSrcweir                    printf "Installation failed. Please refer to the Troubleshooting Section of\n"
298cdf0e10cSrcweir                    printf "the Installation Instructions on the download page.\n"
299cdf0e10cSrcweir                    packerror="1"
300cdf0e10cSrcweir                    break
301cdf0e10cSrcweir                fi
302cdf0e10cSrcweir
303cdf0e10cSrcweir                # remove the old pack file
304cdf0e10cSrcweir                rm -f $javahome/`dirname $i`/`basename $i .jar`.pack
305cdf0e10cSrcweir            fi
306cdf0e10cSrcweir        done
307cdf0e10cSrcweir        if [  "$packerror" = "1" ]; then
308cdf0e10cSrcweir            if [ -d $javahome ]; then
309cdf0e10cSrcweir                /bin/rm -rf $javahome
310cdf0e10cSrcweir            fi
311cdf0e10cSrcweir
312cdf0e10cSrcweir            errortext="Error: Failed to extract the Java Runtime Environment (JRE) files."
313cdf0e10cSrcweir            errorcode="8"
314cdf0e10cSrcweir            do_exit
315cdf0e10cSrcweir        fi
316cdf0e10cSrcweir    fi
317cdf0e10cSrcweir
318cdf0e10cSrcweir    PREFS_LOCATION="`echo \"${javahome}\" | sed -e 's/^jdk.*/&\/jre/'`/.systemPrefs"
319cdf0e10cSrcweir
320cdf0e10cSrcweir    if [ ! -d "${PREFS_LOCATION}" ]; then
321cdf0e10cSrcweir        mkdir -m 755 "${PREFS_LOCATION}"
322cdf0e10cSrcweir    fi
323cdf0e10cSrcweir    if [ ! -f "${PREFS_LOCATION}/.system.lock" ]; then
324cdf0e10cSrcweir        touch "${PREFS_LOCATION}/.system.lock"
325cdf0e10cSrcweir        chmod 644 "${PREFS_LOCATION}/.system.lock"
326cdf0e10cSrcweir    fi
327cdf0e10cSrcweir    if [ ! -f "${PREFS_LOCATION}/.systemRootModFile" ]; then
328cdf0e10cSrcweir        touch "${PREFS_LOCATION}/.systemRootModFile"
329cdf0e10cSrcweir        chmod 644 "${PREFS_LOCATION}/.systemRootModFile"
330cdf0e10cSrcweir    fi
331cdf0e10cSrcweir
332cdf0e10cSrcweir    if [ x$ARCH = "x32" ] && [ -f "$javahome/bin/java" ]; then
333cdf0e10cSrcweir        "$javahome/bin/java" -client -Xshare:dump > /dev/null 2>&1
334cdf0e10cSrcweir    fi
335cdf0e10cSrcweir
336cdf0e10cSrcweir    java_runtime=$tempdir/$javahome/bin/java
337cdf0e10cSrcweir
338cdf0e10cSrcweir    # Make symbolic links to all TrueType font files installed in the system
339cdf0e10cSrcweir    # to avoid garbles for Japanese, Korean or Chinese
340cdf0e10cSrcweir    language=`printenv LANG | cut -c 1-3`
341cdf0e10cSrcweir    if [ x$language = "xja_" -o x$language = "xko_" -o x$language = "xzh_" ]; then
342cdf0e10cSrcweir	    font_fallback_dir=$javahome/lib/fonts/fallback
343cdf0e10cSrcweir	    echo "Making symbolic links to TrueType font files into $font_fallback_dir."
344cdf0e10cSrcweir	    mkdir -p $font_fallback_dir
345cdf0e10cSrcweir	    ttf_files=`locate "*.ttf" | xargs`
346cdf0e10cSrcweir        if [ x$ttf_files = "x" ]; then
347cdf0e10cSrcweir            ttf_files=`find /usr/share/fonts/ -name "*ttf"`
348cdf0e10cSrcweir            if [ x$ttf_files = "x" ]; then
349cdf0e10cSrcweir                ttf_files=`find /usr/X11R6/lib/ -name "*ttf"`
350cdf0e10cSrcweir            fi
351cdf0e10cSrcweir        fi
352cdf0e10cSrcweir	    ln -s $ttf_files $font_fallback_dir
353cdf0e10cSrcweir    fi
354cdf0e10cSrcweir
355cdf0e10cSrcweir    echo "Done."
356cdf0e10cSrcweir    cd "$olddir"
357cdf0e10cSrcweir}
358cdf0e10cSrcweir
359cdf0e10cSrcweirfind_rpm2cpio()
360cdf0e10cSrcweir{
361cdf0e10cSrcweir    # searching for rpm2cpio in path
362cdf0e10cSrcweir    for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
363cdf0e10cSrcweir        if [ -x "$i/rpm2cpio" -a ! -d "$i/$rpm2cpio" ]; then
364cdf0e10cSrcweir            rpm2cpio_found="yes"
365cdf0e10cSrcweir            break
366cdf0e10cSrcweir        fi
367cdf0e10cSrcweir    done
368cdf0e10cSrcweir}
369cdf0e10cSrcweir
370cdf0e10cSrcweirfind_rpm()
371cdf0e10cSrcweir{
372cdf0e10cSrcweir    # searching for rpm in path
373cdf0e10cSrcweir    for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
374cdf0e10cSrcweir        if [ -x "$i/rpm" -a ! -d "$i/$rpm" ]; then
375cdf0e10cSrcweir            rpm_found="yes"
376cdf0e10cSrcweir            break
377cdf0e10cSrcweir        fi
378cdf0e10cSrcweir    done
379cdf0e10cSrcweir}
380cdf0e10cSrcweir
381cdf0e10cSrcweircheck_architecture()
382cdf0e10cSrcweir{
383cdf0e10cSrcweir    # Check, if system and installation set fit together (x86 and sparc).
384cdf0e10cSrcweir    # If not, throw a warning.
385cdf0e10cSrcweir    # Architecture of the installation set is saved in file "installdata/xpd/setup.xpd"
386cdf0e10cSrcweir    # <architecture>sparc</architecture> or <architecture>i386</architecture>
387cdf0e10cSrcweir    # Architecture of system is determined with "uname -p"
388cdf0e10cSrcweir
389cdf0e10cSrcweir    setupxpdfile="installdata/xpd/setup.xpd"
390cdf0e10cSrcweir
391cdf0e10cSrcweir    if [ -f $setupxpdfile ]; then
392cdf0e10cSrcweir        platform=`uname -p`	# valid values are "sparc" or "i386"
393cdf0e10cSrcweir        searchstring="<architecture>$platform</architecture>"
394cdf0e10cSrcweir        match=`cat $setupxpdfile | grep $searchstring`
395cdf0e10cSrcweir
396cdf0e10cSrcweir        if [ -z "$match" ]; then
397cdf0e10cSrcweir            # architecture does not fit, warning required
398cdf0e10cSrcweir            if [ "$platform" = "sparc" ]; then
399cdf0e10cSrcweir                echo "Warning: This is an attempt to install Solaris x86 packages on Solaris Sparc."
400cdf0e10cSrcweir            else
401cdf0e10cSrcweir                echo "Warning: This is an attempt to install Solaris Sparc packages on Solaris x86."
402cdf0e10cSrcweir            fi
403cdf0e10cSrcweir        fi
404cdf0e10cSrcweir    fi
405cdf0e10cSrcweir}
406cdf0e10cSrcweir
407638711acSEike Rathkefind_jre_in_path()
408cdf0e10cSrcweir{
409cdf0e10cSrcweir    # searching for java runtime in path
410cdf0e10cSrcweir    for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
411cdf0e10cSrcweir        if [ -x "$i/$java_runtime" -a ! -d "$i/$java_runtime" ]; then
412cdf0e10cSrcweir            java_runtime="$i/$java_runtime"
413cdf0e10cSrcweir            java_runtime_found="yes"
414cdf0e10cSrcweir            break
415cdf0e10cSrcweir        fi
416cdf0e10cSrcweir    done
417cdf0e10cSrcweir}
418cdf0e10cSrcweir
419cdf0e10cSrcweircheck_jre_version()
420cdf0e10cSrcweir{
421cdf0e10cSrcweir    # check version of an installed JRE
422cdf0e10cSrcweir    javaoutput=`$java_runtime -version 2>&1 | tail ${tail_args} -1`
423cdf0e10cSrcweir    hotspot=`echo $javaoutput | grep $sunjavahotspot`
424cdf0e10cSrcweir    if [ ! -z "$hotspot" ]; then
425cdf0e10cSrcweir        for i in $java_versions_supported; do
426cdf0e10cSrcweir            versionmatch=`echo $javaoutput | grep $i`
427cdf0e10cSrcweir            if [ ! -z "$versionmatch" ]; then
428cdf0e10cSrcweir                java_runtime_sufficient="yes"
429cdf0e10cSrcweir                break
430cdf0e10cSrcweir            fi
431cdf0e10cSrcweir        done
432cdf0e10cSrcweir
433cdf0e10cSrcweir        # check new version format, where version number is not part of line 3 (1.6)
434cdf0e10cSrcweir        if [ ! "$java_runtime_sufficient" = "yes" ]; then
435cdf0e10cSrcweir            javaoutput=`$java_runtime -version 2>&1 | head ${tail_args} -3`
436cdf0e10cSrcweir            for i in $java_versions_supported; do
437cdf0e10cSrcweir                versionmatch=`echo $javaoutput | grep $i`
438cdf0e10cSrcweir                if [ ! -z "$versionmatch" ]; then
439cdf0e10cSrcweir                    java_runtime_sufficient="yes"
440cdf0e10cSrcweir                    break
441cdf0e10cSrcweir                fi
442cdf0e10cSrcweir            done
443cdf0e10cSrcweir        fi
444cdf0e10cSrcweir    fi
445cdf0e10cSrcweir}
446cdf0e10cSrcweir
447638711acSEike Rathkecheck_linux_jre_version()
448638711acSEike Rathke{
449638711acSEike Rathke    # check version of an installed JRE
450638711acSEike Rathke    javaoutput=`$java_runtime -version 2>&1 | head -1`
451638711acSEike Rathke
452638711acSEike Rathke    for i in $java_versions_supported; do
453638711acSEike Rathke        versionmatch=`echo $javaoutput | grep $i`
454638711acSEike Rathke        if [ ! -z "$versionmatch" ]; then
455638711acSEike Rathke            java_runtime_sufficient="yes"
456638711acSEike Rathke            break
457638711acSEike Rathke        fi
458638711acSEike Rathke    done
459638711acSEike Rathke}
460638711acSEike Rathke
461638711acSEike Rathkecheck_64bit_architecture()
462638711acSEike Rathke{
463638711acSEike Rathke    # check system architecture using "uname -m"
464638711acSEike Rathke    # unameoutput=`uname -m 2>&1`
465638711acSEike Rathke    # x64str=`echo $unameoutput | grep $arch64string`
466638711acSEike Rathke
467638711acSEike Rathke    # check system architecture using "file /usr/bin/file"
468638711acSEike Rathke    fileoutput=`file /usr/bin/file 2>&1`
469638711acSEike Rathke    x64str=`echo $fileoutput | grep $arch64string2`
470638711acSEike Rathke
471638711acSEike Rathke    if [ ! -z "$x64str" ]; then
472638711acSEike Rathke        is_64bit_arch="yes"
473638711acSEike Rathke        echo "64-bit Linux"
474638711acSEike Rathke    fi
475638711acSEike Rathke}
476638711acSEike Rathke
477cdf0e10cSrcweir# the user might want to specify java runtime on the commandline
478cdf0e10cSrcweirUSAGE="Usage: $0 [ -j <java_runtime> ]"
479cdf0e10cSrcweirwhile getopts hj: opt; do
480cdf0e10cSrcweir    echo "Parameter: $opt"
481cdf0e10cSrcweir    case $opt in
482cdf0e10cSrcweir        j)  java_runtime_set="yes";
483cdf0e10cSrcweir            java_runtime="${OPTARG}"
484cdf0e10cSrcweir            if [ ! -f "$java_runtime" ]; then
485cdf0e10cSrcweir                errortext="Error: Invalid java runtime $java_runtime, file does not exist."
486cdf0e10cSrcweir                errorcode="2"
487cdf0e10cSrcweir                do_exit
488cdf0e10cSrcweir            fi
489cdf0e10cSrcweir            if [ ! -x "$java_runtime" ]; then
490cdf0e10cSrcweir                errortext="Error: Invalid java runtime $java_runtime, not an executable file."
491cdf0e10cSrcweir                errorcode="3"
492cdf0e10cSrcweir                do_exit
493cdf0e10cSrcweir            fi
494cdf0e10cSrcweir            java_runtime_found="yes";
495cdf0e10cSrcweir            ;;
496cdf0e10cSrcweir        h)  echo ${USAGE}
497cdf0e10cSrcweir            errortext=""
498cdf0e10cSrcweir            errorcode=""
499cdf0e10cSrcweir            do_exit
500cdf0e10cSrcweir            ;;
501cdf0e10cSrcweir        \?) echo ${USAGE}
502cdf0e10cSrcweir            errortext=""
503cdf0e10cSrcweir            errorcode=""
504cdf0e10cSrcweir            do_exit
505cdf0e10cSrcweir            ;;
506cdf0e10cSrcweir    esac
507cdf0e10cSrcweirdone
508cdf0e10cSrcweir
509cdf0e10cSrcweir# changing into setup directory
510cdf0e10cSrcweircd "`dirname "$0"`"
511cdf0e10cSrcweir
512cdf0e10cSrcweir# prepare jre, if not set on command line
513cdf0e10cSrcweirif [ "$java_runtime_set" != "yes" ]; then
514cdf0e10cSrcweir    platform=`uname -s`
515cdf0e10cSrcweir    if [ "`uname -s`" = "Linux" ]; then
516638711acSEike Rathke        check_64bit_architecture
517638711acSEike Rathke        if [ "$is_64bit_arch" = "no" ]; then
518638711acSEike Rathke            install_linux_rpm
519638711acSEike Rathke        else
520638711acSEike Rathke            find_jre_in_path
521638711acSEike Rathke            if [ "$java_runtime_found" = "yes" ]; then
522638711acSEike Rathke                check_linux_jre_version
523638711acSEike Rathke                if [ ! "$java_runtime_sufficient" = "yes" ]; then
524638711acSEike Rathke                    errortext="Error: Did not find a valid Java Runtime Environment (JRE). Required JRE versions: $java_versions_supported"
525638711acSEike Rathke                    errorcode="14"
526638711acSEike Rathke                    do_exit
527638711acSEike Rathke                fi
528638711acSEike Rathke            else
529638711acSEike Rathke                errortext="Error: Did not find an installed Java Runtime Environment (JRE)."
530638711acSEike Rathke                errorcode="15"
531638711acSEike Rathke                do_exit
532638711acSEike Rathke            fi
533638711acSEike Rathke        fi
534cdf0e10cSrcweir    elif [ "`uname -s`" = "SunOS" ]; then
535cdf0e10cSrcweir        check_architecture
536638711acSEike Rathke        find_jre_in_path
537cdf0e10cSrcweir        if [ "$java_runtime_found" = "yes" ]; then
538cdf0e10cSrcweir            check_jre_version
539cdf0e10cSrcweir            if [ ! "$java_runtime_sufficient" = "yes" ]; then
540cdf0e10cSrcweir                errortext="Error: Did not find a valid Java Runtime Environment (JRE). Required JRE versions: $java_versions_supported"
541cdf0e10cSrcweir                errorcode="9"
542cdf0e10cSrcweir                do_exit
543cdf0e10cSrcweir            fi
544cdf0e10cSrcweir        else
545cdf0e10cSrcweir            errortext="Error: Did not find an installed Java Runtime Environment (JRE)."
546cdf0e10cSrcweir            errorcode="10"
547cdf0e10cSrcweir            do_exit
548cdf0e10cSrcweir        fi
549cdf0e10cSrcweir    else
550cdf0e10cSrcweir        errortext="Error: Platform $platform not supported for Java Runtime Environment (JRE) installation."
551cdf0e10cSrcweir        errorcode="1"
552cdf0e10cSrcweir        do_exit
553cdf0e10cSrcweir    fi
554cdf0e10cSrcweirfi
555cdf0e10cSrcweir
556cdf0e10cSrcweir# jre for Linux is also required, if java runtime is set (for uninstallation mode)
557cdf0e10cSrcweirif [ "$java_runtime_set" = "yes" ]; then
558cdf0e10cSrcweir    platform=`uname -s`
559cdf0e10cSrcweir    if [ "`uname -s`" = "Linux" ]; then
560cdf0e10cSrcweir        set_jre_for_uninstall
561cdf0e10cSrcweir    fi
562cdf0e10cSrcweirfi
563cdf0e10cSrcweir
564cdf0e10cSrcweirstart_java
565cdf0e10cSrcweir
566cdf0e10cSrcweircleanup
567cdf0e10cSrcweir
568cdf0e10cSrcweirexit 0
569