Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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