Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created February 23, 2024 14:25
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 jplitza/115b6dbb892b1c6dfa66922af6023306 to your computer and use it in GitHub Desktop.
Save jplitza/115b6dbb892b1c6dfa66922af6023306 to your computer and use it in GitHub Desktop.
Install from Github
#!/bin/sh
set -eu
REPO="$1"
ARCHIVE="$2"
FILE="$3"
# Fetch the latest version using GitHub API
VERSION="$(curl -s "https://api.github.com/repos/${REPO}/releases" | jq -r 'map(select(.prerelease | not)) | .[0].tag_name' | cut -c 2-)"
# Check if the version was fetched successfully
if [ -z "$VERSION" ]; then
echo "Failed to fetch the latest version of repo ${REPO}"
exit 1
fi
echo
echo "Installing $(basename "$FILE") v${VERSION}"
WORKDIR="$(mktemp -d)"
FILE="$(printf "$FILE" "$VERSION")"
curl -L "https://github.com/${REPO}/releases/download/v${VERSION}/$(printf "$ARCHIVE" "$VERSION")" | tar -xzC "$WORKDIR" "$FILE"
install -m 755 "${WORKDIR}/${FILE}" "/usr/local/bin/$(basename "$FILE")"
rm -r "$WORKDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment