From 69b844cb13ed91f9ed3b426d56d73fd879d44416 Mon Sep 17 00:00:00 2001 From: leogtzr Date: Mon, 1 Jan 2018 05:37:30 -0400 Subject: [PATCH 1/2] Fix shellcheck warnings in CLI's bash script See gh-11458 --- .../src/main/executablecontent/bin/spring | 88 +++++++++++-------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring index 21ba6a064b..0b34be8a3d 100755 --- a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring +++ b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring @@ -1,9 +1,9 @@ #!/usr/bin/env bash # OS specific support (must be 'true' or 'false'). -cygwin=false; -darwin=false; -case "`uname`" in +cygwin=false +darwin=false +case "$(uname)" in CYGWIN*) cygwin=true ;; @@ -18,42 +18,57 @@ case "`uname`" in esac # For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +if ${cygwin} ; then + [ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}") fi # Attempt to find JAVA_HOME if not already set if [ -z "${JAVA_HOME}" ]; then - if $darwin ; then - [ -z "$JAVA_HOME" -a -f "/usr/libexec/java_home" ] && export JAVA_HOME=`/usr/libexec/java_home` - [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home" - [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" + if ${darwin} ; then + if [[ -z "${JAVA_HOME}" && -f "/usr/libexec/java_home" ]]; then + JAVA_HOME=$(/usr/libexec/java_home) + export JAVA_HOME + fi + if [[ -z "${JAVA_HOME}" && -d "/Library/Java/Home" ]]; then + export JAVA_HOME="/Library/Java/Home" + fi + if [[ -z "${JAVA_HOME}" && -d "/System/Library/Frameworks/JavaVM.framework/Home" ]]; then + export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" + fi else - javaExecutable="`which javac`" - [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && echo "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." && exit 1 + javaExecutable="$(which javac)" + if [[ -z "$javaExecutable" || "$(expr "${javaExecutable}" : '\([^ ]*\)')" = "no" ]]; then + echo "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." + exit 1 + fi # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && echo "JAVA_HOME not set and readlink not available, please set JAVA_HOME." && exit 1 - javaExecutable="`readlink -f \"$javaExecutable\"`" - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" + readLink=(which readlink) + [ $(expr "$readLink" : '\([^ ]*\)') = "no" ] && { + echo "JAVA_HOME not set and readlink not available, please set JAVA_HOME." + exit 1 + } + javaExecutable="$(readlink -f "${javaExecutable}")" + javaHome="$(dirname "${javaExecutable}")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="${javaHome}" export JAVA_HOME fi fi # Sanity check that we have java if [ ! -f "${JAVA_HOME}/bin/java" ]; then - echo "" - echo "======================================================================================================" - echo " Please ensure that your JAVA_HOME points to a valid Java SDK." - echo " You are currently pointing to:" - echo "" - echo " ${JAVA_HOME}" - echo "" - echo " This does not seem to be valid. Please rectify and restart." - echo "======================================================================================================" - echo "" + cat <<-JAVA_HOME_NOT_SET_TXT + + ====================================================================================================== + Please ensure that your JAVA_HOME points to a valid Java SDK. + You are currently pointing to: + + ${JAVA_HOME} + + This does not seem to be valid. Please rectify and restart. + ====================================================================================================== + + JAVA_HOME_NOT_SET_TXT exit 1 fi @@ -63,17 +78,18 @@ if [ -z "${SPRING_HOME}" ]; then PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') if expr "$link" : '/.*' > /dev/null; then PRG="$link" else - PRG=`dirname "$PRG"`"/$link" + PRG=$(dirname "$PRG")"/$link" fi done - SAVED="`pwd`" - cd "`dirname \"$PRG\"`/../" >&- - export SPRING_HOME="`pwd -P`" + SAVED="$(pwd)" + cd "$(dirname "${PRG}")/../" >&- + SPRING_HOME="$(pwd -P)" + export SPRING_HOME cd "$SAVED" >&- fi @@ -84,7 +100,7 @@ if [ ! -d "${SPRING_HOME}" ]; then fi CLASSPATH=.:${SPRING_HOME}/bin -if [ -d ${SPRING_HOME}/ext ]; then +if [ -d "${SPRING_HOME}/ext" ]; then CLASSPATH=$CLASSPATH:${SPRING_HOME}/ext fi for f in ${SPRING_HOME}/lib/*; do @@ -92,8 +108,8 @@ for f in ${SPRING_HOME}/lib/*; do done if $cygwin; then - SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + SPRING_HOME=$(cygpath --path --mixed "$SPRING_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") fi "${JAVA_HOME}/bin/java" ${JAVA_OPTS} -cp "$CLASSPATH" org.springframework.boot.loader.JarLauncher "$@" From fcc73c6d88586ff83b97f89728221302172a3f95 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 2 Oct 2018 16:42:19 +0100 Subject: [PATCH 2/2] Polish "Fix shellcheck warnings in CLI's bash script" Closes gh-11458 --- .../src/main/executablecontent/bin/spring | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring index 0b34be8a3d..3411a395a4 100755 --- a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring +++ b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring @@ -29,21 +29,21 @@ if [ -z "${JAVA_HOME}" ]; then JAVA_HOME=$(/usr/libexec/java_home) export JAVA_HOME fi - if [[ -z "${JAVA_HOME}" && -d "/Library/Java/Home" ]]; then + if [[ -z "${JAVA_HOME}" && -d "/Library/Java/Home" ]]; then export JAVA_HOME="/Library/Java/Home" fi if [[ -z "${JAVA_HOME}" && -d "/System/Library/Frameworks/JavaVM.framework/Home" ]]; then export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" fi else - javaExecutable="$(which javac)" + javaExecutable="$(command -v javac)" if [[ -z "$javaExecutable" || "$(expr "${javaExecutable}" : '\([^ ]*\)')" = "no" ]]; then echo "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." exit 1 fi # readlink(1) is not available as standard on Solaris 10. - readLink=(which readlink) - [ $(expr "$readLink" : '\([^ ]*\)') = "no" ] && { + readLink="$(command -v readlink)" + [ "$(expr "${readLink}" : '\([^ ]*\)')" = "no" ] && { echo "JAVA_HOME not set and readlink not available, please set JAVA_HOME." exit 1 } @@ -58,39 +58,39 @@ fi # Sanity check that we have java if [ ! -f "${JAVA_HOME}/bin/java" ]; then cat <<-JAVA_HOME_NOT_SET_TXT - + ====================================================================================================== Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: - + ${JAVA_HOME} - + This does not seem to be valid. Please rectify and restart. ====================================================================================================== - + JAVA_HOME_NOT_SET_TXT exit 1 fi # Attempt to find SPRING_HOME if not already set if [ -z "${SPRING_HOME}" ]; then - # Resolve links: $0 may be a link - PRG="$0" - # Need this for relative symlinks. - while [ -h "$PRG" ] ; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=$(dirname "$PRG")"/$link" - fi - done - SAVED="$(pwd)" - cd "$(dirname "${PRG}")/../" >&- - SPRING_HOME="$(pwd -P)" - export SPRING_HOME - cd "$SAVED" >&- + # Resolve links: $0 may be a link + PRG="$0" + # Need this for relative symlinks. + while [ -h "$PRG" ] ; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi + done + SAVED="$(pwd)" + cd "$(dirname "${PRG}")/../" >&- || exit 1 + SPRING_HOME="$(pwd -P)" + export SPRING_HOME + cd "$SAVED" >&- || exit 1 fi if [ ! -d "${SPRING_HOME}" ]; then @@ -103,7 +103,7 @@ CLASSPATH=.:${SPRING_HOME}/bin if [ -d "${SPRING_HOME}/ext" ]; then CLASSPATH=$CLASSPATH:${SPRING_HOME}/ext fi -for f in ${SPRING_HOME}/lib/*; do +for f in "${SPRING_HOME}"/lib/*; do CLASSPATH=$CLASSPATH:$f done @@ -112,4 +112,5 @@ if $cygwin; then CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") fi -"${JAVA_HOME}/bin/java" ${JAVA_OPTS} -cp "$CLASSPATH" org.springframework.boot.loader.JarLauncher "$@" +IFS=" " read -r -a javaOpts <<< "$JAVA_OPTS" +"${JAVA_HOME}/bin/java" "${javaOpts[@]}" -cp "$CLASSPATH" org.springframework.boot.loader.JarLauncher "$@" \ No newline at end of file