1 | #!/bin/bash
|
---|
2 | # Simple wrapper script used to start JOSM in Debian
|
---|
3 | set -e
|
---|
4 |
|
---|
5 | # First, the alternative (if known to work) or users preference as defined by $JAVA_HOME. Next, use OpenJDK.
|
---|
6 | # Override to a specific one using $JAVACMD
|
---|
7 | ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
|
---|
8 |
|
---|
9 | # Let's get the current architecture -- needed for multiarchified Java
|
---|
10 | ARCH=$(dpkg --print-architecture 2> /dev/null || true)
|
---|
11 |
|
---|
12 | JAVA_CMDS="$JAVA_HOME/bin/java"
|
---|
13 |
|
---|
14 | # If OpenJDK is only available headless, do not try it
|
---|
15 | if dpkg --get-selections "openjdk-*-jre" | grep install$ > /dev/null \
|
---|
16 | || dpkg --get-selections "openjdk-*-jre:$ARCH" | grep install$ > /dev/null ; then
|
---|
17 | # LTS versions in decreased order
|
---|
18 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
|
---|
19 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
|
---|
20 | # Released versions in decreased order
|
---|
21 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
|
---|
22 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
|
---|
23 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
|
---|
24 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
|
---|
25 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
|
---|
26 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
|
---|
27 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
|
---|
28 | # Development version(s)
|
---|
29 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
|
---|
30 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
|
---|
31 | fi
|
---|
32 | # Undetermined version
|
---|
33 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
|
---|
34 |
|
---|
35 | if [ -f /etc/default/josm-latest ]; then
|
---|
36 | . /etc/default/josm-latest
|
---|
37 | fi
|
---|
38 |
|
---|
39 | JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=JOSM-latest -Djava.net.useSystemProxies=true $JAVA_OPTS"
|
---|
40 |
|
---|
41 | if [ -z "${JAVACMD}" ]; then
|
---|
42 | for jcmd in $JAVA_CMDS; do
|
---|
43 | if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ]; then
|
---|
44 | JAVACMD="$jcmd"
|
---|
45 | break
|
---|
46 | fi
|
---|
47 | done
|
---|
48 | fi
|
---|
49 |
|
---|
50 | if [ -z "${JAVACMD}" ]; then
|
---|
51 | for jcmd in $JAVA_CMDS; do
|
---|
52 | if [ -x "$jcmd" ] && [ -z "${JAVACMD}" ]; then
|
---|
53 | JAVACMD="$jcmd"
|
---|
54 | break
|
---|
55 | fi
|
---|
56 | done
|
---|
57 | fi
|
---|
58 |
|
---|
59 | if [ "$JAVACMD" ]; then
|
---|
60 | echo "Using $JAVACMD to execute josm-latest." || true
|
---|
61 | if [[ "${JAVACMD}" =~ 'java-9' ]] || [[ "${JAVACMD}" =~ 'java-10' ]]; then
|
---|
62 | JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
|
---|
63 | elif [[ "${JAVACMD}" =~ 'java-1' ]]; then
|
---|
64 | JAVA_OPTS="--add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
|
---|
65 | fi
|
---|
66 | set +e
|
---|
67 | while true; do
|
---|
68 | $JAVACMD $JAVA_OPTS -jar /usr/share/josm-latest/josm-latest.jar "$@"
|
---|
69 | if [ "z$?" != "z9" ]; then
|
---|
70 | break
|
---|
71 | fi
|
---|
72 | echo ">> restarting josm..."
|
---|
73 | done
|
---|
74 | else
|
---|
75 | echo "No valid JVM found to run JOSM." || true
|
---|
76 | exit 1
|
---|
77 | fi
|
---|