Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conjugateprior/7305f205496c078ead9d9d9d52266fe8 to your computer and use it in GitHub Desktop.
Save conjugateprior/7305f205496c078ead9d9d9d52266fe8 to your computer and use it in GitHub Desktop.
A clunky bit of bash to download binaries for the latest release of a private Github repository
#!/usr/bin/env bash
read -p "GitHub username: " username
read -s -p "GitHub password: " password
echo
read -p "Github repository name: " repo
up="$username:$password"
ur="$username/$repo"
# get latest release info
curl -s -u "$up" https://api.github.com/repos/${ur}/releases/latest > latest_resp
# url for each asset
cat latest_resp | grep '"url": "https:.*releases/assets' | cut -d : -f 2,3 | tr -d '[\",]' > asset_url
# filename for each asset (this assumes we want only the zip files)
cat latest_resp | grep '"name":.*zip' | cut -d : -f 2,3 | tr -d '[\",]' > asset_name
# download each one
paste asset_url asset_name > asset_info
while IFS=$'\t' read -r -a Arr
do
echo 'Downloading' ${Arr[1]}
curl -L -s -H "Accept: application/octet-stream" -u ${up} ${Arr[0]} > ${Arr[1]}
done < "asset_info"
# clean up
rm latest_resp asset_url asset_name asset_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment