Changeset 18497 in josm for trunk/native


Ignore:
Timestamp:
2022-06-22T22:49:42+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #22088: Debian start script does not properly check if a path does not exist or is not executable

This also fixes #22157: java options from start script not passed

#22157 had two issues:

  1. The start script fell back to /bin/java, which did not allow for version information (we were using the path to java to get the version information)
  2. #!/bin/bash was not working properly

(1) was fixed in the patch for #22088, while (2) was a single-line change.

#22088 largely made the start scripts more portable, and some variables can be
overridden via environment variables.

  • JAVAFX_HOME (defaults to /usr/share/openjfx/lib)
  • JOSM_PATH (defaults to /usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar, with JOSM_VERSION being one of josm or josm-latest)
  • JAVA_VERSION is now parsed from $JAVACMD -version instead of the binary path
  • The JAVACMD should now always be executable
  • dpkg is no longer required, although it is still checked for, which allows us to prioritize specific Java versions
  • The differences between the josm-latest and josm binaries is 2 lines
Location:
trunk/native/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/native/linux/latest/usr/bin/josm-latest

    r18297 r18497  
    1 #!/bin/bash
     1#!/usr/bin/bash
    22# Simple wrapper script used to start JOSM in Debian
    33set -e
     
    55# First, the alternative (if known to work) or users preference as defined by $JAVA_HOME. Next, use OpenJDK.
    66# Override to a specific one using $JAVACMD
    7 ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
     7ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java || true)
    88
    9 # Let's get the current architecture -- needed for multiarchified Java
    10 ARCH=$(dpkg --print-architecture 2> /dev/null || true)
     9if [ -v JAVA_HOME ]; then
     10    JAVA_CMDS="$JAVA_HOME/bin/java"
     11else
     12    JAVA_CMDS=""
     13fi
    1114
    12 JAVA_CMDS="$JAVA_HOME/bin/java"
     15dpkg_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}
    1338
    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-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
    19         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
    20         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
    21         # Released versions in decreased order
    22         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
    23         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
    24         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
    25         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
    26         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
    27         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
    28         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
    29         # Development version(s)
    30         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
     39if [ -x "$(command -v dpkg)" ]; then
     40        dpkg_java
    3141fi
    3242# Undetermined version
    3343JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
     44JOSM_VERSION="josm-latest"
    3445
    35 if [ -f /etc/default/josm-latest ]; then
    36     . /etc/default/josm-latest
     46if [ -f "/etc/default/${JOSM_VERSION}" ]; then
     47    . "/etc/default/${JOSM_VERSION}"
    3748fi
    3849
    39 JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=JOSM-latest -Djava.net.useSystemProxies=true $JAVA_OPTS"
     50JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=\"${JOSM_VERSION}\" -Djava.net.useSystemProxies=true $JAVA_OPTS"
    4051
    4152if [ -z "${JAVACMD}" ]; then
    4253    for jcmd in $JAVA_CMDS; do
    43         if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ]; then
     54        if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
    4455            JAVACMD="$jcmd"
    4556            break
     
    5869
    5970if [ "$JAVACMD" ]; then
    60     echo "Using $JAVACMD to execute josm-latest." || true
    61     if [[ "${JAVACMD}" =~ 'java-9' ]] || [[ "${JAVACMD}" =~ 'java-10' ]]; then
    62         JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
    63     elif [[ "${JAVACMD}" =~ 'java-1' ]]; then
    64         JAVA_OPTS="--module-path /usr/share/openjfx/lib --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
     71    echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
     72    JAVA_VERSION="$(${JAVACMD} -version 2>&1 | head -n1 | awk '{print $3}' | awk -F'.' '{gsub(/"/, ""); print $1}')"
     73    JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
     74    JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
     75    if [[ "${JAVA_VERSION}" -ge 11 ]]; then
     76        JAVA_OPTS="--module-path ${JAVAFX_HOME} --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
    6577        JAVA_OPTS="$JAVA_OPTS --add-exports=java.base/sun.security.action=ALL-UNNAMED"
    6678        JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED"
    6779        JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED"
     80    elif [[ "${JAVA_VERSION}" -ge 9 ]]; then
     81        JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
    6882    fi
    6983    set +e
    7084    while true; do
    71         $JAVACMD $JAVA_OPTS -jar /usr/share/josm-latest/josm-latest.jar "$@"
     85        $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
    7286        if [ "z$?" != "z9" ]; then
    7387            break
  • trunk/native/linux/tested/usr/bin/josm

    r18297 r18497  
    1 #!/bin/bash
     1#!/usr/bin/bash
    22# Simple wrapper script used to start JOSM in Debian
    33set -e
     
    55# First, the alternative (if known to work) or users preference as defined by $JAVA_HOME. Next, use OpenJDK.
    66# Override to a specific one using $JAVACMD
    7 ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
     7ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java || true)
    88
    9 # Let's get the current architecture -- needed for multiarchified Java
    10 ARCH=$(dpkg --print-architecture 2> /dev/null || true)
     9if [ -v JAVA_HOME ]; then
     10    JAVA_CMDS="$JAVA_HOME/bin/java"
     11else
     12    JAVA_CMDS=""
     13fi
    1114
    12 JAVA_CMDS="$JAVA_HOME/bin/java"
     15dpkg_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}
    1338
    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-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
    19         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
    20         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
    21         # Released versions in decreased order
    22         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
    23         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
    24         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
    25         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
    26         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
    27         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
    28         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
    29         # Development version(s)
    30         JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
     39if [ -x "$(command -v dpkg)" ]; then
     40        dpkg_java
    3141fi
    3242# Undetermined version
    3343JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
     44JOSM_VERSION="josm"
    3445
    35 if [ -f /etc/default/josm ]; then
    36     . /etc/default/josm
     46if [ -f "/etc/default/${JOSM_VERSION}" ]; then
     47    . "/etc/default/${JOSM_VERSION}"
    3748fi
    3849
     
    4152if [ -z "${JAVACMD}" ]; then
    4253    for jcmd in $JAVA_CMDS; do
    43         if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ]; then
     54        if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
    4455            JAVACMD="$jcmd"
    4556            break
     
    5869
    5970if [ "$JAVACMD" ]; then
    60     echo "Using $JAVACMD to execute josm." || true
    61     if [[ "${JAVACMD}" =~ 'java-9' ]] || [[ "${JAVACMD}" =~ 'java-10' ]]; then
    62         JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
    63     elif [[ "${JAVACMD}" =~ 'java-1' ]]; then
    64         JAVA_OPTS="--module-path /usr/share/openjfx/lib --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
     71    echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
     72    JAVA_VERSION="$(${JAVACMD} -version 2>&1 | head -n1 | awk '{print $3}' | awk -F'.' '{gsub(/"/, ""); print $1}')"
     73    JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
     74    JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
     75    if [[ "${JAVA_VERSION}" -ge 11 ]]; then
     76        JAVA_OPTS="--module-path ${JAVAFX_HOME} --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
    6577        JAVA_OPTS="$JAVA_OPTS --add-exports=java.base/sun.security.action=ALL-UNNAMED"
    6678        JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED"
    6779        JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED"
     80    elif [[ "${JAVA_VERSION}" -ge 9 ]]; then
     81        JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
    6882    fi
    6983    set +e
    7084    while true; do
    71         $JAVACMD $JAVA_OPTS -jar /usr/share/josm/josm.jar "$@"
     85        $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
    7286        if [ "z$?" != "z9" ]; then
    7387            break
Note: See TracChangeset for help on using the changeset viewer.