From 9b5f8354b65690339a7edc07098a5039f48035f9 Mon Sep 17 00:00:00 2001 From: Mehdi BEN ABDALLAH Date: Sun, 10 Feb 2019 01:59:47 +0100 Subject: [PATCH] [fix #8] do not use the github API to figure out the download url for a given version of the plugin to prevent hitting github API's rate limit --- install-binary.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/install-binary.sh b/install-binary.sh index b8febd9..0a2d3c1 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -49,19 +49,19 @@ getDownloadURL() { exit 1 fi - local url="https://api.github.com/repos/${PROJECT_GH}/releases/latest" - local version=$(git describe --tags --exact-match 2>/dev/null) + local version=$(git describe --tags --exact-match 2>/dev/null | sed s/^v//) if [ -n "$version" ]; then - url="https://api.github.com/repos/${PROJECT_GH}/releases/tags/${version}" - fi + DOWNLOAD_URL="https://github.com/${PROJECT_GH}/releases/download/v${version}/${PROJECT_NAME}-${version}-${OS}-${ARCH}.tar.gz" + else + local url="https://api.github.com/repos/${PROJECT_GH}/releases/latest" - # Use the GitHub API to find the download url for this project. - if type "curl" > /dev/null; then - DOWNLOAD_URL=$(curl -v -s $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') - elif type "wget" > /dev/null; then - DOWNLOAD_URL=$(wget -q -O - $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + # Use the GitHub API to find the download url for this project. + if type "curl" > /dev/null; then + DOWNLOAD_URL=$(curl -v -s $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + elif type "wget" > /dev/null; then + DOWNLOAD_URL=$(wget -q -O - $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + fi fi - if ! echo "${DOWNLOAD_URL}" | grep -q "${OS}-${ARCH}"; then echo "No prebuilt binary for ${OS}-${ARCH}." exit 1 @@ -91,7 +91,7 @@ fail_trap() { result=$? if [ "$result" != "0" ]; then echo "Failed to install $PROJECT_NAME" - echo "\tFor support, go to https://github.com/${PROJECT_GH}." + echo "For support, go to https://github.com/${PROJECT_GH}." fi exit $result }