From b9fe0aed8732409b79d08c5998ee768186ce5558 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 14 Aug 2019 13:14:15 +0200 Subject: [PATCH 1/3] do not hit github api to get latest version --- install.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index df49d2d546a..ee645b00b57 100755 --- a/install.sh +++ b/install.sh @@ -67,6 +67,23 @@ 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 latest_url="https://github.com/arduino/arduino-cli/releases/latest" + if [ "$DOWNLOAD_TOOL" = "curl" ]; then + tag=$(curl -SsL $latest_url | grep -oP "Release \K([A-Za-z0-9\.-]*)(?= · arduino/arduino-cli)") + elif [ "$DOWNLOAD_TOOL" = "wget" ]; then + tag=$(wget -q -O - $latest_url | grep -oP "Release \K([A-Za-z0-9\.-]*)(?= · arduino/arduino-cli)") + fi + if [ "x$tag" == "x" ]; then + echo "Cannot determine latest tag." + exit 1 + fi + eval "$1='$tag'" +} + get() { local url="$2" local body @@ -101,8 +118,9 @@ 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"])') + # Use the GitHub releases webpage to find the latest version for this project + # so we don't get rate-limited. + checkLatestVersion TAG https://github.com/arduino/arduino-cli/releases/latest echo "TAG=$TAG" # arduino-cli_0.4.0-rc1_Linux_64bit.[tar.gz, zip] if [ "$OS" == "Windows" ]; then From 29eb7c3149f9e4b07d7f66ca1a91f4b05c7707f0 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 14 Aug 2019 13:17:22 +0200 Subject: [PATCH 2/3] do not repeat the same comment --- install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/install.sh b/install.sh index ee645b00b57..cb10ea24591 100755 --- a/install.sh +++ b/install.sh @@ -118,8 +118,6 @@ getFile() { } downloadFile() { - # Use the GitHub releases webpage to find the latest version for this project - # so we don't get rate-limited. checkLatestVersion TAG https://github.com/arduino/arduino-cli/releases/latest echo "TAG=$TAG" # arduino-cli_0.4.0-rc1_Linux_64bit.[tar.gz, zip] From b99534c572b1606f5a3b8aab02c46fd02939b37c Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 14 Aug 2019 15:32:14 +0200 Subject: [PATCH 3/3] don't use PCRE --- install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index cb10ea24591..0e6460cea14 100755 --- a/install.sh +++ b/install.sh @@ -71,11 +71,12 @@ 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 -oP "Release \K([A-Za-z0-9\.-]*)(?= · arduino/arduino-cli)") + 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 -oP "Release \K([A-Za-z0-9\.-]*)(?= · arduino/arduino-cli)") + 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." @@ -118,7 +119,7 @@ getFile() { } downloadFile() { - checkLatestVersion TAG https://github.com/arduino/arduino-cli/releases/latest + checkLatestVersion TAG echo "TAG=$TAG" # arduino-cli_0.4.0-rc1_Linux_64bit.[tar.gz, zip] if [ "$OS" == "Windows" ]; then