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