grokkit/scripts/grokkit-install.sh
Gregory Gauthier 509e02b2e8
All checks were successful
CI / Test (push) Successful in 33s
CI / Lint (push) Successful in 22s
CI / Build (push) Successful in 19s
Release / Create Release (push) Successful in 35s
feat(install): enhance grokkit-install script with checksum verification and version flexibility
- Strip leading 'v' from VERSION for flexible invocation
- Add robust checksum download and verification using sha256sum or shasum
- Handle missing checksum tools or entries gracefully with warnings
- Update asset naming to include 'v' prefix consistently
- Improve platform detection formatting and add trap for temp dir cleanup
- Minor echo message updates for better user feedback
2026-03-30 11:06:50 +01:00

79 lines
2.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
VERSION=${VERSION:-${1:?Provide VERSION env or arg, e.g. VERSION=0.3.2 bash grokkit-install.sh}}
# Strip leading 'v' if present (makes invocation flexible)
VERSION=${VERSION#v}
GITEA_BASE=https://repos.gmgauthier.com/gmgauthier/grokkit
# Platform detection
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux) OS=linux ;;
darwin) OS=darwin ;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
arm64|aarch64) ARCH=arm64 ;;
esac
ASSET="grokkit-${OS}-${ARCH}-v${VERSION}.tar.gz"
echo "Installing grokkit ${VERSION} for ${OS}/${ARCH}..."
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "${TEMP_DIR}"' EXIT
cd "${TEMP_DIR}"
# Download asset + checksums
echo "Downloading ${ASSET}..."
curl -fL "${GITEA_BASE}/releases/download/v${VERSION}/${ASSET}" -o asset.tar.gz
echo "Downloading checksums.txt..."
curl -fL "${GITEA_BASE}/releases/download/v${VERSION}/checksums.txt" -o checksums.txt
# Robust checksum verification
echo "Verifying checksum..."
CHECKSUM_CMD=""
if command -v sha256sum >/dev/null 2>&1; then
CHECKSUM_CMD="sha256sum"
elif command -v shasum >/dev/null 2>&1; then
CHECKSUM_CMD="shasum -a 256"
fi
if [ -n "$CHECKSUM_CMD" ] && [ -f checksums.txt ]; then
# Extract hash (handles "build/..." prefix in checksums.txt)
HASH=$(grep -oE '[0-9a-f]{64}\s+build/[^ ]*' checksums.txt | grep "${ASSET}" | cut -d' ' -f1)
if [ -z "$HASH" ]; then
echo "⚠️ No checksum entry found for ${ASSET} continuing without verification"
else
echo "${HASH} asset.tar.gz" | $CHECKSUM_CMD --check - || {
echo "❌ Checksum mismatch for ${ASSET}!"
exit 1
}
echo "✅ Checksum verified successfully"
fi
else
echo "⚠️ Checksum tool not found (sha256sum/shasum) skipping verification"
fi
# Extract
echo "Extracting asset..."
tar xzf asset.tar.gz
BINARY="grokkit-${OS}-${ARCH}"
# Install
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "${INSTALL_DIR}"
mv "${BINARY}" "${INSTALL_DIR}/grokkit"
chmod +x "${INSTALL_DIR}/grokkit"
echo "✅ grokkit ${VERSION} installed to ${INSTALL_DIR}/grokkit"
echo "Add to PATH if needed: export PATH=\"${INSTALL_DIR}:\$PATH\""
grokkit version