Changeset 18515 in josm for trunk


Ignore:
Timestamp:
2022-07-12T19:41:48+02:00 (2 years ago)
Author:
taylor.smock
Message:

Improve josm launchers (patch by sebastic)

Patch notes from sebastic, modified. See #22193.

  • Use /bin/bash instead of /usr/bin/env bash usrmerge systems have both /bin/bash and /usr/bin/bash, non-usrmerge systems only have /bin/bash. Distributions that have differing behaviors between /bin/bash and /usr/bin/bash should update/fix their version of bash.
  • Set ALTERNATIVE_JDK only if /etc/alternatives/java exists. While not only Debian based distributions use the alternatives system, not all distributions do.
  • Use 4 spaces for indentation consistently. Some indentation used tabs, others 2 spaces.
  • Simplify java_version function.
  • Don't use command -v to test whether dpkg is available. The command may be an alias which results in output like:

dpkg is aliased to 'd*-p*-k*-g*'

  • Fix issues reported by shellcheck. SC2086 is disabled for $JAVA_OPTS because that only works unquoted.
Location:
trunk/native/linux
Files:
2 edited

Legend:

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

    r18512 r18515  
    1 #!/usr/bin/env bash
     1#!/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 || true)
     7if [ -e "/etc/alternatives/java" ]; then
     8    ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
     9fi
    810
    911if [ -v JAVA_HOME ]; then
     
    1416
    1517dpkg_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
     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-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
     25        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
     26        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
     27        # Released versions in decreased order
     28        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
     29        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
     30        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
     31        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
     32        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
     33        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
     34        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
     35        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
     36        # Development version(s)
     37        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-19-openjdk/bin/java /usr/lib/jvm/java-19-openjdk-$ARCH/bin/java"
     38    fi
    3739}
    3840
    3941java_version() {
    40   ${1} -version 2>&1 | head -n1 | awk '{print $3}' | awk -F'.' '{gsub(/"/, ""); print $1}' | cat
     42    ${1} -version 2>&1 | head -n1 | awk -F'"' '{print $2}' | awk -F'.' '{print $1}'
    4143}
    4244
    43 if [ -x "$(command -v dpkg)" ]; then
    44         dpkg_java
     45if dpkg --version > /dev/null 2>&1; then
     46    dpkg_java
    4547fi
     48
    4649# Undetermined version
    4750JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
     
    4952
    5053if [ -f "/etc/default/${JOSM_VERSION}" ]; then
     54    # shellcheck source=/etc/default/josm-latest
    5155    . "/etc/default/${JOSM_VERSION}"
    5256fi
     
    5458JAVA_OPTS="-Djosm.restart=true -Djosm.dir.name=JOSM-latest -Djava.net.useSystemProxies=true $JAVA_OPTS"
    5559
    56 if [ -z "${JAVACMD}" ]; then
     60if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
    5761    for jcmd in $JAVA_CMDS; do
    5862        if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
     
    7478if [ "$JAVACMD" ]; then
    7579    echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
    76     JAVA_VERSION=$(java_version ${JAVACMD})
     80    JAVA_VERSION=$(java_version "${JAVACMD}")
    7781    JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
    7882    JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
     
    8791    set +e
    8892    while true; do
     93        # shellcheck disable=SC2086
    8994        $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
    9095        if [ "z$?" != "z9" ]; then
  • trunk/native/linux/tested/usr/bin/josm

    r18512 r18515  
    1 #!/usr/bin/env bash
     1#!/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 || true)
     7if [ -e "/etc/alternatives/java" ]; then
     8    ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
     9fi
    810
    911if [ -v JAVA_HOME ]; then
     
    1416
    1517dpkg_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
     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-17-openjdk/bin/java /usr/lib/jvm/java-17-openjdk-$ARCH/bin/java"
     25        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-11-openjdk/bin/java /usr/lib/jvm/java-11-openjdk-$ARCH/bin/java"
     26        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk/bin/java /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
     27        # Released versions in decreased order
     28        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-18-openjdk/bin/java /usr/lib/jvm/java-18-openjdk-$ARCH/bin/java"
     29        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-16-openjdk/bin/java /usr/lib/jvm/java-16-openjdk-$ARCH/bin/java"
     30        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-15-openjdk/bin/java /usr/lib/jvm/java-15-openjdk-$ARCH/bin/java"
     31        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-14-openjdk/bin/java /usr/lib/jvm/java-14-openjdk-$ARCH/bin/java"
     32        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-13-openjdk/bin/java /usr/lib/jvm/java-13-openjdk-$ARCH/bin/java"
     33        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-12-openjdk/bin/java /usr/lib/jvm/java-12-openjdk-$ARCH/bin/java"
     34        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk/bin/java /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
     35        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk/bin/java /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
     36        # Development version(s)
     37        JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-19-openjdk/bin/java /usr/lib/jvm/java-19-openjdk-$ARCH/bin/java"
     38    fi
    3739}
    3840
    3941java_version() {
    40   ${1} -version 2>&1 | head -n1 | awk '{print $3}' | awk -F'.' '{gsub(/"/, ""); print $1}' | cat
     42    ${1} -version 2>&1 | head -n1 | awk -F'"' '{print $2}' | awk -F'.' '{print $1}'
    4143}
    4244
    43 if [ -x "$(command -v dpkg)" ]; then
    44         dpkg_java
     45if dpkg --version > /dev/null 2>&1; then
     46    dpkg_java
    4547fi
     48
    4649# Undetermined version
    4750JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
     
    4952
    5053if [ -f "/etc/default/${JOSM_VERSION}" ]; then
     54    # shellcheck source=/etc/default/josm
    5155    . "/etc/default/${JOSM_VERSION}"
    5256fi
     
    5458JAVA_OPTS="-Djosm.restart=true -Djava.net.useSystemProxies=true $JAVA_OPTS"
    5559
    56 if [ -z "${JAVACMD}" ]; then
     60if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
    5761    for jcmd in $JAVA_CMDS; do
    5862        if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
     
    7478if [ "$JAVACMD" ]; then
    7579    echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
    76     JAVA_VERSION=$(java_version ${JAVACMD})
     80    JAVA_VERSION=$(java_version "${JAVACMD}")
    7781    JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
    7882    JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
     
    8791    set +e
    8892    while true; do
     93        # shellcheck disable=SC2086
    8994        $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
    9095        if [ "z$?" != "z9" ]; then
Note: See TracChangeset for help on using the changeset viewer.