Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steinwaywhw/a4cd19cda655b8249d908261a62687f8 to your computer and use it in GitHub Desktop.
Save steinwaywhw/a4cd19cda655b8249d908261a62687f8 to your computer and use it in GitHub Desktop.
One Liner to Download the Latest Release from Github Repo
  • Use curl to get the JSON response for the latest release
  • Use grep to find the line containing file URL
  • Use cut and tr to extract the URL
  • Use wget to download it
curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -
@Samueru-sama
Copy link

Better alternative that will work even if the json is pretty or not:

curl -s https://api.github.com/repos/jgm/pandoc/releases/latest | sed 's/[()",{}]/ /g; s/ /\n/g' | grep "https.*releases/download.*deb"

Using jq -c to turn the json compact and this is what happens:

Old:

curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \"
 https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb
 https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-arm64.deb


curl -s https://api.github.com/repos/jgm/pandoc/releases/latest | jq -c \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \"
https://api.github.com/repos/jgm/pandoc/releases/155373146,assets_url

Alternative:

curl -s https://api.github.com/repos/jgm/pandoc/releases/latest | sed 's/[()",{}]/ /g; s/ /\n/g' | grep "https.*releases/download.*deb"         
https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb
https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-arm64.deb

curl -s https://api.github.com/repos/jgm/pandoc/releases/latest | jq -c | sed 's/[()",{}]/ /g; s/ /\n/g' | grep "https.*releases/download.*deb"
https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb
https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-arm64.deb

Fedora 40 recently changed wget for wget2, and this causes github the send the json compact breaking scripts that were parsing it with grep.

I use gron when it is available, otherwise the sed tricks should work most of the time.

@motdotla
Copy link

This is it

wget https://github.com/aquasecurity/tfsec/releases/latest/download/tfsec-linux-amd64

this is the best solution. thank you @joshjohanning. everything else is unnecessarily complicated for users and could trip them up because of different shell versions and lack of installed libs like jq.

add in a bit of uname magic and all your users are good to go.

curl -L -o dotenvx.tar.gz "https://github.com/dotenvx/dotenvx/releases/latest/download/dotenvx-$(uname -s)-$(uname -m).tar.gz"
tar -xzf dotenvx.tar.gz
./dotenvx help

@bruteforks
Copy link

Since this gist is still very active, here's one I've made recently:

#!/usr/bin/env bash

# Fetch the latest release version
latest_version=$(curl -s https://api.github.com/repos/microsoft/vscode-js-debug/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')

# Remove the 'v' prefix from the version number
version=${latest_version#v}

# Construct the download URL
download_url="https://github.com/microsoft/vscode-js-debug/releases/download/${latest_version}/js-debug-dap-${latest_version}.tar.gz"

# Download the tar.gz file
curl -L -o "js-debug-dap-${version}.tar.gz" "$download_url"

@initiateit
Copy link

initiateit commented Jul 17, 2024

Just curl and grep:

curl -s https://api.github.com/repos/caddyserver/xcaddy/releases/latest | grep '"browser_download_url":' | grep 'amd64.deb' | grep -vE '(\.pem|\.sig)' | grep -o 'https://[^"]*'

https://github.com/caddyserver/xcaddy/releases/download/v0.4.2/xcaddy_0.4.2_linux_amd64.deb

curl -s https://api.github.com/repos/aptly-dev/aptly/releases/latest | grep '"browser_download_url":' | grep 'amd64.deb' | grep -o 'https://[^"]*'

https://github.com/aptly-dev/aptly/releases/download/v1.5.0/aptly_1.5.0_amd64.deb

My apologies if it borrows from other answers.

@adriangalilea
Copy link

dra is making huge strides in simplifying the download process.

@NiceGuyIT thanks for bringing it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment