#!/bin/bash set -euo pipefail REPO="confighub/sdk" VERSION="${VERSION:-latest}" # --- Detect OS and ARCH --- OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" # Normalize arch naming case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64 | arm64) ARCH="arm64" ;; *) echo "Unsupported architecture: $ARCH" && exit 1 ;; esac # Normalize OS naming case "$OS" in darwin | linux) ;; # supported *) echo "Unsupported OS: $OS" && exit 1 ;; esac # Resolve latest version if needed if [ "$VERSION" = "latest" ]; then VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') if [ -z "$VERSION" ]; then echo "Failed to determine latest version" && exit 1 fi fi BASE_URL="https://github.com/$REPO/releases/download/$VERSION" mkdir -p "$HOME/.confighub/bin" echo "Installing ConfigHub CLI $VERSION ($OS/$ARCH)..." echo "Downloading cub..." curl -fsSL "$BASE_URL/cub-$OS-$ARCH" -o "$HOME/.confighub/bin/cub" chmod +x "$HOME/.confighub/bin/cub" echo "Downloading cub-worker-run..." curl -fsSL "$BASE_URL/cub-worker-run-$OS-$ARCH" -o "$HOME/.confighub/bin/cub-worker-run" chmod +x "$HOME/.confighub/bin/cub-worker-run" echo "" echo "Installation complete ($VERSION). Add cub to your PATH using your preferred method. E.g:" echo " sudo ln -sf $HOME/.confighub/bin/cub /usr/local/bin/cub" echo " ln -sf $HOME/.confighub/bin/cub \$HOME/bin/cub" echo " export PATH=\$HOME/.confighub/bin:\$PATH" echo "" echo "Then run 'cub --help' to get started"