chiark / gitweb /
jpctb: Fix syntax
[jarrg-owen.git] / jpctb
diff --git a/jpctb b/jpctb
index c7bfe4b3a8c8facf18cf07d18eb87afe0208963c..f6c60e1552d879c28dceb7a34a66608ee19fc47e 100755 (executable)
--- a/jpctb
+++ b/jpctb
@@ -32,6 +32,12 @@ fail () {
        echo >&2 "jpctb: $*"
        exit 127
 }
        echo >&2 "jpctb: $*"
        exit 127
 }
+
+nojre () {
+       fail "couldn't find the right jre: $*
+ perhaps you should make ypp's java symlink (normally yohoho/java)
+ point to your jre, eg to /usr/lib/jvm/java-6-sun"
+
 badusage () {
        fail "bad usage: $*"
 }
 badusage () {
        fail "bad usage: $*"
 }
@@ -73,65 +79,50 @@ fi
 
 yppdir="${yohoho%/*}"
 
 
 yppdir="${yohoho%/*}"
 
+# this replicates the java-searching logic from yohoho/yohoho:
+if [ -x "$yohoho/java/bin/java" ]; then
+       yppjava="$yohoho/java/bin/java"
+elif [ -x "$JAVA_HOME/bin/java" ]; then
+       yppjava="$JAVA_HOME/bin/java"
+else
+       set +e
+       yppjava=`type -p java 2>&1`
+       set -e
+fi
+
 cat <<END
 jpctb:
    jpctb tree:  "$jpctbdir"
    yohoho:       "$yohoho"
 cat <<END
 jpctb:
    jpctb tree:  "$jpctbdir"
    yohoho:       "$yohoho"
+   ypp uses:     "$yppjava"
 END
 
 END
 
-if [ -x "$yppdir/java/bin/java" ]; then
-       if [ -d "$yppdir/java/jre" ]; then
-               echo "   yohoho/java/bin and yohoho/java/jre exist, good"
-               javadir="$yppdir/java"
-       else
-               absjava=`readlink -f "$yppdir/java/bin/java"`
-               cat <<END
-   yohoho/java/bin exists but yohoho/java/jre does not
-   abs. java:    "$absjava"
-END
-               case "$absjava" in
-               */jre/bin/java)
-                       echo "   found jre directory, good"
-                       javadir="${absjava%/jre/bin/java}"
-                       ;;
-               *)
-                       echo "   java binary not in jre dir as expected, hmm."
-                       ;;
-               esac
-       fi
+if ! [ -x "$yppjava" ]; then
+       nojre "bad java ypp"
 fi
 
 fi
 
-if [ "x$javadir" = x ] && [ x"$JAVA_HOME" != x ] && \
-   [ -x "$JAVA_HOME/bin/java" ]; then
-cat <<END
-   yohoho/java/bin/java nonexistent or unsuitable, trying JAVA_HOME"
-   JAVA_HOME:    "$JAVA_HOME"
-END
-       if [ -d "$JAVA_HOME/jre" ]; then
-               javadir="$JAVA_HOME"
-       else
-               echo "   JAVA_HOME has no jre subdirectory, hmm."
-       fi
-fi
-
-openjdk=/usr/lib/jvm/java-6-openjdk
-
-if [ "x$javadir" = x ] && [ -x $openjdk/bin/java ]; then
-       echo "   using openjdk, hopefully it will work with YPP!"
-       javadir=$openjdk
-fi
-
-if [ "x$javadir" = x ]; then
-       fail "could not find java runtime system
- please check that $yppdir/java points to your Java installation"
+javadir="${yppjava#/bin/java}"
+if [ -x "$javadir/jre/bin/java" ]; then
+       echo "   java/ points to the jre, good"
+else
+       echo "   java/ has just the executable bin/java, trying readlink"
+       absjava=`readlink -f "$yppjava"`
+       echo "   abs. java:    \"$absjava\""
+       case "$absjava" in
+       */jre/bin/java)
+               echo "   found jre directory, good"
+               javadir="${absjava%/jre/bin/java}"
+               ;;
+       *)
+               nojre "java binary not in jre dir"
+               ;;
+       esac
 fi
 
 case "$javadir" in
 fi
 
 case "$javadir" in
-/usr)  fail "javadir is still /usr (and even found /usr/jre!)
- please make $yppdir/java point somewhere more sensible and/or
- reinstall YPP not telling it your java is in /usr.  sorry." ;;
-/*)    ;;
-*)     javadir="$PWD/$javadir" ;;
+|/|/usr)       nojre "javadir is $javadir (and even found $javadir/jre!)" ;;
+/*)            ;;
+*)             javadir="$PWD/$javadir" ;;
 esac
 
 jtmp="$jpctbdir/tmp"
 esac
 
 jtmp="$jpctbdir/tmp"