mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
feat: simplify download script (#673)
This commit is contained in:
+12
-40
@@ -4,14 +4,14 @@ set -euo pipefail
|
||||
##############################################################################
|
||||
# Goose CLI Install Script
|
||||
#
|
||||
# This script downloads the latest 'goose' CLI binary from GitHub releases
|
||||
# This script downloads the latest stable 'goose' CLI binary from GitHub releases
|
||||
# and installs it to your system.
|
||||
#
|
||||
# Supported OS: macOS (darwin), Linux
|
||||
# Supported Architectures: x86_64, arm64
|
||||
#
|
||||
# Usage:
|
||||
# curl -H 'Accept: application/vnd.github.v3.raw' "https://api.github.com/repos/block/goose/contents/download_cli.sh?ref=v1.0" | bash
|
||||
# curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh | sh
|
||||
#
|
||||
# Environment variables:
|
||||
# GOOSE_BIN_DIR - Directory to which Goose will be installed (default: $HOME/.local/bin)
|
||||
@@ -28,14 +28,8 @@ fi
|
||||
# --- 2) Variables ---
|
||||
REPO="block/goose"
|
||||
OUT_FILE="goose"
|
||||
GITHUB_API_ENDPOINT="api.github.com"
|
||||
GOOSE_BIN_DIR="${GOOSE_BIN_DIR:-"$HOME/.local/bin"}"
|
||||
|
||||
# Helper function to fetch JSON from GitHub
|
||||
gh_curl() {
|
||||
curl -sL -H "Accept: application/vnd.github.v3.raw" "$@"
|
||||
}
|
||||
|
||||
# --- 3) Detect OS/Architecture ---
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
@@ -43,7 +37,7 @@ ARCH=$(uname -m)
|
||||
case "$OS" in
|
||||
linux|darwin) ;;
|
||||
*)
|
||||
echo "Error: Unsupported OS '$OS'. Goose only supports Linux and macOS."
|
||||
echo "Error: Unsupported OS '$OS'. Goose currently only supports Linux and macOS."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -62,43 +56,22 @@ case "$ARCH" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# Build the filename we expect in the release assets
|
||||
# Build the filename and URL for the stable release
|
||||
if [ "$OS" = "darwin" ]; then
|
||||
FILE="goose-$ARCH-apple-darwin.tar.bz2"
|
||||
else
|
||||
FILE="goose-$ARCH-unknown-linux-gnu.tar.bz2"
|
||||
fi
|
||||
|
||||
# --- 4) Fetch GitHub Releases and locate the correct asset ID ---
|
||||
echo "Looking up the most recent goose binary release..."
|
||||
RELEASES=$(gh_curl https://$GITHUB_API_ENDPOINT/repos/$REPO/releases)
|
||||
DOWNLOAD_URL="https://github.com/$REPO/releases/download/stable/$FILE"
|
||||
|
||||
# Parse JSON to find the asset ID
|
||||
ASSET_ID=$(echo "$RELEASES" | awk -v file="$FILE" '
|
||||
BEGIN { found_asset = 0; }
|
||||
/"assets"/ { in_assets = 1; next }
|
||||
in_assets && /"id":/ {
|
||||
match($0, /[0-9]+/);
|
||||
current_id = substr($0, RSTART, RLENGTH);
|
||||
next
|
||||
}
|
||||
in_assets && /"name":/ && $0 ~ file {
|
||||
print current_id;
|
||||
exit;
|
||||
}
|
||||
')
|
||||
|
||||
if [ -z "$ASSET_ID" ]; then
|
||||
echo "Error: Could not find a release asset named '$FILE' in the latest releases."
|
||||
# --- 4) Download & extract 'goose' binary ---
|
||||
echo "Downloading stable release: $FILE..."
|
||||
if ! curl -sLf "$DOWNLOAD_URL" --output "$FILE"; then
|
||||
echo "Error: Failed to download $DOWNLOAD_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- 5) Download & extract 'goose' binary ---
|
||||
echo "Downloading $FILE..."
|
||||
curl -sL --header 'Accept: application/octet-stream' \
|
||||
"https://$GITHUB_API_ENDPOINT/repos/$REPO/releases/assets/$ASSET_ID" \
|
||||
--output "$FILE"
|
||||
|
||||
echo "Extracting $FILE..."
|
||||
tar -xjf "$FILE"
|
||||
rm "$FILE" # clean up the downloaded tarball
|
||||
@@ -106,7 +79,7 @@ rm "$FILE" # clean up the downloaded tarball
|
||||
# Make binaries executable
|
||||
chmod +x goose
|
||||
|
||||
# --- 6) Install to $GOOSE_BIN_DIR ---
|
||||
# --- 5) Install to $GOOSE_BIN_DIR ---
|
||||
if [ ! -d "$GOOSE_BIN_DIR" ]; then
|
||||
echo "Creating directory: $GOOSE_BIN_DIR"
|
||||
mkdir -p "$GOOSE_BIN_DIR"
|
||||
@@ -115,8 +88,7 @@ fi
|
||||
echo "Moving goose to $GOOSE_BIN_DIR/$OUT_FILE"
|
||||
mv goose "$GOOSE_BIN_DIR/$OUT_FILE"
|
||||
|
||||
|
||||
# --- 7) Check PATH and give instructions if needed ---
|
||||
# --- 6) Check PATH and give instructions if needed ---
|
||||
if [[ ":$PATH:" != *":$GOOSE_BIN_DIR:"* ]]; then
|
||||
echo ""
|
||||
echo "Warning: $GOOSE_BIN_DIR is not in your PATH."
|
||||
@@ -126,7 +98,7 @@ if [[ ":$PATH:" != *":$GOOSE_BIN_DIR:"* ]]; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# --- 8) Auto-configure Goose (Optional) ---
|
||||
# --- 7) Auto-configure Goose (Optional) ---
|
||||
CONFIG_ARGS=""
|
||||
if [ -n "${GOOSE_PROVIDER:-}" ]; then
|
||||
CONFIG_ARGS="$CONFIG_ARGS -p $GOOSE_PROVIDER"
|
||||
|
||||
Reference in New Issue
Block a user