Skip to content

Fix install script's check for previous installation #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2021
Merged

Fix install script's check for previous installation #189

merged 3 commits into from
Dec 20, 2021

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Dec 17, 2021

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:

https://github.com/arduino/tooling-project-assets/runs/4556007479?check_suite_focus=true#step:4:13

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 fix this by inverting the logic so that the advice about an existing installation in PATH is only printed when one was found.


Originally reported at https://forum.arduino.cc/t/failing-to-instlal-arduino-cli-on-raspberry/936871

The "template" installation script stored in this repository prints advice to the user about adding the installation to
their PATH environment variable.

This advice is adjusted according to whether a previous installation was found in the PATH and according to the path(s)
of their installation(s) so it is fairly complex. For this reason, it will be good to have a check in the
"Test install script" CI workflow to ensure the output is as expected.
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.
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 by checking the exit status of `command -v`. The previous use of `$?` for that check was unnecessary
since the command itself can be checked.

This change is required for compliance with ShellCheck rule SC2181:

https://github.com/koalaman/shellcheck/wiki/SC2181
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Dec 17, 2021
@per1234 per1234 self-assigned this Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants