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 | if [ -e "/etc/alternatives/java" ]; then
|
---|
8 | ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
|
---|
9 | fi
|
---|
10 |
|
---|
11 | if [ -v JAVA_HOME ]; then
|
---|
12 | JAVA_CMDS="$JAVA_HOME/bin/java"
|
---|
13 | else
|
---|
14 | JAVA_CMDS=""
|
---|
15 | fi
|
---|
16 |
|
---|
17 | dpkg_java() {
|
---|
18 | # Let's get the current architecture -- needed for multiarchified Java
|
---|
19 | ARCH=$(dpkg --print-architecture 2> /dev/null || true)
|
---|
20 | # If OpenJDK is only available headless, do not try it
|
---|
21 | if dpkg --get-selections "openjdk-*-jre" | grep install$ > /dev/null \
|
---|
22 | || dpkg --get-selections "openjdk-*-jre:$ARCH" | grep install$ > /dev/null ; then
|
---|
23 | # LTS versions in decreased order
|
---|
24 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-21-openjdk/bin/java /usr/lib/jvm/java-21-openjdk-$ARCH/bin/java"
|
---|
25 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
|
---|
26 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
|
---|
27 | # Released versions in decreased order
|
---|
28 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-22-openjdk/bin/java /usr/lib/jvm/java-22-openjdk-$ARCH/bin/java"
|
---|
29 | # EOL versions in decreased order
|
---|
30 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-20-openjdk/bin/java /usr/lib/jvm/java-20-openjdk-$ARCH/bin/java"
|
---|
31 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-19-openjdk/bin/java /usr/lib/jvm/java-19-openjdk-$ARCH/bin/java"
|
---|
32 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
|
---|
33 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
|
---|
34 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
|
---|
35 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
|
---|
36 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
|
---|
37 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
|
---|
38 | # Development version(s)
|
---|
39 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-23-openjdk/bin/java /usr/lib/jvm/java-23-openjdk-$ARCH/bin/java"
|
---|
40 | fi
|
---|
41 | }
|
---|
42 |
|
---|
43 | java_version() {
|
---|
44 | ${1} -version 2>&1 | head -n1 | awk -F'"' '{print $2}' | awk -F'.' '{print $1}'
|
---|
45 | }
|
---|
46 |
|
---|
47 | if dpkg --version > /dev/null 2>&1; then
|
---|
48 | dpkg_java
|
---|
49 | fi
|
---|
50 |
|
---|
51 | # Undetermined version
|
---|
52 | JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
|
---|
53 | JOSM_VERSION="josm-latest"
|
---|
54 |
|
---|
55 | if [ -f "/etc/default/${JOSM_VERSION}" ]; then
|
---|
56 | # shellcheck source=/etc/default/josm-latest
|
---|
57 | . "/etc/default/${JOSM_VERSION}"
|
---|
58 | fi
|
---|
59 |
|
---|
60 | JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=JOSM-latest -Djava.net.useSystemProxies=true $JAVA_OPTS"
|
---|
61 |
|
---|
62 | if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
|
---|
63 | for jcmd in $JAVA_CMDS; do
|
---|
64 | if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
|
---|
65 | JAVACMD="$jcmd"
|
---|
66 | break
|
---|
67 | fi
|
---|
68 | done
|
---|
69 | fi
|
---|
70 |
|
---|
71 | if [ -z "${JAVACMD}" ]; then
|
---|
72 | for jcmd in $JAVA_CMDS; do
|
---|
73 | if [ -x "$jcmd" ] && [ -z "${JAVACMD}" ]; then
|
---|
74 | JAVACMD="$jcmd"
|
---|
75 | break
|
---|
76 | fi
|
---|
77 | done
|
---|
78 | fi
|
---|
79 |
|
---|
80 | if [ "$JAVACMD" ]; then
|
---|
81 | echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
|
---|
82 | JAVA_VERSION=$(java_version "${JAVACMD}")
|
---|
83 | JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
|
---|
84 | JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
|
---|
85 | if [[ "${JAVA_VERSION}" -ge 11 ]]; then
|
---|
86 | JAVA_OPTS="--module-path ${JAVAFX_HOME} --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
|
---|
87 | JAVA_OPTS="$JAVA_OPTS --add-exports=java.base/sun.security.action=ALL-UNNAMED"
|
---|
88 | JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED"
|
---|
89 | JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED"
|
---|
90 | elif [[ "${JAVA_VERSION}" -ge 9 ]]; then
|
---|
91 | JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
|
---|
92 | fi
|
---|
93 | set +e
|
---|
94 | while true; do
|
---|
95 | # shellcheck disable=SC2086
|
---|
96 | $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
|
---|
97 | if [ "z$?" != "z9" ]; then
|
---|
98 | break
|
---|
99 | fi
|
---|
100 | echo ">> restarting josm..."
|
---|
101 | done
|
---|
102 | else
|
---|
103 | echo "No valid JVM found to run JOSM." || true
|
---|
104 | exit 1
|
---|
105 | fi
|
---|