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