source: trunk/quest-runner/bin/run.sh @ 821

Last change on this file since 821 was 579, checked in by pharms, 12 years ago
  • initial support for building assemblies of quest including the plugins
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/bin/sh
2
3HOME_DIR=`dirname $0`
4
5# Given the "java" executable as an argument, find JAVA_HOME
6find_java() {
7  # First check if it is a JDK in the /usr/lib/jvm directory, or a symlink there.
8  # The test is somewhat complicated due to the different ways the Java implementations
9  # are set up with the alternatives system
10  # e.g.
11  #  /usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
12  # or
13  #  /usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-gcj/bin/java -> /usr/bin/gij-4.2
14
15  JAVA_HOME=$1
16  while true ; do
17    case $JAVA_HOME in
18      /usr/lib/jvm/*)
19        # Found it! Return the correct paremt directory.
20
21        JAVA_HOME=`echo $JAVA_HOME | sed 's:\(/usr/lib/jvm/[^/]*\).*:\1:'`
22        return
23        ;;
24      *) ;;
25    esac
26
27    if [ -h $JAVA_HOME ] ; then
28      JAVA_HOME=`readlink $JAVA_HOME`
29    else
30      break
31    fi
32  done
33       
34  # Not found in the Debian alternatives system, so presumably
35  # it is a user-installed JDK/JRE. Might as well be helpful
36  # and try to find JAVA_HOME.
37
38  # First try for a JDK:
39  JAVA_HOME=`readlink -e $1`
40  while [ `dirname $JAVA_HOME` != /  ]; do
41    if [ -e $JAVA_HOME/lib/tools.jar ]; then
42      return
43    fi
44
45    JAVA_HOME=`dirname $JAVA_HOME`
46  done
47
48  # If we get here we did not find a JDK. Search again for a JRE:
49  JAVA_HOME=`readlink -e $1`
50  while [ `dirname $JAVA_HOME` != /  ]; do
51    if [ -e $JAVA_HOME/bin/java ]; then
52      return
53    fi
54
55    JAVA_HOME=`dirname $JAVA_HOME`
56  done
57
58  # Nothing found; leave blank
59  JAVA_HOME=
60}
61
62if [ -z "$JAVA_HOME" ] ; then
63  if [ -r /etc/gentoo-release ] ; then
64    JAVA_HOME=`java-config --jre-home`
65  else
66    # Debian patch - search for preferred JRE
67    if [ -n "$JAVACMD" ] ; then
68      find_java "$JAVACMD"
69    else
70      find_java `which java`
71    fi
72  fi
73fi
74
75if [ -z "$JAVACMD" ] ; then
76  if [ -n "$JAVA_HOME"  ] ; then
77    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
78      # IBM's JDK on AIX uses strange locations for the executables
79      JAVACMD="$JAVA_HOME/jre/sh/java"
80    else
81      JAVACMD="$JAVA_HOME/bin/java"
82    fi
83  else
84    JAVACMD="`which java`"
85  fi
86fi
87
88if [ ! -x "$JAVACMD" ] ; then
89  echo "Error: JAVA_HOME is not defined correctly."
90  echo "  We cannot execute $JAVACMD"
91  exit 1
92fi
93
94if [ -z "$JAVA_HOME" ] ; then
95  echo "Warning: JAVA_HOME environment variable is not set."
96fi
97
98cd ${HOME_DIR}
99
100JAR_FILE=`find . -type f -name 'quest-runner-*.jar'`
101
102if [ ! -f "$JAR_FILE" ] ; then
103  echo "Error: Could not find executable jar file in distribution."
104  echo "  Execution aborted."
105  exit 1
106fi
107
108exec "$JAVACMD" -jar "${JAR_FILE}" $*
Note: See TracBrowser for help on using the repository browser.