Skip to content

Sync installation assets from template #217

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 6 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- Source: https://github.com/arduino/tooling-project-assets/blob/main/other/installation-script/installation.md -->

## 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
Expand Down Expand Up @@ -81,5 +83,5 @@ Checksums for the nightly builds are available at

### Build from source

If youre 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.
57 changes: 24 additions & 33 deletions etc/install.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#!/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.

#
# 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"

Expand Down Expand Up @@ -89,7 +80,7 @@ checkLatestVersion() {
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
CHECKLATESTVERSION_TAG=$(wget -q -O - $CHECKLATESTVERSION_LATEST_URL | grep -o "<title>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
Expand Down Expand Up @@ -135,54 +126,54 @@ 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."
LATEST_RELEASE_URL="https://api.github.com/repos/${PROJECT_OWNER}/$PROJECT_NAME/releases/tags/$TAG"
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() {
Expand All @@ -195,24 +186,24 @@ bye() {

testVersion() {
set +e
ARDUINO_LINT="$(which $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
Expand Down