source: josm/trunk/native/linux/tested/usr/bin/josm

Last change on this file was 19234, checked in by taylor.smock, 2 months ago

Fix #23951: Fix free in startup linux scripts when it is in a localized environment

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1#!/bin/bash
2# Simple wrapper script used to start JOSM in Debian
3set -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
7if [ -e "/etc/alternatives/java" ]; then
8 ALTERNATIVE_JDK=$(readlink -n -f /etc/alternatives/java)
9fi
10
11if [ -v JAVA_HOME ]; then
12 JAVA_CMDS="$JAVA_HOME/bin/java"
13else
14 JAVA_CMDS=""
15fi
16
17dpkg_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
43java_version() {
44 ${1} -version 2>&1 | head -n1 | awk -F'"' '{print $2}' | awk -F'.' '{print $1}'
45}
46
47if dpkg --version > /dev/null 2>&1; then
48 dpkg_java
49fi
50
51# Undetermined version
52JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/default-java/bin/java /usr/bin/java"
53JOSM_VERSION="josm"
54
55if [ -f "/etc/default/${JOSM_VERSION}" ]; then
56 # shellcheck source=/etc/default/josm
57 . "/etc/default/${JOSM_VERSION}"
58fi
59
60# If there is more than 8G ram, we can use up to 75% of the memory while still leaving 2G for other things.
61if [ "$(LC_ALL=C LANG=C free --mega | grep '^Mem:' | awk '{print $2}')" -gt 8192 ]; then
62 # But don't set anything if JAVA_OPTS is already set.
63 JAVA_OPTS="${JAVA_OPTS:=-XX:MaxRAMPercentage=75.0 -Xms256m}"
64fi
65
66JAVA_OPTS="-Djosm.restart=true -Djava.net.useSystemProxies=true $JAVA_OPTS"
67
68if [ -z "${JAVACMD}" ] && [ -n "${ALTERNATIVE_JDK}" ]; then
69 for jcmd in $JAVA_CMDS; do
70 if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ] && [ -x "$jcmd" ]; then
71 JAVACMD="$jcmd"
72 break
73 fi
74 done
75fi
76
77if [ -z "${JAVACMD}" ]; then
78 for jcmd in $JAVA_CMDS; do
79 if [ -x "$jcmd" ] && [ -z "${JAVACMD}" ]; then
80 JAVACMD="$jcmd"
81 break
82 fi
83 done
84fi
85
86if [ "$JAVACMD" ]; then
87 echo "Using $JAVACMD to execute ${JOSM_VERSION}." || true
88 JAVA_VERSION=$(java_version "${JAVACMD}")
89 JAVAFX_HOME="${JAVAFX_HOME:-/usr/share/openjfx/lib}"
90 JOSM_PATH="${JOSM_PATH:-/usr/share/${JOSM_VERSION}/${JOSM_VERSION}.jar}"
91 if [[ "${JAVA_VERSION}" -ge 11 ]]; then
92 JAVA_OPTS="--module-path ${JAVAFX_HOME} --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web $JAVA_OPTS"
93 JAVA_OPTS="$JAVA_OPTS --add-exports=java.base/sun.security.action=ALL-UNNAMED"
94 JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED"
95 JAVA_OPTS="$JAVA_OPTS --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED"
96 elif [[ "${JAVA_VERSION}" -ge 9 ]]; then
97 JAVA_OPTS="--add-modules java.activation,java.se.ee $JAVA_OPTS"
98 fi
99 set +e
100 while true; do
101 # shellcheck disable=SC2086
102 $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"
103 if [ "z$?" != "z9" ]; then
104 break
105 fi
106 echo ">> restarting josm..."
107 done
108else
109 echo "No valid JVM found to run JOSM." || true
110 exit 1
111fi
Note: See TracBrowser for help on using the repository browser.