1#!/bin/sh -f 2############################################################################################################################ 3# 4# jdksetup script (to be sourced from some other 'sh' or 'bash' script) 5# 6# Searches for `java' in "standard" locations, then sets and returns ${JAVA} and ${JAVA_HOME} 7# ${JAVA} --> path to the executable 8# ${JAVA_HOME} --> path to the JDK installation 9# 10# Searches the following locations (trying in that order): 11# 12# 1. ${JAVA_HOME}/bin/java if environment variable JAVA_HOME is defined 13# 2. <mydir>/../../${JDK_OS}/jre/bin/java <mydir> is dir containing this script itself (auto detected) 14# if JDK_OS is not defined --> auto detected on-the-fly 15# if JDK_VERSION is not defined -> defaults to 'jdk-1.4' 16# 3. ${JAVA_BASE}/${JDK_OS}/jdk/${JDK_VERSION}/bin/java if JAVA_BASE is not defined -> defaults to '/home/g5/users/hoschek/java' 17# 4. java if all above fails, hoping that some 'java' is in the PATH 18# 19# author: whoschek@lbl.gov 20# version: 1.0.0 - 05 June 2003 21# changelog: no changes so far 22# 23############################################################################################################################ 24 25# detect the directory containing this file (the root of this installation) 26_MYDIR="`dirname $0`" 27#echo _MYDIR=$_MYDIR 28 29# detect operating system 30if [ -z "$JDK_OS" ] ; then 31 JDK_OS=`uname -s` > /dev/null 2>&1 32 case "$JDK_OS" in 33 Linux*) JDK_OS="i386_redhat61";; 34 SunOS*) JDK_OS="sparc_solaris26";; 35 Darwin*) JDK_OS="darwin";; 36 FreeBSD*) JDK_OS="freebsd";; 37 HP-UX*) JDK_OS="hp_ux102";; 38 AIX*) JDK_OS="rs_aix43";; 39 OSF*) JDK_OS="alpha_dux40";; 40 IRIX*) JDK_OS="sgi_64";; 41 *) JDK_OS="undefined";; 42 esac 43fi 44 45# try various paths for java installation 46 47# try this path 48jpath="/usr/j2se" 49if [ -x "$jpath/bin/java" ]; then 50 jhome=$jpath 51fi 52 53# try this path 54jpath="/afs/cern.ch/sw/java/$JDK_OS/jdk/jdk-1.5" 55if [ -x "$jpath/bin/java" ]; then 56 jhome=$jpath 57fi 58 59# try this path 60jpath="/usr/local/java2/jdk/jdk-1.5" 61if [ -x "$jpath/bin/java" ]; then 62 jhome=$jpath 63fi 64 65# try this path 66jpath="/home/dsd/java2/jdk/jdk-1.5" 67if [ -x "$jpath/bin/java" ]; then 68 jhome=$jpath 69fi 70 71# 72# if you want, add other "standard" locations here 73# 74 75# try this path 76jpath="$_MYDIR/../../$JDK_OS/jre" 77if [ -x "$jpath/bin/java" ]; then 78 jhome=$jpath 79fi 80 81# try this path 82if [ ! -z "$JAVA_HOME" ] ; then 83 jpath="$JAVA_HOME" 84 if [ -x "$jpath/bin/java" ]; then 85 jhome=$jpath 86 fi 87fi 88 89# try to find in PATH, unless already found elsewhere above 90if [ -z "$jhome" ] ; then 91 JAVA="`which java 2>&1`" 92 # strip away trailing '/bin/java' 93 jhome=`echo $JAVA | sed "s/\/bin\/java//g"` 94fi 95 96 97JAVA_HOME="$jhome" 98JAVA="$jhome/bin/java" 99 100if [ ! -x "$JAVA" ] ; then 101 echo "Cannot find or execute 'java' from $JAVA. Please check file permissions, or set your PATH or JAVA_HOME." 102 echo "(last tried JAVA=$JAVA)" 103 echo "(last tried JAVA_HOME=$JAVA_HOME)" 104 exit 1 105fi 106 107 108export JAVA 109export JAVA_HOME 110export JDK_OS 111 112#echo "javahome is $JAVA_HOME" 113