+fail () {
+ 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: $*"
+}
+
+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
+
+yohoho="$1"; shift
+
+#---------- find ourselves ----------
+
+jpctbdir="$0"
+jpctbdir="${jpctbdir%/*}"
+
+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%/*}"
+
+# this replicates the java-searching logic from yohoho/yohoho:
+if [ -x "$yppdir/java/bin/java" ]; then
+ yppjava="$yppdir/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"
+ ypp dir: "$yppdir"
+ ypp uses: "$yppjava"
+END
+
+if ! [ -x "$yppjava" ]; then
+ nojre "bad java ypp"
+fi
+
+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
+''|/|/usr) nojre "javadir is $javadir (and even found $javadir/jre!)" ;;
+/*) ;;
+*) javadir="$PWD/$javadir" ;;
+esac
+
+jtmp="$jpctbdir/tmp"
+linkfarm="$jtmp/linkfarm"
+extdir="$jtmp/ext"