Skip to content

Commit

Permalink
Do not hit github api to get latest version from install script (#347)
Browse files Browse the repository at this point in the history
* do not hit github api to get latest version

* don't use PCRE
  • Loading branch information
masci committed Aug 19, 2019
1 parent dd6f633 commit 37a8e5e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions install.sh
Expand Up @@ -67,6 +67,24 @@ initDownloadTool() {
echo "Using $DOWNLOAD_TOOL as download tool"
}

checkLatestVersion() {
# Use the GitHub releases webpage to find the latest version for this project
# so we don't get rate-limited.
local tag
local regex="[0-9][A-Za-z0-9\.-]*"
local latest_url="https://github.com/arduino/arduino-cli/releases/latest"
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
tag=$(curl -SsL $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
tag=$(wget -q -O - $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
fi
if [ "x$tag" == "x" ]; then
echo "Cannot determine latest tag."
exit 1
fi
eval "$1='$tag'"
}

get() {
local url="$2"
local body
Expand Down Expand Up @@ -101,8 +119,7 @@ getFile() {
}

downloadFile() {
get TAG_JSON https://api.github.com/repos/arduino/arduino-cli/releases/latest
TAG=$(echo $TAG_JSON | python -c 'import json,sys;obj=json.load(sys.stdin, strict=False);sys.stdout.write(obj["tag_name"])')
checkLatestVersion TAG
echo "TAG=$TAG"
# arduino-cli_0.4.0-rc1_Linux_64bit.[tar.gz, zip]
if [ "$OS" == "Windows" ]; then
Expand Down

0 comments on commit 37a8e5e

Please sign in to comment.