Skip to content

Commit

Permalink
Merge pull request #9 from mbenabda/bugfix/github_rate_limit_on_install
Browse files Browse the repository at this point in the history
[fix #8] do not use the github API to figure out the download url fora given version of the plugin to prevent hitting github API's rate limit
  • Loading branch information
mbenabda authored Feb 10, 2019
2 parents 85cd1c0 + 9b5f835 commit 688b54d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions install-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 688b54d

Please sign in to comment.