chiark / gitweb /
new wrapper script actually works
[jarrg-ian.git] / jpctb
1 #!/bin/bash -e
2 usage () { cat <<END
3 usage: .../jpctb /path/to/dir/with/PCTB*.jar /path/to/yohoho/yohoho [...]
4 END
5 }
6
7 fail () {
8         echo >&2 "jpctb: $*"
9         exit 127
10 }
11
12 if [ $# -lt 2 ]; then usage; fail 'bad usage'; exit 127; fi
13
14 srcjardir="$1"; shift
15 yohoho="$1"; shift
16
17 #---------- find ourselves ----------
18
19 jpctbdir="$0"
20 jpctbdir="${jpctbdir%/*}"
21
22 case "$jpctbdir" in
23 /*)     ;;
24 *)      jpctbdir="$PWD/$jpctbdir" ;;
25 esac
26
27 #---------- find YPP client and the Java installation it uses ----------
28
29 yppdir="${yohoho%/*}"
30
31 if [ -x "$yppdir/java/bin/java" ]; then
32         javadir="$yppdir/java"
33 elif [ x"$JAVA_HOME" != x ] && [ -x "$JAVA_HOME/bin/java" ]; then
34         javadir="$JAVA_HOME"
35 else
36         fail "could not find java runtime system"
37 fi
38
39 case "$javadir" in
40 /*)     ;;
41 *)      javadir="$PWD/$javadir" ;;
42 esac
43
44 jtmp="$jpctbdir/tmp"
45 linkfarm="$jtmp/linkfarm"
46 extdir="$jtmp/ext"
47
48 #---------- confirm for the user which paths we're using ----------
49
50 cat <<END
51 jpctb:
52    jpctb tree:   "$jpctbdir"
53    yohoho:       "$yohoho"
54    java:         "$javadir"
55    PCTB jars:    "$srcjardir"
56    jpctb tmpdir: "$jtmp"
57 END
58
59 #---------- create the temporary are and link farm ----------
60
61 rm -rf -- "$jtmp"
62 mkdir -- "$jtmp" "$extdir" "$linkfarm"
63 cp "$srcjardir"/PCTB*.jar "$extdir"
64
65 lndir -silent "$javadir" "$linkfarm"
66
67 #---------- edit the linkfarm to have our jvm wrapper ----------
68
69 wrapper="$linkfarm"/jre/bin/java
70 rm -- "$wrapper"
71
72 export JPCTB_EXTDIR="$extdir"
73 export JPCTB_JRE="$javadir/jre"
74
75 cat <<'END' >"$wrapper"
76 #!/bin/bash
77         set -e$JPCTB_JWRAP_X
78
79         log () {
80                 lh=`date +'%Y/%m/%d %H:%M:%S jpctb'`
81                 printf >&2 "%s: %s |\f\n" "$lh" "$*"
82         }
83
84         log "invoked as $*"
85
86 #echo >&2 "$djava-wrap 
87 #exec 4>>/home/ian/u
88 #date >&4
89 #exec 4>&-
90
91         yppclass=com.threerings.yohoho.client.YoApp
92         atclass=com.tedpearson.ypp.market.MarketUploader
93
94         args=( "$@" )
95         nargs=${#args[*]}
96         lastarg="${args[$(( $nargs - 1 ))]}"
97
98         fail () { echo >&2 "jpctb-java: $*"; exit 127; }
99
100         if [ x"$lastarg" = x"$yppclass" ]; then
101
102                 [ x"$JPCTB_EXTDIR" != x ] || fail 'JPCTB_EXTDIR not set'
103
104                 set     -e$JPCTB_JWRAP_X -- \
105                         -Djavax.accessibility.assistive_technologies=$atclass \
106                         -Djava.ext.dirs="$JPCTB_EXTDIR:$JPCTB_JRE/lib/ext" \
107                         "$@"
108         fi
109
110         real="$JPCTB_JRE/bin/java"
111         log "running $real $*"
112         exec "$real" "$@"
113 END
114
115 chmod +x -- "$wrapper"
116
117 #---------- now run it ----------
118
119 exec "$yohoho" -Djava.home="$linkfarm/jre"