Skip to content

Commit 2573f87

Browse files
authored
Merge pull request #123 from arduino/per1234/install-script
Add release installation support
2 parents 78a99c7 + ca03ece commit 2573f87

File tree

7 files changed

+338
-0
lines changed

7 files changed

+338
-0
lines changed

Diff for: .github/workflows/check-formatting.yml

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ jobs:
3939
- name: Check Go code formatting
4040
run: task go:check-formatting
4141

42+
- name: Check shell script formatting
43+
# https://github.com/mvdan/sh
44+
run: |
45+
docker run --volume "$GITHUB_WORKSPACE/libraries/spell-check":/mnt --workdir /mnt mvdan/shfmt:latest -w .
46+
git diff --color --exit-code
47+
4248
- name: Check documentation formatting
4349
run: task docs:check-formatting
4450

Diff for: .github/workflows/lint-shell.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint shell scripts
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/workflows/lint-shell.yml"
7+
- "**.sh"
8+
pull_request:
9+
paths:
10+
- ".github/workflows/lint-shell.yml"
11+
- "**.sh"
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
21+
- name: Install Taskfile
22+
uses: arduino/actions/setup-taskfile@master
23+
with:
24+
repo-token: ${{ secrets.GITHUB_TOKEN }}
25+
version: 3.x
26+
27+
- name: Lint shell scripts
28+
run: task shell:lint

Diff for: Taskfile.yml

+19
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,25 @@ tasks:
203203
cmds:
204204
- npx {{ .PRETTIER }} --write "**/*.md"
205205

206+
shell:lint:
207+
desc: Lint shell scripts
208+
cmds:
209+
# https://github.com/koalaman/shellcheck
210+
- |
211+
shopt -s globstar # Needed to check all scripts recursively.
212+
shellcheck ./**/*.sh
213+
214+
shell:check-formatting:
215+
desc: Format shell scripts
216+
cmds:
217+
# https://github.com/mvdan/sh#shfmt
218+
- shfmt -d .
219+
220+
shell:format:
221+
desc: Format shell scripts
222+
cmds:
223+
- shfmt -l -w .
224+
206225
config:check:
207226
desc: Lint and check formatting of configuration files
208227
cmds:

Diff for: docs/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Its focus is on the structure, metadata, and configuration of Arduino projects,
55
[specification](https://arduino.github.io/arduino-cli/latest/library-specification) compliance, Library Manager
66
submission [requirements](https://github.com/arduino/Arduino/wiki/Library-Manager-FAQ), and best practices.
77

8+
## Installation
9+
10+
See the [installation instructions](installation.md).
11+
812
## Getting started
913

1014
Once installed, you only need to open a terminal at your project folder and run the command:

Diff for: docs/installation.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## Use the install script
2+
3+
The script requires `sh`, which is always available on Linux and macOS. `sh` is not available by default on Windows. The
4+
script can be run on Windows by installing [Git for Windows](https://gitforwindows.org/), then running it from Git Bash.
5+
6+
This script will install the latest version of arduino-lint to `$PWD/bin`:
7+
8+
```
9+
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | sh
10+
```
11+
12+
If you want to target a different directory, for example `~/local/bin`, set the `BINDIR` environment variable like this:
13+
14+
```
15+
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | BINDIR=~/local/bin sh
16+
```
17+
18+
If you would like to use the `arduino-lint` command from any location, install arduino-lint to a directory already in
19+
your `PATH` or add the arduino-lint installation path to your `PATH` environment variable.
20+
21+
If you want to download a specific arduino-lint version, for example `0.9.0`, pass the version number as a parameter
22+
like this:
23+
24+
```
25+
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | sh -s 0.9.0
26+
```
27+
28+
### Download
29+
30+
Pre-built binaries for all the supported platforms are available for download from the links below.
31+
32+
If you would like to use the `arduino-lint` command from any location, extract the downloaded file to a directory
33+
already in your `PATH` or add the arduino-lint installation path to your `PATH` environment variable.
34+
35+
#### Latest release
36+
37+
| Platform | | |
38+
| --------- | -------------------- | -------------------- |
39+
| Linux | [32 bit][linux32] | [64 bit][linux64] |
40+
| Linux ARM | [32 bit][linuxarm32] | [64 bit][linuxarm64] |
41+
| Windows | [32 bit][windows32] | [64 bit][windows64] |
42+
| macOS | | [64 bit][macos] |
43+
44+
[linux64]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Linux_64bit.tar.gz
45+
[linux32]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Linux_32bit.tar.gz
46+
[linuxarm64]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Linux_ARM64.tar.gz
47+
[linuxarm32]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Linux_ARMv7.tar.gz
48+
[windows64]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Windows_64bit.zip
49+
[windows32]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_Windows_32bit.zip
50+
[macos]: https://downloads.arduino.cc/arduino-lint/arduino-lint_latest_macOS_64bit.tar.gz
51+
52+
#### Previous versions
53+
54+
These are available from the "Assets" sections on the [releases page](https://github.com/arduino/arduino-lint/releases).
55+
56+
`https://downloads.arduino.cc/arduino-lint/nightly/nightly-<DATE>-checksums.txt`
57+
58+
### Build from source
59+
60+
If you’re familiar with Golang or if you want to contribute to the project, you will probably build arduino-lint locally
61+
with your Go toolchain. See the ["How to contribute"](CONTRIBUTING.md#building-the-source-code) page for instructions.

Diff for: etc/install.sh

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#!/bin/sh
2+
3+
# The original version of this script (https://github.com/Masterminds/glide.sh/blob/master/get) is licensed under the
4+
# MIT license. See https://github.com/Masterminds/glide/blob/master/LICENSE for more details and copyright notice.
5+
6+
#
7+
# Usage:
8+
#
9+
# To install the latest version of arduino-lint:
10+
# ./install.sh
11+
#
12+
# To pin a specific release of arduino-lint:
13+
# ./install.sh 0.9.0
14+
#
15+
16+
PROJECT_OWNER="arduino"
17+
PROJECT_NAME="arduino-lint"
18+
19+
# BINDIR represents the local bin location, defaults to ./bin.
20+
EFFECTIVE_BINDIR=""
21+
DEFAULT_BINDIR="$PWD/bin"
22+
23+
fail() {
24+
echo "$1"
25+
exit 1
26+
}
27+
28+
initDestination() {
29+
if [ -n "$BINDIR" ]; then
30+
if [ ! -d "$BINDIR" ]; then
31+
# The second instance of $BINDIR is intentionally a literal in this message.
32+
# shellcheck disable=SC2016
33+
fail "$BINDIR "'($BINDIR)'" folder not found. Please create it before continuing."
34+
fi
35+
EFFECTIVE_BINDIR="$BINDIR"
36+
else
37+
if [ ! -d "$DEFAULT_BINDIR" ]; then
38+
mkdir "$DEFAULT_BINDIR"
39+
fi
40+
EFFECTIVE_BINDIR="$DEFAULT_BINDIR"
41+
fi
42+
echo "Installing in $EFFECTIVE_BINDIR"
43+
}
44+
45+
initArch() {
46+
ARCH=$(uname -m)
47+
case $ARCH in
48+
armv5*) ARCH="armv5" ;;
49+
armv6*) ARCH="ARMv6" ;;
50+
armv7*) ARCH="ARMv7" ;;
51+
aarch64) ARCH="ARM64" ;;
52+
x86) ARCH="32bit" ;;
53+
x86_64) ARCH="64bit" ;;
54+
i686) ARCH="32bit" ;;
55+
i386) ARCH="32bit" ;;
56+
esac
57+
echo "ARCH=$ARCH"
58+
}
59+
60+
initOS() {
61+
OS=$(uname -s)
62+
case "$OS" in
63+
Linux*) OS='Linux' ;;
64+
Darwin*) OS='macOS' ;;
65+
MINGW*) OS='Windows' ;;
66+
MSYS*) OS='Windows' ;;
67+
esac
68+
echo "OS=$OS"
69+
}
70+
71+
initDownloadTool() {
72+
if command -v "curl" >/dev/null 2>&1; then
73+
DOWNLOAD_TOOL="curl"
74+
elif command -v "wget" >/dev/null 2>&1; then
75+
DOWNLOAD_TOOL="wget"
76+
else
77+
fail "You need curl or wget as download tool. Please install it first before continuing"
78+
fi
79+
echo "Using $DOWNLOAD_TOOL as download tool"
80+
}
81+
82+
checkLatestVersion() {
83+
# Use the GitHub releases webpage to find the latest version for this project
84+
# so we don't get rate-limited.
85+
CHECKLATESTVERSION_REGEX="[0-9][A-Za-z0-9\.-]*"
86+
CHECKLATESTVERSION_LATEST_URL="https://github.com/${PROJECT_OWNER}/${PROJECT_NAME}/releases/latest"
87+
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
88+
CHECKLATESTVERSION_TAG=$(curl -SsL $CHECKLATESTVERSION_LATEST_URL | grep -o "<title>Release $CHECKLATESTVERSION_REGEX · ${PROJECT_OWNER}/${PROJECT_NAME}" | grep -o "$CHECKLATESTVERSION_REGEX")
89+
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
90+
CHECKLATESTVERSION_TAG=$(wget -q -O - $CHECKLATESTVERSION_LATEST_URL | grep -o "<title>Release $CHECKLATESTVERSION_REGEX · ${PROJECT_OWNER}/${PROJECT_NAME}" | grep -o "$CHECKLATESTVERSION_REGEX")
91+
fi
92+
if [ "x$CHECKLATESTVERSION_TAG" = "x" ]; then
93+
echo "Cannot determine latest tag."
94+
exit 1
95+
fi
96+
eval "$1='$CHECKLATESTVERSION_TAG'"
97+
}
98+
99+
get() {
100+
GET_URL="$2"
101+
echo "Getting $GET_URL"
102+
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
103+
GET_HTTP_RESPONSE=$(curl -sL --write-out 'HTTPSTATUS:%{http_code}' "$GET_URL")
104+
GET_HTTP_STATUS_CODE=$(echo "$GET_HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
105+
GET_BODY=$(echo "$GET_HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
106+
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
107+
TMP_FILE=$(mktemp)
108+
GET_BODY=$(wget --server-response --content-on-error -q -O - "$GET_URL" 2>"$TMP_FILE" || true)
109+
GET_HTTP_STATUS_CODE=$(awk '/^ HTTP/{print $2}' "$TMP_FILE")
110+
fi
111+
if [ "$GET_HTTP_STATUS_CODE" != 200 ]; then
112+
echo "Request failed with HTTP status code $GET_HTTP_STATUS_CODE"
113+
fail "Body: $GET_BODY"
114+
fi
115+
eval "$1='$GET_BODY'"
116+
}
117+
118+
getFile() {
119+
GETFILE_URL="$1"
120+
GETFILE_FILE_PATH="$2"
121+
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
122+
GETFILE_HTTP_STATUS_CODE=$(curl -s -w '%{http_code}' -L "$GETFILE_URL" -o "$GETFILE_FILE_PATH")
123+
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
124+
wget --server-response --content-on-error -q -O "$GETFILE_FILE_PATH" "$GETFILE_URL"
125+
GETFILE_HTTP_STATUS_CODE=$(awk '/^ HTTP/{print $2}' "$TMP_FILE")
126+
fi
127+
echo "$GETFILE_HTTP_STATUS_CODE"
128+
}
129+
130+
downloadFile() {
131+
if [ -z "$1" ]; then
132+
checkLatestVersion TAG
133+
else
134+
TAG=$1
135+
fi
136+
# arduino-lint_0.4.0-rc1_Linux_64bit.[tar.gz, zip]
137+
if [ "$OS" = "Windows" ]; then
138+
ARDUINO_LINT_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.zip"
139+
else
140+
ARDUINO_LINT_DIST="${PROJECT_NAME}_${TAG}_${OS}_${ARCH}.tar.gz"
141+
fi
142+
DOWNLOAD_URL="https://downloads.arduino.cc/${PROJECT_NAME}/${ARDUINO_LINT_DIST}"
143+
ARDUINO_LINT_TMP_FILE="/tmp/$ARDUINO_LINT_DIST"
144+
echo "Downloading $DOWNLOAD_URL"
145+
httpStatusCode=$(getFile "$DOWNLOAD_URL" "$ARDUINO_LINT_TMP_FILE")
146+
if [ "$httpStatusCode" -ne 200 ]; then
147+
echo "Did not find a release for your system: $OS $ARCH"
148+
echo "Trying to find a release using the GitHub API."
149+
LATEST_RELEASE_URL="https://api.github.com/repos/${PROJECT_OWNER}/$PROJECT_NAME/releases/tags/$TAG"
150+
echo "LATEST_RELEASE_URL=$LATEST_RELEASE_URL"
151+
get LATEST_RELEASE_JSON "$LATEST_RELEASE_URL"
152+
# || true forces this command to not catch error if grep does not find anything
153+
DOWNLOAD_URL=$(echo "$LATEST_RELEASE_JSON" | grep 'browser_' | cut -d\" -f4 | grep "$ARDUINO_LINT_DIST") || true
154+
if [ -z "$DOWNLOAD_URL" ]; then
155+
echo "Sorry, we dont have a dist for your system: $OS $ARCH"
156+
fail "You can request one here: https://github.com/${PROJECT_OWNER}/$PROJECT_NAME/issues"
157+
else
158+
echo "Downloading $DOWNLOAD_URL"
159+
getFile "$DOWNLOAD_URL" "$ARDUINO_LINT_TMP_FILE"
160+
fi
161+
fi
162+
}
163+
164+
installFile() {
165+
ARDUINO_LINT_TMP="/tmp/$PROJECT_NAME"
166+
mkdir -p "$ARDUINO_LINT_TMP"
167+
if [ "$OS" = "Windows" ]; then
168+
unzip -d "$ARDUINO_LINT_TMP" "$ARDUINO_LINT_TMP_FILE"
169+
else
170+
tar xf "$ARDUINO_LINT_TMP_FILE" -C "$ARDUINO_LINT_TMP"
171+
fi
172+
ARDUINO_LINT_TMP_BIN="$ARDUINO_LINT_TMP/$PROJECT_NAME"
173+
cp "$ARDUINO_LINT_TMP_BIN" "$EFFECTIVE_BINDIR"
174+
rm -rf "$ARDUINO_LINT_TMP"
175+
rm -f "$ARDUINO_LINT_TMP_FILE"
176+
}
177+
178+
bye() {
179+
BYE_RESULT=$?
180+
if [ "$BYE_RESULT" != "0" ]; then
181+
echo "Failed to install $PROJECT_NAME"
182+
fi
183+
exit $BYE_RESULT
184+
}
185+
186+
testVersion() {
187+
set +e
188+
ARDUINO_LINT="$(which $PROJECT_NAME)"
189+
if [ "$?" = "1" ]; then
190+
# $PATH is intentionally a literal in this message.
191+
# shellcheck disable=SC2016
192+
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
193+
else
194+
# Convert to resolved, absolute paths before comparison
195+
ARDUINO_LINT_REALPATH="$(cd -- "$(dirname -- "$ARDUINO_LINT")" && pwd -P)"
196+
EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)"
197+
if [ "$ARDUINO_LINT_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then
198+
# shellcheck disable=SC2016
199+
echo "An existing $PROJECT_NAME was found at $ARDUINO_LINT. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one."
200+
fi
201+
fi
202+
203+
set -e
204+
ARDUINO_LINT_VERSION="$("$EFFECTIVE_BINDIR/$PROJECT_NAME" --version)"
205+
echo "$ARDUINO_LINT_VERSION installed successfully in $EFFECTIVE_BINDIR"
206+
}
207+
208+
# Execution
209+
210+
#Stop execution on any error
211+
trap "bye" EXIT
212+
initDestination
213+
set -e
214+
initArch
215+
initOS
216+
initDownloadTool
217+
downloadFile "$1"
218+
installFile
219+
testVersion

Diff for: mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ markdown_extensions:
4646
# Navigation
4747
nav:
4848
- Documentation Home: index.md
49+
- installation.md
4950
- Command reference: commands/arduino-lint.md
5051
- CONTRIBUTING.md
5152

0 commit comments

Comments
 (0)