chiark / gitweb /
pctb upload: actually look at the right XML tag for the commod maps!
[jarrg-ian.git] / jpctb
diff --git a/jpctb b/jpctb
index c55f90cbb5c6df97094c5f1062034c404070825c..50f295298b14b58b3cd688eafb23c4bef19aaaac 100755 (executable)
--- a/jpctb
+++ b/jpctb
@@ -32,10 +32,21 @@ 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: $*"
 }
 
+check_only=false
+setup_only=false
+setup_only_simulate=''
+
 while [ $# -ge 1 ]; do
        case "$1" in
        -)              shift; break;;
@@ -44,6 +55,15 @@ while [ $# -ge 1 ]; do
                        srcjardir="$1"
                        shift || badusage "--jpctb needs a value"
                        ;;
+       --check-only)
+                       check_only=true
+                       shift
+                       ;;
+       --setup-only)
+                       setup_only=true
+                       setup_only_simulate=echo
+                       shift
+                       ;;
        -*)             badusage "unknown option \`$1'"
                        ;;
        *)
@@ -73,85 +93,96 @@ fi
 
 yppdir="${yohoho%/*}"
 
-cat <<END
-jpctb:
-   jpctb tree:  "$jpctbdir"
-   yohoho:       "$yohoho"
-END
-
+# this replicates the java-searching logic from yohoho/yohoho:
 if [ -x "$yppdir/java/bin/java" ]; then
-       if [ test -d "$yppdir/java/jre" ]; then
-               echo "   yohoho/java/bin and yohoho/java/jre exist, good"
-               javadir="$yppdir/java"
-       else
-               absjava=`readlink -f "$javadir/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
+       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
 
-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"
+jpctb:
+   jpctb tree:  "$jpctbdir"
+   yohoho:       "$yohoho"
+   ypp dir:      "$yppdir"
+   ypp uses:     "$yppjava"
 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
+if ! [ -x "$yppjava" ]; then
+       nojre "bad java ypp"
 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"
+       jreleaf=jre
+else
+       echo "   java/ has just the executable bin/java, trying readlink"
+       absjava=`readlink -f "$yppjava"`
+       echo "   abs. java:    \"$absjava\""
+       case "$absjava" in
+       */*/bin/java)
+               javadir="${absjava%/bin/java}"
+               jreleaf="${javadir##*/}"
+               javadir="${javadir%/*}"
+               echo "   jre leaf dir: \"$jreleaf\""
+               case "$jreleaf" in
+               jre)    echo "   found jre directory, good";;
+               jre1.*) echo "   found versioned jre directory $jreleaf, ok";;
+               *)      nojre "java binary not in jre dir ($jreleaf)";;
+               esac
+               ;;
+       *)
+               nojre "real java binary not in ../bin/java dir";;
+       esac
 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"
 linkfarm="$jtmp/linkfarm"
 extdir="$jtmp/ext"
 
-export JPCTB_JRE="$javadir/jre"
+export JPCTB_JRE="$javadir/$jreleaf"
+realjava="$JPCTB_JRE/bin/java"
 
 #---------- confirm for the user which paths we're using ----------
 
 cat <<END
-   java:         "$javadir"
-   JRE:          "$JPCTB_JRE"
-   PCTB jars:    "$srcjardir"
+   java dir.:    "$javadir"
+   jre:          "$JPCTB_JRE"
+   primary java: "$realjava"
+   jpctb jars:   "$srcjardir"
    jpctb tmpdir: "$jtmp"
 END
 
 #---------- run the control panel ----------
 
-"$javadir/bin/java" -jar "$srcjardir/PCTB-ControlPanel.jar"
+if $check_only; then echo "Check successful."; exit 0; fi
+
+set +e
+$setup_only_simulate "$realjava" \
+ -Dcom.tedpearson.ypp.market.controlpanel.exitstatus=12 \
+ -jar "$srcjardir/PCTB-ControlPanel.jar"
+rc=$?
+set -e
+
+if $setup_only; then rc=12; fi
+
+case $rc in
+0)     echo "launcher dialogue closed, quitting"; exit 0 ;;
+12)    ;;
+*)     echo >&2 "control panel failed with exit status $rc"; exit "$rc" ;;
+esac
+
 
 #---------- create the temporary are and link farm ----------
 
@@ -159,11 +190,11 @@ 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 ----------
 
-wrapper="$linkfarm"/jre/bin/java
+wrapper="$linkfarm"/$jreleaf/bin/java
 rm -- "$wrapper"
 
 export JPCTB_EXTDIR="$extdir"
@@ -212,4 +243,4 @@ chmod +x -- "$wrapper"
 
 #---------- now run it ----------
 
-exec "$yohoho" -Djava.home="$linkfarm/jre"
+exec $setup_only_simulate "$yohoho" -Djava.home="$linkfarm/$jreleaf"