chiark / gitweb /
Add the lib elevate stuff (even though it's only used by the old
[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 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 if [ -x "$yppdir/java/bin/java" ]; then
77         javadir="$yppdir/java"
78 elif [ x"$JAVA_HOME" != x ] && [ -x "$JAVA_HOME/bin/java" ]; then
79         javadir="$JAVA_HOME"
80 else
81         fail "could not find java runtime system"
82 fi
83
84 case "$javadir" in
85 /*)     ;;
86 *)      javadir="$PWD/$javadir" ;;
87 esac
88
89 jtmp="$jpctbdir/tmp"
90 linkfarm="$jtmp/linkfarm"
91 extdir="$jtmp/ext"
92
93 #---------- confirm for the user which paths we're using ----------
94
95 cat <<END
96 jpctb:
97    jpctb tree:   "$jpctbdir"
98    yohoho:       "$yohoho"
99    java:         "$javadir"
100    PCTB jars:    "$srcjardir"
101    jpctb tmpdir: "$jtmp"
102 END
103
104 #---------- run the control panel ----------
105
106 "$javadir/bin/java" -jar "$srcjardir/PCTB-ControlPanel.jar"
107
108 #---------- create the temporary are and link farm ----------
109
110 rm -rf -- "$jtmp"
111 mkdir -- "$jtmp" "$extdir" "$linkfarm"
112 cp "$srcjardir"/PCTB*.jar "$extdir"
113
114 lndir -silent "$javadir" "$linkfarm"
115
116 #---------- edit the linkfarm to have our jvm wrapper ----------
117
118 wrapper="$linkfarm"/jre/bin/java
119 rm -- "$wrapper"
120
121 export JPCTB_EXTDIR="$extdir"
122 export JPCTB_JRE="$javadir/jre"
123
124 cat <<'END' >"$wrapper"
125 #!/bin/bash
126         set -e$JPCTB_JWRAP_X
127
128         log () {
129                 lh=`date +'%Y/%m/%d %H:%M:%S jpctb'`
130                 printf >&2 "%s: %s |\f\n" "$lh" "$*"
131         }
132
133         log "invoked as $*"
134
135 #echo >&2 "$djava-wrap 
136 #exec 4>>/home/ian/u
137 #date >&4
138 #exec 4>&-
139
140         yppclass=com.threerings.yohoho.client.YoApp
141         atclass=com.tedpearson.ypp.market.MarketUploader
142
143         args=( "$@" )
144         nargs=${#args[*]}
145         lastarg="${args[$(( $nargs - 1 ))]}"
146
147         fail () { echo >&2 "jpctb-java: $*"; exit 127; }
148
149         if [ x"$lastarg" = x"$yppclass" ]; then
150
151                 [ x"$JPCTB_EXTDIR" != x ] || fail 'JPCTB_EXTDIR not set'
152
153                 set     -e$JPCTB_JWRAP_X -- \
154                         -Djavax.accessibility.assistive_technologies=$atclass \
155                         -Djava.ext.dirs="$JPCTB_EXTDIR:$JPCTB_JRE/lib/ext" \
156                         "$@"
157         fi
158
159         real="$JPCTB_JRE/bin/java"
160         log "running $real $*"
161         exec "$real" "$@"
162 END
163
164 chmod +x -- "$wrapper"
165
166 #---------- now run it ----------
167
168 exec "$yohoho" -Djava.home="$linkfarm/jre"