Forked from illepic/private-github-release-download.sh
Created
April 29, 2016 19:00
-
-
Save bleeDev/f297a771415981f51cd8db59acd64180 to your computer and use it in GitHub Desktop.
Download the latest release binary from a private GitHub repo. (i.e. a .tar.gz that you have manually uploaded in a GitHub release). Update OAUTH_TOKEN, OWNER, REPO, FILE_NAME with your custom values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Authorize to GitHub to get the latest release tar.gz | |
# Requires: oauth token, https://help.github.com/articles/creating-an-access-token-for-command-line-use/ | |
# Requires: jq package to parse json | |
# Your oauth token goes here, see link above | |
OAUTH_TOKEN="34k234lk234lk2j3lk4j2l3k4j2kj3lk" | |
# Repo owner (user id) | |
OWNER="your-user-name" | |
# Repo name | |
REPO="the-repo-clean-name" | |
# The file name expected to download. This is deleted before curl pulls down a new one | |
FILE_NAME="file-you-are-downloading.tar.gz" | |
# Concatenate the values together for a | |
API_URL="https://$OAUTH_TOKEN:@api.github.com/repos/$OWNER/$REPO" | |
# Gets info on latest release, gets first uploaded asset url of a release | |
ASSET_ID=$(curl $API_URL/releases/latest | jq -r '.assets[0].id') | |
echo "Asset ID: $ASSET_ID" | |
# curl does not allow overwriting file from -O, nuke | |
rm -f $FILE_NAME | |
# curl: | |
# -O: Use name provided from endpoint | |
# -J: "Content Disposition" header, in this case "attachment" | |
# -L: Follow links, we actually get forwarded in this request | |
# -H "Accept: application/octet-stream": Tells api we want to dl the full binary | |
curl -O -J -L -H "Accept: application/octet-stream" "$API_URL/releases/assets/$ASSET_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment