From b0646d3350b9df16552ecdda69acda0ea0ac6d2e Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 21:36:02 -0700 Subject: [PATCH 1/6] Use POSIX approach to get effective executable path in install script The installation script checks the path of the effective executable after installing the application. If it is different from the installation path, it warns the user. Previously, the external tool `which` was used for this purpose. This is a violation of ShellCheck rule C2230, which results in an error with the version of ShellCheck installed in the GitHub Actions runner (0.7.0). The installation script is intended to use POSIX standard tools where possible in order to be as portable as possible. The recommended replacement `command -v` works equally as well for this particular application, so there is no reason not to make the change recommended by ShellCheck. Reference: https://github.com/koalaman/shellcheck/wiki/SC2230 --- etc/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/install.sh b/etc/install.sh index 920ab003..470cd17e 100755 --- a/etc/install.sh +++ b/etc/install.sh @@ -195,7 +195,7 @@ bye() { testVersion() { set +e - ARDUINO_LINT="$(which $PROJECT_NAME)" + ARDUINO_LINT="$(command -v $PROJECT_NAME)" if [ "$?" = "1" ]; then # $PATH is intentionally a literal in this message. # shellcheck disable=SC2016 From 973d6d8788c09d055c79f75ccbdb0e8290e8c38b Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 21:36:40 -0700 Subject: [PATCH 2/6] Add source comments to installation assets These are intended to facilitate syncing fixes and improvements to the templates in either direction. --- docs/installation.md | 2 ++ etc/install.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/installation.md b/docs/installation.md index 99dc8c63..38abc67a 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,3 +1,5 @@ + + ## Use the install script The script requires `sh`, which is always available on Linux and macOS. `sh` is not available by default on Windows. The diff --git a/etc/install.sh b/etc/install.sh index 470cd17e..4706fc04 100755 --- a/etc/install.sh +++ b/etc/install.sh @@ -1,4 +1,5 @@ #!/bin/sh +# Source: https://github.com/arduino/tooling-project-assets/blob/main/other/installation-script/install.sh # The original version of this script (https://github.com/Masterminds/glide.sh/blob/master/get) is licensed under the # MIT license. See https://github.com/Masterminds/glide/blob/master/LICENSE for more details and copyright notice. From 9bc86dfdd37a0f0a24af70b1f3adb74983924e5c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 21:37:37 -0700 Subject: [PATCH 3/6] Remove usage instructions from installation script This content has multiple issues: - Contains project-specific references - Outdated (doesn't mention BINDIR) Since it needs to be modified one way or the other and we already have documentation of the script in installation.md, I think it's best to remove this altogether to avoid the need to maintain two copies of the documentation, and the likelihood that it will not be maintained. --- etc/install.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/etc/install.sh b/etc/install.sh index 4706fc04..98e872d4 100755 --- a/etc/install.sh +++ b/etc/install.sh @@ -4,16 +4,6 @@ # The original version of this script (https://github.com/Masterminds/glide.sh/blob/master/get) is licensed under the # MIT license. See https://github.com/Masterminds/glide/blob/master/LICENSE for more details and copyright notice. -# -# Usage: -# -# To install the latest version of Arduino Lint: -# ./install.sh -# -# To pin a specific release of Arduino Lint: -# ./install.sh 0.9.0 -# - PROJECT_OWNER="arduino" PROJECT_NAME="arduino-lint" From 3edc9f60d34db25b750aa444578de97bed4e8250 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 21:39:20 -0700 Subject: [PATCH 4/6] Replace project-specific variable names in template install script Variable names made reference to the specific project the script originated from. This is not appropriate now that the installation script is intended to be used for any project. This is a pure refactoring without any functional effect. --- etc/install.sh | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/etc/install.sh b/etc/install.sh index 98e872d4..2e50e92d 100755 --- a/etc/install.sh +++ b/etc/install.sh @@ -126,24 +126,24 @@ downloadFile() { fi # arduino-lint_0.4.0-rc1_Linux_64bit.[tar.gz, zip] if [ "$OS" = "Windows" ]; then - ARDUINO_LINT_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.zip" + APPLICATION_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.zip" else - ARDUINO_LINT_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.tar.gz" + APPLICATION_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.tar.gz" fi # Support specifying nightly build versions (e.g., "nightly-latest") via the script argument. case "$TAG" in nightly*) - DOWNLOAD_URL="https://downloads.arduino.cc/${PROJECT_NAME}/nightly/${ARDUINO_LINT_DIST}" + DOWNLOAD_URL="https://downloads.arduino.cc/${PROJECT_NAME}/nightly/${APPLICATION_DIST}" ;; *) - DOWNLOAD_URL="https://downloads.arduino.cc/${PROJECT_NAME}/${ARDUINO_LINT_DIST}" + DOWNLOAD_URL="https://downloads.arduino.cc/${PROJECT_NAME}/${APPLICATION_DIST}" ;; esac - ARDUINO_LINT_TMP_FILE="/tmp/$ARDUINO_LINT_DIST" + INSTALLATION_TMP_FILE="/tmp/$APPLICATION_DIST" echo "Downloading $DOWNLOAD_URL" - httpStatusCode=$(getFile "$DOWNLOAD_URL" "$ARDUINO_LINT_TMP_FILE") + httpStatusCode=$(getFile "$DOWNLOAD_URL" "$INSTALLATION_TMP_FILE") if [ "$httpStatusCode" -ne 200 ]; then echo "Did not find a release for your system: $OS $ARCH" echo "Trying to find a release using the GitHub API." @@ -151,29 +151,29 @@ downloadFile() { echo "LATEST_RELEASE_URL=$LATEST_RELEASE_URL" get LATEST_RELEASE_JSON "$LATEST_RELEASE_URL" # || true forces this command to not catch error if grep does not find anything - DOWNLOAD_URL=$(echo "$LATEST_RELEASE_JSON" | grep 'browser_' | cut -d\" -f4 | grep "$ARDUINO_LINT_DIST") || true + DOWNLOAD_URL=$(echo "$LATEST_RELEASE_JSON" | grep 'browser_' | cut -d\" -f4 | grep "$APPLICATION_DIST") || true if [ -z "$DOWNLOAD_URL" ]; then echo "Sorry, we dont have a dist for your system: $OS $ARCH" fail "You can request one here: https://github.com/${PROJECT_OWNER}/$PROJECT_NAME/issues" else echo "Downloading $DOWNLOAD_URL" - getFile "$DOWNLOAD_URL" "$ARDUINO_LINT_TMP_FILE" + getFile "$DOWNLOAD_URL" "$INSTALLATION_TMP_FILE" fi fi } installFile() { - ARDUINO_LINT_TMP="/tmp/$PROJECT_NAME" - mkdir -p "$ARDUINO_LINT_TMP" + INSTALLATION_TMP_DIR="/tmp/$PROJECT_NAME" + mkdir -p "$INSTALLATION_TMP_DIR" if [ "$OS" = "Windows" ]; then - unzip -d "$ARDUINO_LINT_TMP" "$ARDUINO_LINT_TMP_FILE" + unzip -d "$INSTALLATION_TMP_DIR" "$INSTALLATION_TMP_FILE" else - tar xf "$ARDUINO_LINT_TMP_FILE" -C "$ARDUINO_LINT_TMP" + tar xf "$INSTALLATION_TMP_FILE" -C "$INSTALLATION_TMP_DIR" fi - ARDUINO_LINT_TMP_BIN="$ARDUINO_LINT_TMP/$PROJECT_NAME" - cp "$ARDUINO_LINT_TMP_BIN" "$EFFECTIVE_BINDIR" - rm -rf "$ARDUINO_LINT_TMP" - rm -f "$ARDUINO_LINT_TMP_FILE" + INSTALLATION_TMP_BIN="$INSTALLATION_TMP_DIR/$PROJECT_NAME" + cp "$INSTALLATION_TMP_BIN" "$EFFECTIVE_BINDIR" + rm -rf "$INSTALLATION_TMP_DIR" + rm -f "$INSTALLATION_TMP_FILE" } bye() { @@ -186,24 +186,24 @@ bye() { testVersion() { set +e - ARDUINO_LINT="$(command -v $PROJECT_NAME)" + 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 # Convert to resolved, absolute paths before comparison - ARDUINO_LINT_REALPATH="$(cd -- "$(dirname -- "$ARDUINO_LINT")" && pwd -P)" + EXECUTABLE_REALPATH="$(cd -- "$(dirname -- "$EXECUTABLE_PATH")" && pwd -P)" EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)" - if [ "$ARDUINO_LINT_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then + if [ "$EXECUTABLE_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then # shellcheck disable=SC2016 - echo "An existing $PROJECT_NAME was found at $ARDUINO_LINT. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one." + echo "An existing $PROJECT_NAME was found at $EXECUTABLE_PATH. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one." fi fi set -e - ARDUINO_LINT_VERSION="$("$EFFECTIVE_BINDIR/$PROJECT_NAME" --version)" - echo "$ARDUINO_LINT_VERSION installed successfully in $EFFECTIVE_BINDIR" + APPLICATION_VERSION="$("$EFFECTIVE_BINDIR/$PROJECT_NAME" --version)" + echo "$APPLICATION_VERSION installed successfully in $EFFECTIVE_BINDIR" } # Execution From 1cb66c76323ab7289b0497e80d349dfd60eca1e7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 31 Jul 2021 21:40:15 -0700 Subject: [PATCH 5/6] Remove obsolete x-prefix from installation script comparison From https://github.com/koalaman/shellcheck/wiki/SC2268 > Some older shells would get confused if the first argument started with a dash, or consisted of ! or (. As a > workaround, people would prefix variables and values to be compared with x to ensure the left-hand side always started > with an alphanumeric character. > > POSIX ensures this is not necessary, and all modern shells now follow suite. This obsolete practice is used by the template installation script in a comparison of the release's Git tag name. Since it would be extremely unusual to start a tag name with any of these characters (or impossible in the case of `-`, since it is prohibited by Git), it's unlikely this would be necessary even in the days when this bug was prevalent in shells. In addition, this bug was fixed quite some years ago, making it unlikely that it even exists on any user's system. So this practice makes the script code more complex without providing any real benefit. Since it is a violation of ShellCheck rule SC2268 and causing a CI failure, it is best to just remove it. --- etc/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/install.sh b/etc/install.sh index 2e50e92d..b22629f1 100755 --- a/etc/install.sh +++ b/etc/install.sh @@ -80,7 +80,7 @@ checkLatestVersion() { elif [ "$DOWNLOAD_TOOL" = "wget" ]; then CHECKLATESTVERSION_TAG=$(wget -q -O - $CHECKLATESTVERSION_LATEST_URL | grep -o "Release $CHECKLATESTVERSION_REGEX · ${PROJECT_OWNER}/${PROJECT_NAME}" | grep -o "$CHECKLATESTVERSION_REGEX") fi - if [ "x$CHECKLATESTVERSION_TAG" = "x" ]; then + if [ "$CHECKLATESTVERSION_TAG" = "" ]; then echo "Cannot determine latest tag." exit 1 fi From 403b8f41e982ca007bc835f0961c63a0e2efa929 Mon Sep 17 00:00:00 2001 From: per1234 <accounts@perglass.com> Date: Sat, 31 Jul 2021 21:43:55 -0700 Subject: [PATCH 6/6] Replace inappropriate character in install docs A "right single quotation mark" (U+2019) somehow ended up being used as an apostrophe in the installation instructions. --- docs/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index 38abc67a..2dd46125 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -83,5 +83,5 @@ Checksums for the nightly builds are available at ### Build from source -If you’re familiar with Golang or if you want to contribute to the project, you will probably build Arduino Lint locally +If you're familiar with Golang or if you want to contribute to the project, you will probably build Arduino Lint locally with your Go toolchain. See the ["How to contribute"](CONTRIBUTING.md#building-the-source-code) page for instructions.