#!/usr/bin/bash # Simple wrapper script used to start JOSM in Debian set -e # First, the alternative (if known to work) or users preference as defined by $JAVA_HOME. Next, use OpenJDK. # Override to a specific one using $JAVACMD ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java || true) if [ -v JAVA_HOME ]; then JAVA_CMDS="$JAVA_HOME/bin/java" else JAVA_CMDS="" fi dpkg_java() { # Let's get the current architecture -- needed for multiarchified Java ARCH=$(dpkg --print-architecture 2> /dev/null || true) # If OpenJDK is only available headless, do not try it if dpkg --get-selections "openjdk-*-jre" | grep install$ > /dev/null \ || dpkg --get-selections "openjdk-*-jre:$ARCH" | grep install$ > /dev/null ; then # LTS versions in decreased order JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java" # Released versions in decreased order JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java" JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java" # Development version(s) JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-19-openjdk/bin/java /usr/lib/jvm/java-19-openjdk-$ARCH/bin/java" fi } java_version() { ${1} -version 2>&1 | head -n1 | awk '{print $3}' | awk -F'.' '{gsub(/"/, ""); print $1}' | cat } if [ -x "$(command -v dpkg)" ]; then dpkg_java fi # Undetermined version JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java" JOSM_VERSION="josm-latest" if [ -f "/etc/default/${JOSM_VERSION}" ]; then . "/etc/default/${JOSM_VERSION}" fi JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=\"${JOSM_VERSION}\" -Djava.net.useSystemProxies=true $JAVA_OPTS" if [ -z "${JAVACMD}" ]; then for jcmd in $JAVA_CMDS; do if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then JAVACMD="$jcmd" break fi done fi if [ -z "${JAVACMD}" ]; then for jcmd in $JAVA_CMDS; do if [ -x "$jcmd" ] && [ -z "${JAVACMD}" ]; then JAVACMD="$jcmd" break fi done fi if [ "$JAVACMD" ]; then echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true JAVA_VERSION=$(java_version ${JAVACMD}) JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}" JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}" if [[ "${JAVA_VERSION}" -ge 11 ]]; then JAVA_OPTS="--module-path ${JAVAFX_HOME} --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS" JAVA_OPTS="$JAVA_OPTS --add-exports=java.base/sun.security.action=ALL-UNNAMED" JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED" JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED" elif [[ "${JAVA_VERSION}" -ge 9 ]]; then JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS" fi set +e while true; do $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@" if [ "z$?" != "z9" ]; then break fi echo ">> restarting josm..." done else echo "No valid JVM found to run JOSM." || true exit 1 fi