chiark / gitweb /
Do not use openjdk; it doesn't work to mix and match
[jarrg-owen.git] / jpctb
1 #!/bin/bash -e
2
3 # This is jpctb, a wrapper script for plumbing Ted Pearson's Java PCTB
4 # client into a JVM on Linux.
5
6 # This program is Free Software.  Copyright (C) 2009 Ian Jackson.
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is fur-
13 # nished to do so, subject to the following conditions:
14
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
17
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
20 # NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 # XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
23 # NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
26 usage () { cat <<END
27 usage: .../jpctb /path/to/yohoho/yohoho [...]
28 END
29 }
30
31 fail () {
32         echo >&2 "jpctb: $*"
33         exit 127
34 }
35 badusage () {
36         fail "bad usage: $*"
37 }
38
39 while [ $# -ge 1 ]; do
40         case "$1" in
41         -)              shift; break;;
42         --jpctb)
43                         shift
44                         srcjardir="$1"
45                         shift || badusage "--jpctb needs a value"
46                         ;;
47         -*)             badusage "unknown option \`$1'"
48                         ;;
49         *)
50                         break
51         esac
52 done
53
54 if [ $# -lt 1 ]; then usage; badusage "need path to yohoho"; exit 127; fi
55
56 yohoho="$1"; shift
57
58 #---------- find ourselves ----------
59
60 jpctbdir="$0"
61 jpctbdir="${jpctbdir%/*}"
62
63 case "$jpctbdir" in
64 /*)     ;;
65 *)      jpctbdir="$PWD/$jpctbdir" ;;
66 esac
67
68 if [ x"$srcjardir" = x ]; then
69         srcjardir="$jpctbdir"
70 fi
71
72 #---------- find YPP client and the Java installation it uses ----------
73
74 yppdir="${yohoho%/*}"
75
76 cat <<END
77 jpctb:
78    jpctb tree:   "$jpctbdir"
79    yohoho:       "$yohoho"
80 END
81
82 if [ -x "$yppdir/java/bin/java" ]; then
83         if [ -d "$yppdir/java/jre" ]; then
84                 echo "   yohoho/java/bin and yohoho/java/jre exist, good"
85                 javadir="$yppdir/java"
86         else
87                 absjava=`readlink -f "$yppdir/java/bin/java"`
88                 cat <<END
89    yohoho/java/bin exists but yohoho/java/jre does not
90    abs. java:    "$absjava"
91 END
92                 case "$absjava" in
93                 */jre/bin/java)
94                         echo "   found jre directory, good"
95                         javadir="${absjava%/jre/bin/java}"
96                         ;;
97                 *)
98                         echo "   java binary not in jre dir as expected, hmm."
99                         ;;
100                 esac
101         fi
102 fi
103
104 if [ "x$javadir" = x ] && [ x"$JAVA_HOME" != x ] && \
105    [ -x "$JAVA_HOME/bin/java" ]; then
106 cat <<END
107    yohoho/java/bin/java nonexistent or unsuitable, trying JAVA_HOME"
108    JAVA_HOME:    "$JAVA_HOME"
109 END
110         if [ -d "$JAVA_HOME/jre" ]; then
111                 javadir="$JAVA_HOME"
112         else
113                 echo "   JAVA_HOME has no jre subdirectory, hmm."
114         fi
115 fi
116
117 if [ "x$javadir" = x ]; then
118         fail "could not find java runtime system
119  please check that $yppdir/java points to your Java installation"
120 fi
121
122 case "$javadir" in
123 /usr)   fail "javadir is still /usr (and even found /usr/jre!)
124  please make $yppdir/java point somewhere more sensible and/or
125  reinstall YPP not telling it your java is in /usr.  sorry." ;;
126 /*)     ;;
127 *)      javadir="$PWD/$javadir" ;;
128 esac
129
130 jtmp="$jpctbdir/tmp"
131 linkfarm="$jtmp/linkfarm"
132 extdir="$jtmp/ext"
133
134 export JPCTB_JRE="$javadir/jre"
135
136 #---------- confirm for the user which paths we're using ----------
137
138 cat <<END
139    java:         "$javadir"
140    JRE:          "$JPCTB_JRE"
141    PCTB jars:    "$srcjardir"
142    jpctb tmpdir: "$jtmp"
143 END
144
145 #---------- run the control panel ----------
146
147 "$javadir/bin/java" -jar "$srcjardir/PCTB-ControlPanel.jar"
148
149 #---------- create the temporary are and link farm ----------
150
151 rm -rf -- "$jtmp"
152 mkdir -- "$jtmp" "$extdir" "$linkfarm"
153 cp "$srcjardir"/PCTB*.jar "$extdir"
154
155 cp -Rs "$javadir"/. "$linkfarm"/.
156
157 #---------- edit the linkfarm to have our jvm wrapper ----------
158
159 wrapper="$linkfarm"/jre/bin/java
160 rm -- "$wrapper"
161
162 export JPCTB_EXTDIR="$extdir"
163
164 cat <<'END' >"$wrapper"
165 #!/bin/bash
166         set -e$JPCTB_JWRAP_X
167
168         log () {
169                 lh=`date +'%Y/%m/%d %H:%M:%S jpctb'`
170                 printf >&2 "%s: %s |\f\n" "$lh" "$*"
171         }
172
173         log "invoked as $*"
174
175 #echo >&2 "$djava-wrap 
176 #exec 4>>/home/ian/u
177 #date >&4
178 #exec 4>&-
179
180         yppclass=com.threerings.yohoho.client.YoApp
181         atclass=com.tedpearson.ypp.market.MarketUploader
182
183         args=( "$@" )
184         nargs=${#args[*]}
185         lastarg="${args[$(( $nargs - 1 ))]}"
186
187         fail () { echo >&2 "jpctb-java: $*"; exit 127; }
188
189         if [ x"$lastarg" = x"$yppclass" ]; then
190
191                 [ x"$JPCTB_EXTDIR" != x ] || fail 'JPCTB_EXTDIR not set'
192
193                 set     -e$JPCTB_JWRAP_X -- \
194                         -Djavax.accessibility.assistive_technologies=$atclass \
195                         -Djava.ext.dirs="$JPCTB_EXTDIR:$JPCTB_JRE/lib/ext" \
196                         "$@"
197         fi
198
199         real="$JPCTB_JRE/bin/java"
200         log "running $real $*"
201         exec "$real" "$@"
202 END
203
204 chmod +x -- "$wrapper"
205
206 #---------- now run it ----------
207
208 exec "$yohoho" -Djava.home="$linkfarm/jre"