Download GitHub Latest Release

Introduction A shell script curl-github.sh to download the latest release of GitHub repositories. It needs curl and grep. usage: curl-github.sh [command] [repo] [keyword] commands: help, list, get. Script #!/bin/sh # download the latest release from github [ -n "$2" ] && REPO_PATH="$2" [ -n "$3" ] && KEYWORD="$3" [ -n "$4" ] && FILE_NAME="$4" [ -z "$REPO_PATH" ] && REPO_PATH="microsoft/vscode" [ -z "$KEYWORD" ] && KEYWORD="tarball" list() { echo $REPO_PATH curl -sL "https://api.github.com/repos/$REPO_PATH/releases/latest" | grep 'browser_download_url\|tarball_url\|zipball_url' | grep -o 'https:[^"]*' } get() { echo $REPO_PATH echo $KEYWORD URL=$(curl -sL "https://api.github.com/repos/$REPO_PATH/releases/latest" | grep 'browser_download_url\|tarball_url\|zipball_url' | grep -o 'https:[^"]*' | grep "$KEYWORD") echo $URL curl -LO "$URL" } help() { echo "usage: curl-github.sh [command] [repo] [keyword], commands: help, list, get." } CMD=$1 : ${CMD:='help'} $CMD P.S. grep -o 'https:[^"]*' If the first character of the list is the caret ‘^’, then it matches any character not in the list, and it is unspecified whether it matches an encoding error. Check the manual for details. ...

January 6, 2024 · 1 min · Mu Jiang