Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Last active April 9, 2020 23:03
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/11bc3f21f47e1a79d099 to your computer and use it in GitHub Desktop.
Save rtrouton/11bc3f21f47e1a79d099 to your computer and use it in GitHub Desktop.
Downloading the latest release of a project from GitHub
#!/bin/bash
# How to set these variables:
#
# GitHub_Owner
# GitHub_Repo
#
# Example use:
#
# The Linde Group has repos on GitHub available
# via https://github.com/lindegroup
# To set the Linde Group as the owner,
# set the following:
# GitHub_Owner="lindegroup"
#
# If you want to get the latest release of
# the Linde Group's AutoPkgr software, the
# repo which has AutoPkgr is named "autopkgr".
# The Linde Group has set up releases for AutoPkgr,
# so set the following:
# GitHub_Repo="autopkgr"
#
GitHub_Owner="repo_owner_goes_here"
GitHub_Repo="repo_name_goes_here"
# Specify a directory in /tmp to store the downloaded file
download_location=`/usr/bin/mktemp -d /tmp/$GitHub_Repo.XXXX`
GitHubProjectLatestRelease=$(/usr/bin/curl --silent https://api.github.com/repos/$GitHub_Owner/$GitHub_Repo/releases/latest | /usr/bin/awk '/browser_download_url/ { print $2 }' | /usr/bin/sed 's/"//g')
# Download latest release to the specified location in /tmp
cd $download_location;/usr/bin/curl -LOk "$GitHubProjectLatestRelease"
echo "Downloaded file is stored in $download_location."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment