Skip to content

Instantly share code, notes, and snippets.

@rbf
Created September 14, 2015 10:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rbf/a3a8c9509407ef46a8d1 to your computer and use it in GitHub Desktop.
Save rbf/a3a8c9509407ef46a8d1 to your computer and use it in GitHub Desktop.
Small script to download the binary of a release using curl.
# You can inspect the release by `tag` before to get the URL of the first asset.
# API_DOC: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
# The you can download the release asset file (not the API object) by including the header 'Accept: application/octet-stream'
# NOTE: When downloading the binary file, don't forget to specify the name of the downloaded file (with -o <filename>).
# Otherwise the binary will be streamed into the terminal, doing weird unexpected things.
# API_DOC: https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
#
# Everything put together gives that script:
GITHUB_OWNER=twbs
GITHUB_REPO=bootstrap
GITHUB_TAG=v3.3.5
GITHUB_ASSET_FILENAME=bootstrap-3.3.5-dist.zip
GITHUB_TOKEN=$GITHUB_TOKEN # Necessary only for private repos
GITHUB_ASSET_ID=$(curl -sSL https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases/tags/${GITHUB_TAG}?access_token=${GITHUB_TOKEN} | grep -B 1 "\"name\": \"${GITHUB_ASSET_FILENAME}\"" | head -1 | sed 's/.*"id": \(.*\),/\1/')
curl -L https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases/assets/${GITHUB_ASSET_ID}?access_token=${GITHUB_TOKEN} -o ${GITHUB_ASSET_FILENAME} -H 'Accept: application/octet-stream'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment