From fef225ca30a1dafb2b1606a1d12f0eedbef55849 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 17 May 2019 13:24:30 +0200 Subject: [PATCH] [platform] minor improvements in Unix startup script; fix for IDEA-212759 - corrects IDE_HOME/IDE_BIN_HOME handling on paths with spaces - fixes 'shellcheck' warnings - makes build script substitutions friendlier to 'shellcheck' GitOrigin-RevId: 51f1137b3cac80c16f7514fef6075e761f848356 --- .../impl/LinuxDistributionBuilder.groovy | 2 +- .../linux/scripts/executable-template.sh | 145 +++++++++--------- 2 files changed, 77 insertions(+), 70 deletions(-) diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LinuxDistributionBuilder.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LinuxDistributionBuilder.groovy index 6c04fc352451..21ca956c45db 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LinuxDistributionBuilder.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LinuxDistributionBuilder.groovy @@ -87,7 +87,7 @@ class LinuxDistributionBuilder extends OsSpecificDistributionBuilder { buildContext.ant.copy(todir: "${unixDistPath}/bin") { fileset(dir: "$buildContext.paths.communityHome/platform/build-scripts/resources/linux/scripts") - filterset(begintoken: "@@", endtoken: "@@") { + filterset(begintoken: "__", endtoken: "__") { filter(token: "product_full", value: fullName) filter(token: "product_uc", value: buildContext.productProperties.getEnvironmentVariableBaseName(buildContext.applicationInfo)) filter(token: "vm_options", value: vmOptionsFileName) diff --git a/platform/build-scripts/resources/linux/scripts/executable-template.sh b/platform/build-scripts/resources/linux/scripts/executable-template.sh index 2cd2cb803ec9..463b648a836d 100755 --- a/platform/build-scripts/resources/linux/scripts/executable-template.sh +++ b/platform/build-scripts/resources/linux/scripts/executable-template.sh @@ -1,70 +1,72 @@ #!/bin/sh # # --------------------------------------------------------------------- -# @@product_full@@ startup script. +# __product_full__ startup script. # --------------------------------------------------------------------- # message() { - TITLE="Cannot start @@product_full@@" - if [ -n "`which zenity`" ]; then + TITLE="Cannot start __product_full__" + if [ -n "$(command -v zenity)" ]; then zenity --error --title="$TITLE" --text="$1" --no-wrap - elif [ -n "`which kdialog`" ]; then + elif [ -n "$(command -v kdialog)" ]; then kdialog --error "$1" --title "$TITLE" - elif [ -n "`which notify-send`" ]; then + elif [ -n "$(command -v notify-send)" ]; then notify-send "ERROR: $TITLE" "$1" - elif [ -n "`which xmessage`" ]; then + elif [ -n "$(command -v xmessage)" ]; then xmessage -center "ERROR: $TITLE: $1" else - printf "ERROR: $TITLE\n$1\n" + printf "ERROR: %s\n%s\n" "$TITLE" "$1" fi } -UNAME=`which uname` -GREP=`which egrep` -GREP_OPTIONS="" -CUT=`which cut` -READLINK=`which readlink` -XARGS=`which xargs` -DIRNAME=`which dirname` -MKTEMP=`which mktemp` -RM=`which rm` -CAT=`which cat` -SED=`which sed` +UNAME=$(command -v uname) +GREP=$(command -v egrep) +CUT=$(command -v cut) +READLINK=$(command -v readlink) +XARGS=$(command -v xargs) +DIRNAME=$(command -v dirname) +MKTEMP=$(command -v mktemp) +RM=$(command -v rm) +CAT=$(command -v cat) +SED=$(command -v sed) -if [ -z "$UNAME" -o -z "$GREP" -o -z "$CUT" -o -z "$DIRNAME" -o -z "$MKTEMP" -o -z "$RM" -o -z "$CAT" -o -z "$SED" ]; then +if [ -z "$UNAME" ] || [ -z "$GREP" ] || [ -z "$CUT" ] || [ -z "$DIRNAME" ] || [ -z "$MKTEMP" ] || [ -z "$RM" ] || [ -z "$CAT" ] || [ -z "$SED" ]; then message "Required tools are missing - check beginning of \"$0\" file for details." exit 1 fi -OS_TYPE=`"$UNAME" -s` +# shellcheck disable=SC2034 +GREP_OPTIONS='' +OS_TYPE=$("$UNAME" -s) # --------------------------------------------------------------------- # Ensure IDE_HOME points to the directory where the IDE is installed. # --------------------------------------------------------------------- -SCRIPT_LOCATION=$0 +SCRIPT_LOCATION="$0" if [ -x "$READLINK" ]; then while [ -L "$SCRIPT_LOCATION" ]; do - SCRIPT_LOCATION=`"$READLINK" -e "$SCRIPT_LOCATION"` + SCRIPT_LOCATION=$("$READLINK" -e "$SCRIPT_LOCATION") done fi -cd $(${DIRNAME} ${SCRIPT_LOCATION}) -IDE_BIN_HOME=`pwd` -IDE_HOME=$(${DIRNAME} ${IDE_BIN_HOME}) -cd ${OLDPWD} +cd "$("$DIRNAME" "$SCRIPT_LOCATION")" || exit 2 +IDE_BIN_HOME=$(pwd) +IDE_HOME=$("$DIRNAME" "$IDE_BIN_HOME") +cd "${OLDPWD}" || exit 2 # --------------------------------------------------------------------- -# Locate a JDK installation directory which will be used to run the IDE. -# Try (in order): @@product_uc@@_JDK, @@vm_options@@.jdk, ./jbr, ./jre64, JDK_HOME, JAVA_HOME, "java" in PATH. +# Locate a JDK installation directory command -v will be used to run the IDE. +# Try (in order): __product_uc___JDK, __vm_options__.jdk, ./jbr, ./jre64, JDK_HOME, JAVA_HOME, "java" in PATH. # --------------------------------------------------------------------- -if [ -n "$@@product_uc@@_JDK" -a -x "$@@product_uc@@_JDK/bin/java" ]; then - JDK="$@@product_uc@@_JDK" +# shellcheck disable=SC2154 +if [ -n "$__product_uc___JDK" ] && [ -x "$__product_uc___JDK/bin/java" ]; then + JDK="$__product_uc___JDK" fi -if [ -z "$JDK" -a -s "$HOME/.@@system_selector@@/config/@@vm_options@@.jdk" ]; then - USER_JRE=`"$CAT" $HOME/.@@system_selector@@/config/@@vm_options@@.jdk` +if [ -z "$JDK" ] && [ -s "$HOME/.__system_selector__/config/__vm_options__.jdk" ]; then + USER_JRE=$("$CAT" "$HOME/.__system_selector__/config/__vm_options__.jdk") if [ ! -d "$USER_JRE" ]; then USER_JRE="$IDE_HOME/$USER_JRE" fi @@ -73,7 +75,7 @@ if [ -z "$JDK" -a -s "$HOME/.@@system_selector@@/config/@@vm_options@@.jdk" ]; t fi fi -if [ -z "$JDK" -a "$OS_TYPE" = "Linux" ] ; then +if [ -z "$JDK" ] && [ "$OS_TYPE" = "Linux" ] ; then BUNDLED_JRE="$IDE_HOME/jbr" if [ ! -d "$BUNDLED_JRE" ]; then BUNDLED_JRE="$IDE_HOME/jre64" @@ -86,20 +88,21 @@ if [ -z "$JDK" -a "$OS_TYPE" = "Linux" ] ; then fi fi -if [ -z "$JDK" -a -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then +# shellcheck disable=SC2153 +if [ -z "$JDK" ] && [ -n "$JDK_HOME" ] && [ -x "$JDK_HOME/bin/java" ]; then JDK="$JDK_HOME" fi -if [ -z "$JDK" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then +if [ -z "$JDK" ] && [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then JDK="$JAVA_HOME" fi if [ -z "$JDK" ]; then - JDK_PATH=`which java` + JDK_PATH=$(command -v java) if [ -n "$JDK_PATH" ]; then - if [ "$OS_TYPE" = "FreeBSD" -o "$OS_TYPE" = "MidnightBSD" ]; then - JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-` + if [ "$OS_TYPE" = "FreeBSD" ] || [ "$OS_TYPE" = "MidnightBSD" ]; then + JAVA_LOCATION=$(JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-) if [ -x "$JAVA_LOCATION/bin/java" ]; then JDK="$JAVA_LOCATION" fi @@ -109,24 +112,24 @@ if [ -z "$JDK" ]; then JDK="$JAVA_LOCATION" fi elif [ "$OS_TYPE" = "Darwin" ]; then - JAVA_LOCATION=`/usr/libexec/java_home` + JAVA_LOCATION=$(/usr/libexec/java_home) if [ -x "$JAVA_LOCATION/bin/java" ]; then JDK="$JAVA_LOCATION" fi fi fi - if [ -z "$JDK" -a -n "$JDK_PATH" -a -x "$READLINK" -a -x "$XARGS" ]; then - JAVA_LOCATION=`"$READLINK" -f "$JDK_PATH"` + if [ -z "$JDK" ] && [ -n "$JDK_PATH" ] && [ -x "$READLINK" ] && [ -x "$XARGS" ]; then + JAVA_LOCATION=$("$READLINK" -f "$JDK_PATH") case "$JAVA_LOCATION" in */jre/bin/java) - JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"` + JAVA_LOCATION=$(echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME") if [ ! -d "$JAVA_LOCATION/bin" ]; then JAVA_LOCATION="$JAVA_LOCATION/jre" fi ;; *) - JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"` + JAVA_LOCATION=$(echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME") ;; esac if [ -x "$JAVA_LOCATION/bin/java" ]; then @@ -136,13 +139,13 @@ if [ -z "$JDK" ]; then fi JAVA_BIN="$JDK/bin/java" -if [ -z "$JDK" -o ! -x "$JAVA_BIN" ]; then - message "No JDK found. Please validate either @@product_uc@@_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation." +if [ -z "$JDK" ] || [ ! -x "$JAVA_BIN" ]; then + message "No JDK found. Please validate either __product_uc___JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation." exit 1 fi -VERSION_LOG=`"$MKTEMP" -t java.version.log.XXXXXX` -JAVA_TOOL_OPTIONS= "$JAVA_BIN" -version 2> "$VERSION_LOG" +VERSION_LOG=$("$MKTEMP" -t java.version.log.XXXXXX) +JAVA_TOOL_OPTIONS='' "$JAVA_BIN" -version 2> "$VERSION_LOG" "$GREP" "64-Bit|x86_64|amd64" "$VERSION_LOG" > /dev/null BITS=$? "$RM" -f "$VERSION_LOG" @@ -151,66 +154,70 @@ test ${BITS} -eq 0 && BITS="64" || BITS="" # --------------------------------------------------------------------- # Collect JVM options and IDE properties. # --------------------------------------------------------------------- -if [ -n "$@@product_uc@@_PROPERTIES" ]; then - IDE_PROPERTIES_PROPERTY="-Didea.properties.file=$@@product_uc@@_PROPERTIES" +# shellcheck disable=SC2154 +if [ -n "$__product_uc___PROPERTIES" ]; then + IDE_PROPERTIES_PROPERTY="-Didea.properties.file=$__product_uc___PROPERTIES" fi VM_OPTIONS_FILE="" -if [ -n "$@@product_uc@@_VM_OPTIONS" -a -r "$@@product_uc@@_VM_OPTIONS" ]; then +# shellcheck disable=SC2154 +if [ -n "$__product_uc___VM_OPTIONS" ] && [ -r "$__product_uc___VM_OPTIONS" ]; then # explicit - VM_OPTIONS_FILE="$@@product_uc@@_VM_OPTIONS" + VM_OPTIONS_FILE="$__product_uc___VM_OPTIONS" elif [ -r "$IDE_HOME.vmoptions" ]; then # Toolbox VM_OPTIONS_FILE="$IDE_HOME.vmoptions" -elif [ -r "$HOME/.@@system_selector@@/config/@@vm_options@@$BITS.vmoptions" ]; then +elif [ -r "$HOME/.__system_selector__/config/__vm_options__$BITS.vmoptions" ]; then # user-overridden - VM_OPTIONS_FILE="$HOME/.@@system_selector@@/config/@@vm_options@@$BITS.vmoptions" -elif [ -r "$IDE_BIN_HOME/@@vm_options@@$BITS.vmoptions" ]; then + VM_OPTIONS_FILE="$HOME/.__system_selector__/config/__vm_options__$BITS.vmoptions" +elif [ -r "$IDE_BIN_HOME/__vm_options__$BITS.vmoptions" ]; then # default, standard installation - VM_OPTIONS_FILE="$IDE_BIN_HOME/@@vm_options@@$BITS.vmoptions" + VM_OPTIONS_FILE="$IDE_BIN_HOME/__vm_options__$BITS.vmoptions" else # default, universal package test "$OS_TYPE" = "Darwin" && OS_SPECIFIC="mac" || OS_SPECIFIC="linux" - VM_OPTIONS_FILE="$IDE_BIN_HOME/$OS_SPECIFIC/@@vm_options@@$BITS.vmoptions" + VM_OPTIONS_FILE="$IDE_BIN_HOME/$OS_SPECIFIC/__vm_options__$BITS.vmoptions" fi VM_OPTIONS="" if [ -r "$VM_OPTIONS_FILE" ]; then - VM_OPTIONS=`"$CAT" "$VM_OPTIONS_FILE" | "$GREP" -v "^#.*"` - if { echo "$VM_OPTIONS" | "$GREP" -q "agentlib:yjpagent" - ; } then + VM_OPTIONS=$("$CAT" "$VM_OPTIONS_FILE" | "$GREP" -v "^#.*") + if { echo "$VM_OPTIONS" | "$GREP" -q "agentlib:yjpagent" - ; }; then if [ "$OS_TYPE" = "Linux" ]; then - VM_OPTIONS=`echo "$VM_OPTIONS" | "$SED" -e "s|-agentlib:yjpagent\(-linux\)\?\([^=]*\)|-agentpath:$IDE_BIN_HOME/libyjpagent-linux\2.so|"` + VM_OPTIONS=$(echo "$VM_OPTIONS" | "$SED" -e "s|-agentlib:yjpagent\(-linux\)\?\([^=]*\)|-agentpath:$IDE_BIN_HOME/libyjpagent-linux\2.so|") else - VM_OPTIONS=`echo "$VM_OPTIONS" | "$SED" -e "s|-agentlib:yjpagent[^ ]*||"` + VM_OPTIONS=$(echo "$VM_OPTIONS" | "$SED" -e "s|-agentlib:yjpagent[^ ]*||") fi fi else message "Cannot find VM options file" fi -@@class_path@@ -if [ -n "$@@product_uc@@_CLASSPATH" ]; then - CLASSPATH="$CLASSPATH:$@@product_uc@@_CLASSPATH" +__class_path__ +# shellcheck disable=SC2154 +if [ -n "$__product_uc___CLASSPATH" ]; then + CLASSPATH="$CLASSPATH:$__product_uc___CLASSPATH" fi # --------------------------------------------------------------------- # Run the IDE. # --------------------------------------------------------------------- -JAVA_ERR_LOG=`"$MKTEMP" -t java.error.log.XXXXXX` +JAVA_ERR_LOG=$("$MKTEMP" -t java.error.log.XXXXXX) IFS="$(printf '\n\t')" +# shellcheck disable=SC2086 "$JAVA_BIN" \ -classpath "$CLASSPATH" \ ${VM_OPTIONS} \ - "-XX:ErrorFile=$HOME/java_error_in_@@product_uc@@_%p.log" \ - "-XX:HeapDumpPath=$HOME/java_error_in_@@product_uc@@.hprof" \ - -Didea.paths.selector=@@system_selector@@ \ + "-XX:ErrorFile=$HOME/java_error_in___product_uc___%p.log" \ + "-XX:HeapDumpPath=$HOME/java_error_in___product_uc__.hprof" \ + -Didea.paths.selector=__system_selector__ \ "-Djb.vmOptionsFile=$VM_OPTIONS_FILE" \ ${IDE_PROPERTIES_PROPERTY} \ - @@ide_jvm_args@@ \ + __ide_jvm_args__ \ com.intellij.idea.Main \ "$@" 2> "$JAVA_ERR_LOG" EC=$? -if [ ${EC} -ne 0 -a -s "$JAVA_ERR_LOG" ]; then +if [ ${EC} -ne 0 ] && [ -s "$JAVA_ERR_LOG" ]; then message "$(cat "$JAVA_ERR_LOG")" fi rm -f "$JAVA_ERR_LOG"