Skip to content

Commit 45b0ef0

Browse files
committed
Fix install script's check for previous installation
The "template" installation script stored in this repository 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-lint was found at . Please prepend "/home/runner/work/tooling-project-assets/tooling-project-assets/bin" to your $PATH or remove the existing one. ``` It seems safest to invert the logic so that the advice about an existing installation in PATH is only printed when one was found.
1 parent b1c82a3 commit 45b0ef0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

other/installation-script/install.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,19 @@ bye() {
187187
testVersion() {
188188
set +e
189189
EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"
190-
if [ "$?" = "1" ]; then
191-
# $PATH is intentionally a literal in this message.
192-
# shellcheck disable=SC2016
193-
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
194-
else
190+
if [ "$?" = "0" ]; then
195191
# Convert to resolved, absolute paths before comparison
196192
EXECUTABLE_REALPATH="$(cd -- "$(dirname -- "$EXECUTABLE_PATH")" && pwd -P)"
197193
EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)"
198194
if [ "$EXECUTABLE_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then
195+
# $PATH is intentionally a literal in this message.
199196
# shellcheck disable=SC2016
200197
echo "An existing $PROJECT_NAME was found at $EXECUTABLE_PATH. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one."
201198
fi
199+
else
200+
# $PATH is intentionally a literal in this message.
201+
# shellcheck disable=SC2016
202+
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
202203
fi
203204

204205
set -e

0 commit comments

Comments
 (0)