chiark / gitweb /
jpctb: More fixes for testing
[jarrg-ian.git] / jpctb
diff --git a/jpctb b/jpctb
index a2cb243e910b5754201bc56757f7b2e230e8a39a..c7bfe4b3a8c8facf18cf07d18eb87afe0208963c 100755 (executable)
--- a/jpctb
+++ b/jpctb
@@ -1,6 +1,30 @@
 #!/bin/bash -e
+
+# This is jpctb, a wrapper script for plumbing Ted Pearson's Java PCTB
+# client into a JVM on Linux.
+
+# This program is Free Software.  Copyright (C) 2009 Ian Jackson.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is fur-
+# nished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+# NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+# NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
 usage () { cat <<END
-usage: .../jpctb /path/to/dir/with/PCTB*.jar /path/to/yohoho/yohoho [...]
+usage: .../jpctb /path/to/yohoho/yohoho [...]
 END
 }
 
@@ -8,10 +32,27 @@ fail () {
        echo >&2 "jpctb: $*"
        exit 127
 }
+badusage () {
+       fail "bad usage: $*"
+}
 
-if [ $# -lt 2 ]; then usage; fail 'bad usage'; exit 127; fi
+while [ $# -ge 1 ]; do
+       case "$1" in
+       -)              shift; break;;
+       --jpctb)
+                       shift
+                       srcjardir="$1"
+                       shift || badusage "--jpctb needs a value"
+                       ;;
+       -*)             badusage "unknown option \`$1'"
+                       ;;
+       *)
+                       break
+       esac
+done
+
+if [ $# -lt 1 ]; then usage; badusage "need path to yohoho"; exit 127; fi
 
-srcjardir="$1"; shift
 yohoho="$1"; shift
 
 #---------- find ourselves ----------
@@ -24,19 +65,71 @@ case "$jpctbdir" in
 *)     jpctbdir="$PWD/$jpctbdir" ;;
 esac
 
+if [ x"$srcjardir" = x ]; then
+       srcjardir="$jpctbdir"
+fi
+
 #---------- find YPP client and the Java installation it uses ----------
 
 yppdir="${yohoho%/*}"
 
+cat <<END
+jpctb:
+   jpctb tree:  "$jpctbdir"
+   yohoho:       "$yohoho"
+END
+
 if [ -x "$yppdir/java/bin/java" ]; then
-       javadir="$yppdir/java"
-elif [ x"$JAVA_HOME" != x ] && [ -x "$JAVA_HOME/bin/java" ]; then
-       javadir="$JAVA_HOME"
-else
-       fail "could not find java runtime system"
+       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
+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"
 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" ;;
 esac
@@ -45,24 +138,28 @@ jtmp="$jpctbdir/tmp"
 linkfarm="$jtmp/linkfarm"
 extdir="$jtmp/ext"
 
+export JPCTB_JRE="$javadir/jre"
+
 #---------- confirm for the user which paths we're using ----------
 
 cat <<END
-jpctb:
-   jpctb tree:  "$jpctbdir"
-   yohoho:       "$yohoho"
    java:         "$javadir"
+   JRE:          "$JPCTB_JRE"
    PCTB jars:    "$srcjardir"
    jpctb tmpdir: "$jtmp"
 END
 
+#---------- run the control panel ----------
+
+"$javadir/bin/java" -jar "$srcjardir/PCTB-ControlPanel.jar"
+
 #---------- create the temporary are and link farm ----------
 
 rm -rf -- "$jtmp"
 mkdir -- "$jtmp" "$extdir" "$linkfarm"
 cp "$srcjardir"/PCTB*.jar "$extdir"
 
-lndir -silent "$javadir" "$linkfarm"
+cp -Rs "$javadir"/. "$linkfarm"/.
 
 #---------- edit the linkfarm to have our jvm wrapper ----------
 
@@ -70,7 +167,6 @@ wrapper="$linkfarm"/jre/bin/java
 rm -- "$wrapper"
 
 export JPCTB_EXTDIR="$extdir"
-export JPCTB_JRE="$javadir/jre"
 
 cat <<'END' >"$wrapper"
 #!/bin/bash