Created
February 23, 2024 14:25
-
-
Save jplitza/115b6dbb892b1c6dfa66922af6023306 to your computer and use it in GitHub Desktop.
Install from Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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