From c15290f320dfa5fc6431b4f1f9b9b371430c9583 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 20 Dec 2021 06:51:05 -0800 Subject: [PATCH] Fix install script's check for previous installation The installation script checks for an existing installation in the PATH in order to provide appropriate advice to the user about adding the installation to their their PATH environment variable. This check is done using `command -v`. It turns out that the exit status is shell dependent in the event the command is not found, so that it might be either 1 or 127 depending on the user's system. The script previously assumed that the exit status would be 1 when the command was not found in PATH, which resulted in spurious advice under these conditions: ``` An existing arduino-cli was found at . Please prepend "/home/foo/arduino-cli/bin" to your $PATH or remove the existing one. ``` It seems safest to fix this by inverting the logic so that the advice about an existing installation in PATH is only printed when one was found. --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index f2c0711732c..08df803294c 100755 --- a/install.sh +++ b/install.sh @@ -186,19 +186,19 @@ bye() { testVersion() { set +e - EXECUTABLE_PATH="$(command -v $PROJECT_NAME)" - if [ "$?" = "1" ]; then - # $PATH is intentionally a literal in this message. - # shellcheck disable=SC2016 - echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH' - else + if EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"; then # Convert to resolved, absolute paths before comparison EXECUTABLE_REALPATH="$(cd -- "$(dirname -- "$EXECUTABLE_PATH")" && pwd -P)" EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)" if [ "$EXECUTABLE_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then + # $PATH is intentionally a literal in this message. # shellcheck disable=SC2016 echo "An existing $PROJECT_NAME was found at $EXECUTABLE_PATH. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one." fi + else + # $PATH is intentionally a literal in this message. + # shellcheck disable=SC2016 + echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH' fi set -e