#!/usr/bin/env bash # Cocache CLI installer - downloads pre-built binaries from get.cocache.dev. # Usage: # curl -fsSL https://get.cocache.dev/install.sh | bash # COCACHE_VERSION=v0.1.0 curl -fsSL https://get.cocache.dev/install.sh | bash set -euo pipefail BASE_URL="https://get.cocache.dev" VERSION="${COCACHE_VERSION:-latest}" INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" # ── detect platform ─────────────────────────────────────────────────────────── OS=$(uname -s | tr '[:upper:]' '[:lower:]') case "$OS" in linux | darwin) ;; *) echo "error: unsupported OS: $OS" >&2; exit 1 ;; esac ARCH=$(uname -m) case "$ARCH" in x86_64 | amd64) ARCH="amd64" ;; aarch64 | arm64) ARCH="arm64" ;; *) echo "error: unsupported architecture: $ARCH" >&2; exit 1 ;; esac # ── resolve version ─────────────────────────────────────────────────────────── if [ "$VERSION" = "latest" ]; then VERSION=$(curl -fsSL "${BASE_URL}/releases/latest.txt") fi if [ -z "$VERSION" ]; then echo "error: could not resolve latest version from ${BASE_URL}/releases/latest.txt" >&2 exit 1 fi # ── download & install ──────────────────────────────────────────────────────── TARBALL="cocache_${OS}_${ARCH}.tar.gz" URL="${BASE_URL}/releases/${VERSION}/${TARBALL}" echo "Installing cocache ${VERSION} (${OS}/${ARCH})..." TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT curl -fsSL "$URL" -o "$TMP/$TARBALL" tar -xzf "$TMP/$TARBALL" -C "$TMP" mkdir -p "$INSTALL_DIR" mv "$TMP/cocache" "$INSTALL_DIR/cocache" mv "$TMP/cocached" "$INSTALL_DIR/cocached" chmod +x "$INSTALL_DIR/cocache" "$INSTALL_DIR/cocached" echo "" echo "Installed cocache + cocached to $INSTALL_DIR" # ── PATH hint ───────────────────────────────────────────────────────────────── if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then echo "" echo " Add this to your shell profile (~/.zshrc or ~/.bashrc):" echo " export PATH=\"\$HOME/.local/bin:\$PATH\"" fi echo "" echo "Next steps:" echo " 1. Sign in at https://cocache.dev and create a project - note the slug." echo " 2. cocache login --server https://api.cocache.dev --project --token " echo " 3. cocache init --server https://api.cocache.dev --project --client " echo "" echo " The Setup tab in your dashboard shows these commands pre-filled."