Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/java/javavmwrapper/src/javavmwrapper.sh
16461 views
1
#!/bin/sh
2
#
3
# javawrapper.sh
4
#
5
# Allow the installation of several Java Virtual Machines on the system.
6
# They can then be selected from based on environment variables and the
7
# configuration file.
8
#
9
# ----------------------------------------------------------------------------
10
# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
11
# Maxim Sobolev <[email protected]> wrote this file. As long as you retain
12
# this notice you can do whatever you want with this stuff. If we meet some
13
# day, and you think this stuff is worth it, you can buy me a beer in return.
14
#
15
# Maxim Sobolev
16
# ----------------------------------------------------------------------------
17
#
18
# ----------------------------------------------------------------------------
19
# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
20
# Greg Lewis <[email protected]> substantially rewrote this file. As long
21
# as you retain this notice you can do whatever you want with this stuff. If
22
# we meet some day, and you think this stuff is worth it, you can buy me a
23
# beer in return.
24
#
25
# Greg Lewis
26
# ----------------------------------------------------------------------------
27
#
28
# [email protected]
29
30
_JAVAVM_SAVE_PATH=${PATH}
31
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
32
33
_JAVAVM_PREFIX="%%PREFIX%%"
34
_JAVAVM_CONF="${_JAVAVM_PREFIX}/etc/javavms"
35
_JAVAVM_OPTS_CONF="${_JAVAVM_PREFIX}/etc/javavm_opts.conf"
36
_JAVAVM_PROG=`basename "${0}"`
37
_JAVAVM_MAKE=/usr/bin/make
38
39
#
40
# Try to run a Java command.
41
#
42
tryJavaCommand () {
43
# If this is a test run, spit out the configuration and exit
44
if [ -n "${JAVAVM_DRYRUN}" ]; then
45
echo "JAVA_HOME=${JAVA_HOME}"
46
echo "JAVAVM_CONF=${_JAVAVM_CONF}"
47
echo "JAVAVM_OPTS_CONF=${_JAVAVM_OPTS_CONF}"
48
echo "JAVAVM_PROG=${1}"
49
echo "JAVAVM_OPTS=${_JAVAVM_OPTS}"
50
echo "JAVAVM_COMMAND=${@}"
51
exit 0
52
fi
53
54
# Check for the command being executable and exec it if so.
55
if [ -x "${1}" ]; then
56
if [ -n "${_JAVAVM_SAVE_PATH}" ]; then
57
export PATH=${_JAVAVM_SAVE_PATH}
58
fi
59
exec "${@}"
60
fi
61
62
echo "${_JAVAVM_PROG}: warning: couldn't run specified Java command - \"${1}\"" 1>&2
63
}
64
65
#
66
# Set java command options, if applicable
67
# 1 - Name of the java programme to be executed.
68
# 2 - Base directory of JAVA_HOME for the java programme to be executed.
69
#
70
setJavaOptions () {
71
local OPTS_PROG=`echo ${1} | sed -e s/\\\\./_/g -e s/-/_/g`
72
local OPTS_JAVA_HOME=`echo ${2} | sed -e s/\\\\./_/g -e s/-/_/g`
73
local JAVA_HOME_PROG_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_JAVA_HOME}_${OPTS_PROG}\} 2>/dev/null`"
74
local JAVA_HOME_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_JAVA_HOME}\} 2>/dev/null`"
75
local PROG_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_PROG}\} 2>/dev/null`"
76
77
# Possible environment variables are stackable
78
if [ -n "${JAVA_HOME_PROG_OPTS}" ]; then
79
_JAVAVM_OPTS="${JAVA_HOME_PROG_OPTS} ${_JAVAVM_OPTS}"
80
fi
81
if [ -n "${JAVA_HOME_OPTS}" ]; then
82
_JAVAVM_OPTS="${JAVA_HOME_OPTS} ${_JAVAVM_OPTS}"
83
fi
84
if [ -n "${PROG_OPTS}" ]; then
85
_JAVAVM_OPTS="${PROG_OPTS} ${_JAVAVM_OPTS}"
86
fi
87
if [ -n "${JAVAVM_OPTS}" ]; then
88
_JAVAVM_OPTS="${JAVAVM_OPTS} ${_JAVAVM_OPTS}"
89
fi
90
}
91
92
#
93
# Create symbolic links for all of a Java VMs executables.
94
#
95
createJavaLinks () {
96
for exe in "${1}"/bin/* "${1}"/jre/bin/*; do
97
if [ -x "${exe}" -a \
98
! -d "${exe}" -a \
99
"`basename "${exe}"`" = "`basename "${exe}" .so`" -a \
100
! -e "${_JAVAVM_PREFIX}/bin/`basename "${exe}"`" -a \
101
-w "${_JAVAVM_PREFIX}/bin" ]; then
102
ln -s "${_JAVAVM_PREFIX}/bin/javavm" \
103
"${_JAVAVM_PREFIX}/bin/`basename "${exe}"`" 2>/dev/null
104
fi
105
done
106
}
107
108
#
109
# Sort the configuration file
110
#
111
sortConfiguration () {
112
local IFS=:
113
114
# Ensure the configuration file exists
115
if [ ! -f "${_JAVAVM_CONF}" ]; then
116
return
117
fi
118
119
# Ensure the configuration file has the correct permissions
120
if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then
121
echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2
122
return
123
fi
124
125
cat "${_JAVAVM_CONF}" | \
126
(
127
export JAVAVMS
128
while read JAVAVM; do
129
VM=`echo "${JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
130
# Check that the VM exists and is "sane"
131
if [ ! -e "${VM}" ]; then
132
continue
133
fi
134
if [ -d "${VM}" ]; then
135
continue
136
fi
137
if [ ! -x "${VM}" ]; then
138
continue
139
fi
140
if [ `basename "${VM}"` != "java" ]; then
141
continue
142
fi
143
if [ "`realpath "${VM}" 2>/dev/null `" = "${_JAVAVM_PREFIX}/bin/javavm" ]; then
144
continue
145
fi
146
# Skip duplicate VMs
147
if [ -n "${JAVAVMS}" ]; then
148
for _JAVAVM in ${JAVAVMS}; do
149
if [ -z "${_JAVAVM}" ]; then
150
continue
151
fi
152
_VM=`echo "${_JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
153
if [ "x${VM}" = "x${_VM}" ]; then
154
continue 2
155
fi
156
done
157
fi
158
VM=`dirname "${VM}"`
159
VM=`dirname "${VM}"`
160
VM=`basename "${VM}"`
161
_JAVAVMS=:
162
for _JAVAVM in ${JAVAVMS}; do
163
if [ -z "${_JAVAVM}" ]; then
164
continue
165
fi
166
if [ -z "${JAVAVM}" ]; then
167
_JAVAVMS="${_JAVAVMS}:${_JAVAVM}"
168
continue
169
fi
170
_VM=`echo "${_JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
171
_VM=`dirname "${_VM}"`
172
_VM=`dirname "${_VM}"`
173
_VM=`basename "${_VM}"`
174
# Consistent version numbering for various install directory names.
175
VERSION=`echo ${VM} | sed -e 's|[^0-9]*||' \
176
-e 's|1\.\([0-9][0-9]*\)|\1|' \
177
-e 's|\([0-9][0-9]*\)\.[0-9]|\1|' \
178
-e 's|[^0-9]*\([0-9][0-9]*\)[^0-9]*|\1|'
179
2>/dev/null`
180
_VERSION=`echo ${_VM} | sed -e 's|[^0-9]*||' \
181
-e 's|1\.\([0-9][0-9]*\)|\1|' \
182
-e 's|\([0-9][0-9]*\)\.[0-9]|\1|' \
183
-e 's|[^0-9]*\([0-9][0-9]*\)[^0-9]*|\1|'
184
2>/dev/null`
185
if [ "${VERSION}" -gt "${_VERSION}" ]; then
186
_JAVAVMS="${_JAVAVMS}:${JAVAVM}:${_JAVAVM}"
187
JAVAVM=
188
continue
189
elif [ "${VERSION}" -lt "${_VERSION}" ]; then
190
_JAVAVMS="${_JAVAVMS}:${_JAVAVM}"
191
continue
192
else
193
case "${VM}" in
194
openjdk*)
195
_JAVAVMS="${_JAVAVMS}:${JAVAVM}:${_JAVAVM}"
196
JAVAVM=
197
continue
198
;;
199
linux-sun-jdk*|linux-oracle-jdk*)
200
case "${_VM}" in
201
open*)
202
_JAVAVMS="${_JAVAVMS}:${_JAVAVM}"
203
continue
204
;;
205
*)
206
_JAVAVMS="${_JAVAVMS}:${JAVAVM}:${_JAVAVM}"
207
JAVAVM=
208
continue
209
;;
210
esac
211
;;
212
linux-sun-jre*|linux-oracle-jre*)
213
case "${_VM}" in
214
open*|linux-sun*|linux-oracle*)
215
_JAVAVMS="${_JAVAVMS}:${_JAVAVM}"
216
continue
217
;;
218
*)
219
_JAVAVMS="${_JAVAVMS}:${JAVAVM}:${_JAVAVM}"
220
JAVAVM=
221
continue
222
;;
223
esac
224
;;
225
esac
226
_JAVAVMS="${_JAVAVMS}:${_JAVAVM}"
227
fi
228
done
229
JAVAVMS="${_JAVAVMS}"
230
if [ -n "${JAVAVM}" ]; then
231
JAVAVMS="${JAVAVMS}:${JAVAVM}"
232
fi
233
done;
234
if [ -n "${JAVAVMS}" ]; then
235
rm "${_JAVAVM_CONF}"
236
for JAVAVM in ${JAVAVMS}; do
237
if [ -n "${JAVAVM}" ]; then
238
echo "${JAVAVM}" >> "${_JAVAVM_CONF}"
239
fi
240
done
241
fi
242
)
243
}
244
245
#
246
# Check all of the VMs in the configuration file
247
#
248
checkVMs () {
249
# Ensure the configuration file exists
250
if [ ! -f "${_JAVAVM_CONF}" ]; then
251
exit 0
252
fi
253
254
# Ensure the configuration file has the correct permissions
255
if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then
256
echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2
257
exit 1
258
fi
259
260
# Sort the configuration. This will also remove duplicates and
261
# non-existent VMs
262
sortConfiguration
263
264
# Ensure links are created for every executable for a VM.
265
cat "${_JAVAVM_CONF}" | \
266
(
267
while read JAVAVM; do
268
VM=`echo "${JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
269
# Create symbolic links as appropriate if they don't exist.
270
JAVA_HOME=`dirname "${VM}"`
271
JAVA_HOME=`dirname "${JAVA_HOME}"`
272
createJavaLinks "${JAVA_HOME}"
273
done;
274
)
275
276
exit 0
277
}
278
279
#
280
# Register a new Java VM.
281
#
282
registerVM () {
283
# Check the java command given to us.
284
if [ -z "${1}" ]; then
285
echo "Usage: ${_JAVAVM_PROG} path"
286
exit 1
287
fi
288
289
# Create the configuration file if it doesn't exist
290
if [ ! -e "${_JAVAVM_CONF}" ]; then
291
touch "${_JAVAVM_CONF}"
292
fi
293
294
# Ensure the configuration file exists and has the correct permissions
295
if [ ! -f "${_JAVAVM_CONF}" -o ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then
296
echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2
297
exit 1
298
fi
299
300
# Check that the given VM can be found in the configuration file
301
VM=`echo "${1}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
302
REGISTERED=
303
if [ -n "`grep "${VM}" "${_JAVAVM_CONF}"`" ]; then
304
echo "${_JAVAVM_PROG}: warning: JavaVM \"${VM}\" is already registered" 1>&2
305
REGISTERED="yes"
306
fi
307
308
# Check that the VM exists and is "sane"
309
if [ ! -e "${VM}" ]; then
310
echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" does not exist" 1>&2
311
exit 1
312
fi
313
if [ -d "${VM}" ]; then
314
echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is a directory" 1>&2
315
exit 1
316
fi
317
if [ ! -x "${VM}" ]; then
318
echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is not executable" 1>&2
319
exit 1
320
fi
321
if [ `basename "${VM}"` != "java" ]; then
322
echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is not valid" 1>&2
323
exit 1
324
fi
325
if [ "`realpath "${VM}" 2>/dev/null `" = "${_JAVAVM_PREFIX}/bin/javavm" ]; then
326
echo "${_JAVAVM_PROG}: error: JavaVM \"${VM}\" is javavm!" 1>&2
327
exit 1
328
fi
329
330
# Add the VM to the configuration file
331
if [ "${REGISTERED}" != "yes" ]; then
332
echo "${1}" >> "${_JAVAVM_CONF}"
333
fi
334
335
# Create symbolic links as appropriate if they don't exist.
336
JAVA_HOME=`dirname "${VM}"`
337
JAVA_HOME=`dirname "${JAVA_HOME}"`
338
createJavaLinks "${JAVA_HOME}"
339
340
# Sort the VMs
341
sortConfiguration
342
343
exit 0
344
}
345
346
#
347
# Unregister a Java VM.
348
#
349
unregisterVM () {
350
# Check usage
351
if [ -z "${1}" ]; then
352
echo "Usage: ${_JAVAVM_PROG} path"
353
exit 1
354
fi
355
356
# Check for the configuration file
357
if [ ! -e "${_JAVAVM_CONF}" ]; then
358
echo "${_JAVAVM_PROG}: error: can't find ${_JAVAVM_CONF} configuration file!" 1>&2
359
exit 1
360
fi
361
362
# Ensure the configuration file has the correct permissions
363
if [ ! -w "${_JAVAVM_CONF}" -o ! -r "${_JAVAVM_CONF}" ]; then
364
echo "${_JAVAVM_PROG}: error: can't read/write ${_JAVAVM_CONF} configuration file!" 1>&2
365
exit 1
366
fi
367
368
# Check that the given VM can be found in the configuration file
369
if [ -z "`grep "${1}" "${_JAVAVM_CONF}"`" ]; then
370
echo "${_JAVAVM_PROG}: error: \"${1}\" JavaVM is not currently registered"
371
exit 1
372
fi
373
374
# Remove unneeded symlinks
375
VMS=`sed -E 's|[[:space:]]*#.*||' < "${_JAVAVM_CONF}" | uniq 2>/dev/null`
376
VM=`grep "${1}" "${_JAVAVM_CONF}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
377
JAVA_HOME=`dirname "${VM}"`
378
JAVA_HOME=`dirname "${JAVA_HOME}"`
379
for exe in "${JAVA_HOME}"/bin/* "${JAVA_HOME}"/jre/bin/*; do
380
exe=`basename "${exe}"`
381
if [ -L "${_JAVAVM_PREFIX}/bin/${exe}" -a \
382
"`realpath "${_JAVAVM_PREFIX}/bin/${exe}" 2>/dev/null `" = \
383
"${_JAVAVM_PREFIX}/bin/javavm" ]; then
384
for JAVAVM in ${VMS}; do
385
if [ "${JAVAVM}" != "${VM}" ]; then
386
JAVAVM=`dirname "${JAVAVM}"`
387
JAVAVM=`dirname "${JAVAVM}"`
388
if [ -x "${JAVAVM}/bin/${exe}" -o \
389
-x "${JAVAVM}/jre/bin/${exe}" ]; then
390
continue 2
391
fi
392
fi
393
done
394
395
rm "${_JAVAVM_PREFIX}/bin/${exe}"
396
fi
397
done
398
399
# Remove the VM from the configuration file
400
ed "${_JAVAVM_CONF}" >/dev/null <<EOF
401
g|${1}|d
402
w
403
q
404
EOF
405
406
# Remove configuration file if its size reached 0
407
if [ ! -s "${_JAVAVM_CONF}" ]; then
408
rm "${_JAVAVM_CONF}"
409
fi
410
411
exit 0
412
}
413
414
#
415
# Show the manual page for a Java VM
416
#
417
manualpageVM () {
418
# Check usage
419
if [ -z "${1}" ]; then
420
echo "Usage: ${_JAVAVM_PROG} name"
421
exit 1
422
fi
423
424
# Look for an appropriate JAVA_HOME
425
_JAVAVM_SAVE_PROG=${_JAVAVM_PROG}
426
_JAVAVM_PROG="../man/man1/${1}.1"
427
setJavaHome
428
if [ $? != 0 ]; then
429
echo "${_JAVAVM_SAVE_PROG}: error: no suitable JavaVMs found" 1>&2
430
exit 1
431
fi
432
433
# Run man(1)
434
MANPATH="${JAVA_HOME}/man:${MANPATH}"
435
export MANPATH
436
if [ "${LANG}" = "ja_JP.eucJP" -a -x "${_JAVAVM_PREFIX}/bin/jman" ]; then
437
setJavaOptions jman "`basename ${JAVA_HOME}`"
438
exec ${_JAVAVM_PREFIX}/bin/jman -S 1 ${_JAVAVM_OPTS} ${1}
439
else
440
setJavaOptions man "`basename ${JAVA_HOME}`"
441
exec man -S 1 ${_JAVAVM_OPTS} ${1}
442
fi
443
}
444
445
#
446
# Set up an appropriate JAVA_HOME
447
#
448
setJavaHome() {
449
# Use JAVA_HOME if it's set, unless its set to %%PREFIX%%
450
if [ -n "${JAVA_HOME}" ]; then
451
if [ "`realpath "${JAVA_HOME}"`" != "`realpath "${_JAVAVM_PREFIX}"`" ]; then
452
if [ -f "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
453
_JAVAVM_PROG_PATH="${JAVA_HOME}/bin"
454
return 0
455
elif [ -f "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
456
_JAVAVM_PROG_PATH="${JAVA_HOME}/jre/bin"
457
return 0
458
fi
459
fi
460
fi
461
462
unset JAVA_HOME
463
464
# Use bsd.java.mk to determine the VM to use if it exists unless
465
# JAVAVM_FALLBACK_ONLY is set
466
if [ -z "${JAVAVM_FALLBACK_ONLY}" ]; then
467
# Determine location of bsd.port.mk if it exists
468
_JAVAVM_PORTSDIR=
469
if [ -r /usr/share/mk/bsd.port.mk ]; then
470
_JAVAVM_PORTSDIR=`"${_JAVAVM_MAKE}" -f /usr/share/mk/bsd.port.mk -V PORTSDIR 2>/dev/null`
471
fi
472
473
_JAVAVM_BSD_PORT_MK=
474
if [ -n "${_JAVAVM_PORTSDIR}" -a -r "${_JAVAVM_PORTSDIR}/Mk/bsd.port.mk" ]; then
475
_JAVAVM_BSD_PORT_MK="${_JAVAVM_PORTSDIR}/Mk/bsd.port.mk"
476
fi
477
478
# If bsd.port.mk was found, use that to determine the VM to use.
479
if [ -n "${_JAVAVM_BSD_PORT_MK}" ]; then
480
JAVA_HOME=`"${_JAVAVM_MAKE}" -f "${_JAVAVM_BSD_PORT_MK}" -V JAVA_HOME USE_JAVA=yes 2>/dev/null`
481
if [ -n "${JAVA_HOME}" -a -f "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
482
_JAVAVM_PROG_PATH="${JAVA_HOME}/bin"
483
return 0
484
elif [ -n "${JAVA_HOME}" -a \
485
-f "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
486
_JAVAVM_PROG_PATH="${JAVA_HOME}/jre/bin"
487
return 0
488
fi
489
fi
490
fi
491
492
# Then try to make sure that ${_JAVAVM_CONF} exists
493
if [ ! -e "${_JAVAVM_CONF}" ]; then
494
echo "${_JAVAVM_PROG}: error: can't find ${_JAVAVM_CONF} configuration file" 1>&2
495
exit 1
496
fi
497
498
# Allow comments in the ${_JAVAVM_CONF}
499
_JAVAVM_VMS=`sed -E 's|[[:space:]]*#.*||' < "${_JAVAVM_CONF}" | uniq 2>/dev/null`
500
501
# Fix up JAVA_VERSION
502
if [ -n "${JAVA_VERSION}" ]; then
503
_JAVAVM_VERSION=
504
for version in ${JAVA_VERSION}; do
505
case "${version}" in
506
8+)
507
_JAVAVM_VERSION="${_JAVAVM_VERSION} 8 11 17 18 19 20 21"
508
;;
509
11+)
510
_JAVAVM_VERSION="${_JAVAVM_VERSION} 11 17 18 19 20 21"
511
;;
512
17+)
513
_JAVAVM_VERSION="${_JAVAVM_VERSION} 17 18 19 20 21"
514
;;
515
18+)
516
_JAVAVM_VERSION="${_JAVAVM_VERSION} 18 19 20 21"
517
;;
518
19+)
519
_JAVAVM_VERSION="${_JAVAVM_VERSION} 19 20 21"
520
;;
521
20+)
522
_JAVAVM_VERSION="${_JAVAVM_VERSION} 20 21"
523
;;
524
21+)
525
_JAVAVM_VERSION="${_JAVAVM_VERSION} 21"
526
;;
527
*)
528
_JAVAVM_VERSION="${_JAVAVM_VERSION} ${version}"
529
;;
530
esac
531
done
532
JAVA_VERSION=`echo "${_JAVAVM_VERSION}" | sort -n | uniq`
533
fi
534
535
# Finally try to run one of the ${_JAVAVM_VMS}
536
for _JAVAVM_JAVAVM in ${_JAVAVM_VMS}; do
537
JAVA_HOME=`dirname "${_JAVAVM_JAVAVM}"`
538
JAVA_HOME=`dirname "${JAVA_HOME}"`
539
_JAVAVM_VM=`basename "${JAVA_HOME}"`
540
# Respect JAVA_VERSION
541
if [ -n "${JAVA_VERSION}" ]; then
542
_JAVAVM_VERSION=`echo ${_JAVAVM_VM} | \
543
sed -e 's|^[^0-9]*\([0-9]\)\.\([0-9]\)\.[0-9]$|\2|' \
544
-e 's|^[^0-9]*\([0-9][0-9]*\)$|\1|'`
545
for _JAVAVM_REQUESTED_VERSION in ${JAVA_VERSION}; do
546
if [ "${_JAVAVM_VERSION}" = "${_JAVAVM_REQUESTED_VERSION}" ]; then
547
_JAVAVM_VERSION=
548
break
549
fi
550
done
551
if [ -n "${_JAVAVM_VERSION}" ]; then
552
continue
553
fi
554
fi
555
# Respect JAVA_OS
556
if [ -n "${JAVA_OS}" ]; then
557
_JAVAVM_OS=
558
case "${_JAVAVM_VM}" in
559
openjdk*)
560
_JAVAVM_OS=native
561
;;
562
linux*)
563
_JAVAVM_OS=linux
564
;;
565
esac
566
for _JAVAVM_REQUESTED_OS in ${JAVA_OS}; do
567
if [ "${_JAVAVM_OS}" = "${_JAVAVM_REQUESTED_OS}" ]; then
568
_JAVAVM_OS=
569
break
570
fi
571
done
572
if [ -n "${_JAVAVM_OS}" ]; then
573
continue
574
fi
575
fi
576
# Respect JAVA_VENDOR
577
if [ -n "${JAVA_VENDOR}" ]; then
578
_JAVAVM_VENDOR=
579
case "${_JAVAVM_VM}" in
580
openjdk*)
581
_JAVAVM_VENDOR=openjdk
582
;;
583
linux-sun*)
584
_JAVAVM_VENDOR=sun
585
;;
586
linux-oracle*)
587
_JAVAVM_VENDOR=oracle
588
;;
589
esac
590
for _JAVAVM_REQUESTED_VENDOR in ${JAVA_VENDOR}; do
591
if [ "${_JAVAVM_VENDOR}" = "${_JAVAVM_REQUESTED_VENDOR}" ]; then
592
_JAVAVM_VENDOR=
593
break
594
fi
595
done
596
if [ -n "${_JAVAVM_VENDOR}" ]; then
597
continue
598
fi
599
fi
600
# Check if the command exists
601
if [ -n "${JAVA_HOME}" -a -f "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
602
_JAVAVM_PROG_PATH="${JAVA_HOME}/bin"
603
return 0
604
elif [ -n "${JAVA_HOME}" -a \
605
-f "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
606
_JAVAVM_PROG_PATH="${JAVA_HOME}/jre/bin"
607
return 0
608
fi
609
done
610
611
unset JAVA_HOME
612
613
return 1
614
}
615
616
# Check for an alias and call the appropriate function.
617
case "${_JAVAVM_PROG}" in
618
registervm )
619
registerVM "${1}"
620
;;
621
unregistervm )
622
unregisterVM "${1}"
623
;;
624
checkvms )
625
checkVMs
626
;;
627
manvm )
628
manualpageVM "${1}"
629
;;
630
esac
631
632
# Main ()
633
634
# Backwards compatibility
635
if [ "${_JAVAVM_PROG}" = "javavm" ]; then
636
echo "${_JAVAVM_PROG}: warning: The use of 'javavm' as a synonym for 'java' is deprecated" 1>&2
637
_JAVAVM_PROG=java
638
fi
639
640
# Initialise options
641
if [ -r "${_JAVAVM_OPTS_CONF}" ]; then
642
. "${_JAVAVM_OPTS_CONF}"
643
fi
644
_JAVAVM_OPTS=
645
646
# Determine JAVA_HOME
647
setJavaHome
648
if [ $? != 0 ]; then
649
echo "${_JAVAVM_PROG}: error: no suitable JavaVMs found" 1>&2
650
exit 1
651
fi
652
653
# Set up the options and run the command
654
if [ -x "${_JAVAVM_PROG_PATH}/${_JAVAVM_PROG}" ]; then
655
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
656
export JAVA_HOME
657
tryJavaCommand "${_JAVAVM_PROG_PATH}/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
658
fi
659
660
echo "${_JAVAVM_PROG}: error: no suitable JavaVMs found" 1>&2
661
exit 1
662
663