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