Skip to content

Commit e41e22d

Browse files
authored
[skip changelog] Improve install script's check for conflicting installation in $PATH (#822)
* Make install script's check for conflicting $PATH installation more reliable Previously, the comparison between the install script's target path and the path of an existing installation in $PATH could easily give a false positive, producing a spurious "An existing arduino-cli was found at..." error. The solution is to fully resolve the paths before comparing them. * Don't fail installation script when other installation in $PATH is detected Previously, when a different installation of Arduino CLI was detected in $PATH by the installation script, the error message "Failed to install arduino-cli" would be printed and the script would have exit status 1. It is wise that the script warns of this situation ("An existing arduino-cli was found at..."), but the "Failed to install arduino-cli" error message was misleading, since Arduino CLI was indeed installed. It is also incorrect to have an error exit status in this situation, since the user may intend to have multiple installations and provide the full path when using the new installation.
1 parent a2f63fb commit e41e22d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

install.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,13 @@ testVersion() {
191191
CLI="$(which $PROJECT_NAME)"
192192
if [ "$?" = "1" ]; then
193193
echo "$PROJECT_NAME not found. You might want to add "$LBINDIR" to your "'$PATH'
194-
elif [ $CLI != "$LBINDIR/$PROJECT_NAME" ]; then
195-
fail "An existing $PROJECT_NAME was found at $CLI. Please prepend "$LBINDIR" to your "'$PATH'" or remove the existing one."
194+
else
195+
# Convert to resolved, absolute paths before comparison
196+
CLI_REALPATH="$(cd -- "$(dirname -- "$CLI")" && pwd -P)"
197+
LBINDIR_REALPATH="$(cd -- "$LBINDIR" && pwd -P)"
198+
if [ "$CLI_REALPATH" != "$LBINDIR_REALPATH" ]; then
199+
echo "An existing $PROJECT_NAME was found at $CLI. Please prepend "$LBINDIR" to your "'$PATH'" or remove the existing one."
200+
fi
196201
fi
197202

198203
set -e

0 commit comments

Comments
 (0)