Skip to content

Instantly share code, notes, and snippets.

@Andi-Lo
Created December 19, 2021 13:51
Show Gist options
  • Save Andi-Lo/7bb70f2de8f8c86dcaec6e3e5fb9f0f1 to your computer and use it in GitHub Desktop.
Save Andi-Lo/7bb70f2de8f8c86dcaec6e3e5fb9f0f1 to your computer and use it in GitHub Desktop.
Download and extract latest version of a Github repository using curl
#!/bin/bash
# Change to your needs
TARGET_FOLDER='./your-folder'
OWNER=''
REPOSITORY=''
mkdir -p $TARGET_FOLDER
echo "Querying Github for latest version..."
URL=$( curl -sLo /dev/null -w '%{url_effective}' https://github.com/$OWNER/$REPOSITORY/releases/latest )
echo "Found latest version: $VERSION"
# grep extracts semver version from url via regex
VERSION=$( echo $URL | grep -E -o "(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(\.(0|[1-9]\d*))?")
echo "Downloading..."
curl -LO https://github.com/$OWNER/$REPOSITORY/archive/refs/tags/$VERSION.tar.gz
echo "Extrating to $TARGET_FOLDER"
tar -xzf $VERSION.tar.gz -C $TARGET_FOLDER --strip-components=1
echo "Cleaning up... $VERSION.tar.gz"
rm -d -r -f $VERSION.tar.gz
echo "Success"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment