Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanHerbert/04b554079ec8667fa6f0c7317f1d2343 to your computer and use it in GitHub Desktop.
Save DanHerbert/04b554079ec8667fa6f0c7317f1d2343 to your computer and use it in GitHub Desktop.
One Liner (& multi-liner) to download latest Github repo release

1-liner to download latest Github repo release

Requires 2 apps to be installed on your machine:

  1. wget
  2. jq

Replace amd64.deb in the command below with the file name ending used in the project you're downloading.

wget -q -O - https://api.github.com/repos/AUTHOR_NAME/REPO_NAME/releases/latest | \
    jq -r '.assets[] | select(.name|endswith("amd64.deb")).browser_download_url' | \
    wget -qi -

Full update, but with a version check

Borrowing from the 1-liner implementation, this script checks the installed version against the latest version before downloading and installs the update if a new one is available.

This example uses ripgrep but should be easy enough to adapt for other projects.

#!/bin/bash
SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$(realpath $0)")" && pwd)

set -eu

cd "$SCRIPT_DIR"

latest_release_json=$(wget -q -O - https://api.github.com/repos/BurntSushi/ripgrep/releases/latest)

if command -v rg >/dev/null 2>&1; then
    existing_version=$(rg --version 2> /dev/null | head -1 | awk '{print $2}')
    latest_version=$(echo "$latest_release_json" | jq -r '.name')
    if [[ "$existing_version" == "$latest_version" ]]; then
        echo "installed: $existing_version latest: $latest_version"
        echo 'Currently on the latest version doing nothing.'
        exit 0
    fi
fi
echo "$latest_release_json" | jq -r '.assets[] | select(.name|endswith("amd64.deb")).browser_download_url' | wget -qi -

sudo dpkg -i ./*amd64.deb

rm ./*amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment