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-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
|
---|
22 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
|
---|
23 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
|
---|
24 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
|
---|
25 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
|
---|
26 | # Development version
|
---|
27 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
|
---|
28 | fi
|
---|
29 | # Undetermined version
|
---|
30 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
|
---|
31 |
|
---|
32 | if [ -f /etc/default/josm ]; then
|
---|
33 | . /etc/default/josm
|
---|
34 | fi
|
---|
35 |
|
---|
36 | JAVA_OPTS="-Djosm.restart=true -Djava.net.useSystemProxies=true $JAVA_OPTS"
|
---|
37 |
|
---|
38 | if [ -z "${JAVACMD}" ]; then
|
---|
39 | for jcmd in $JAVA_CMDS; do
|
---|
40 | if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ]; then
|
---|
41 | JAVACMD="$jcmd"
|
---|
42 | break
|
---|
43 | fi
|
---|
44 | done
|
---|
45 | fi
|
---|
46 |
|
---|
47 | if [ -z "${JAVACMD}" ]; then
|
---|
48 | for jcmd in $JAVA_CMDS; do
|
---|
49 | if [ -x "$jcmd" ] && [ -z "${JAVACMD}" ]; then
|
---|
50 | JAVACMD="$jcmd"
|
---|
51 | break
|
---|
52 | fi
|
---|
53 | done
|
---|
54 | fi
|
---|
55 |
|
---|
56 | if [ "$JAVACMD" ]; then
|
---|
57 | echo "Using $JAVACMD to execute josm." || true
|
---|
58 | if [[ "${JAVACMD}" =~ 'java-9' ]] || [[ "${JAVACMD}" =~ 'java-10' ]]; then
|
---|
59 | JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
|
---|
60 | elif [[ "${JAVACMD}" =~ 'java-1' ]]; then
|
---|
61 | JAVA_OPTS="--add-modules java.scripting,java.sql $JAVA_OPTS"
|
---|
62 | fi
|
---|
63 | set +e
|
---|
64 | while true; do
|
---|
65 | $JAVACMD $JAVA_OPTS -jar /usr/share/josm/josm.jar "$@"
|
---|
66 | if [ "z$?" != "z9" ]; then
|
---|
67 | break
|
---|
68 | fi
|
---|
69 | echo ">> restarting josm..."
|
---|
70 | done
|
---|
71 | else
|
---|
72 | echo "No valid JVM found to run JOSM." || true
|
---|
73 | exit 1
|
---|
74 | fi
|
---|