|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +# ccv installer — Claude Code Vault |
| 5 | +# Usage: curl -fsSL https://raw.githubusercontent.com/takielias/ccv/main/install.sh | sh |
| 6 | + |
| 7 | +VERSION="0.1.0" |
| 8 | +REPO="takielias/claude-code-vault" |
| 9 | +BINARY="ccv" |
| 10 | +INSTALL_DIR="/usr/local/bin" |
| 11 | + |
| 12 | +# Colors |
| 13 | +RED='\033[0;31m' |
| 14 | +GREEN='\033[0;32m' |
| 15 | +YELLOW='\033[1;33m' |
| 16 | +CYAN='\033[0;36m' |
| 17 | +NC='\033[0m' |
| 18 | + |
| 19 | +info() { printf "${CYAN}[ccv]${NC} %s\n" "$1"; } |
| 20 | +ok() { printf "${GREEN}[ccv]${NC} %s\n" "$1"; } |
| 21 | +warn() { printf "${YELLOW}[ccv]${NC} %s\n" "$1"; } |
| 22 | +error() { printf "${RED}[ccv]${NC} %s\n" "$1" >&2; exit 1; } |
| 23 | + |
| 24 | +# Detect OS |
| 25 | +detect_os() { |
| 26 | + OS="$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 27 | + case "$OS" in |
| 28 | + linux*) OS="linux" ;; |
| 29 | + darwin*) OS="darwin" ;; |
| 30 | + *) error "Unsupported OS: $OS" ;; |
| 31 | + esac |
| 32 | +} |
| 33 | + |
| 34 | +# Detect architecture |
| 35 | +detect_arch() { |
| 36 | + ARCH="$(uname -m)" |
| 37 | + case "$ARCH" in |
| 38 | + x86_64|amd64) ARCH="amd64" ;; |
| 39 | + aarch64|arm64) ARCH="arm64" ;; |
| 40 | + *) error "Unsupported architecture: $ARCH" ;; |
| 41 | + esac |
| 42 | +} |
| 43 | + |
| 44 | +# Download and install |
| 45 | +install_binary() { |
| 46 | + ARCHIVE="${BINARY}-${VERSION}-${OS}-${ARCH}.tar.gz" |
| 47 | + URL="https://github.com/${REPO}/releases/download/v${VERSION}/${ARCHIVE}" |
| 48 | + |
| 49 | + info "Downloading ccv v${VERSION} for ${OS}/${ARCH}..." |
| 50 | + |
| 51 | + TMPDIR="$(mktemp -d)" |
| 52 | + trap 'rm -rf "$TMPDIR"' EXIT |
| 53 | + |
| 54 | + if command -v curl >/dev/null 2>&1; then |
| 55 | + curl -fsSL "$URL" -o "${TMPDIR}/${ARCHIVE}" || error "Download failed. Check https://github.com/${REPO}/releases" |
| 56 | + elif command -v wget >/dev/null 2>&1; then |
| 57 | + wget -q "$URL" -O "${TMPDIR}/${ARCHIVE}" || error "Download failed. Check https://github.com/${REPO}/releases" |
| 58 | + else |
| 59 | + error "curl or wget required" |
| 60 | + fi |
| 61 | + |
| 62 | + info "Extracting..." |
| 63 | + tar -xzf "${TMPDIR}/${ARCHIVE}" -C "$TMPDIR" |
| 64 | + |
| 65 | + info "Installing to ${INSTALL_DIR}/${BINARY}..." |
| 66 | + if [ -w "$INSTALL_DIR" ]; then |
| 67 | + mv "${TMPDIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}" |
| 68 | + else |
| 69 | + sudo mv "${TMPDIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}" |
| 70 | + fi |
| 71 | + chmod +x "${INSTALL_DIR}/${BINARY}" |
| 72 | + |
| 73 | + # Verify |
| 74 | + if command -v ccv >/dev/null 2>&1; then |
| 75 | + ok "Installed successfully: $(ccv --version 2>&1 | head -1)" |
| 76 | + else |
| 77 | + warn "Installed to ${INSTALL_DIR}/${BINARY}" |
| 78 | + warn "Make sure ${INSTALL_DIR} is in your PATH" |
| 79 | + fi |
| 80 | +} |
| 81 | + |
| 82 | +# Build from source as fallback |
| 83 | +install_from_source() { |
| 84 | + if ! command -v go >/dev/null 2>&1; then |
| 85 | + error "Go is not installed. Install Go from https://go.dev/dl/ or download a pre-built binary from https://github.com/${REPO}/releases" |
| 86 | + fi |
| 87 | + |
| 88 | + info "Building from source..." |
| 89 | + go install -ldflags "-s -w -X 'github.com/taki/ccv/cmd.Version=${VERSION}'" github.com/taki/ccv@latest |
| 90 | + |
| 91 | + if command -v ccv >/dev/null 2>&1; then |
| 92 | + ok "Installed successfully: $(ccv --version 2>&1 | head -1)" |
| 93 | + else |
| 94 | + GOPATH="$(go env GOPATH)" |
| 95 | + warn "Installed to ${GOPATH}/bin/ccv" |
| 96 | + warn "Add this to your shell profile: export PATH=\$PATH:${GOPATH}/bin" |
| 97 | + fi |
| 98 | +} |
| 99 | + |
| 100 | +main() { |
| 101 | + printf "\n${CYAN}╔══════════════════════════════════════╗${NC}\n" |
| 102 | + printf "${CYAN}║ ccv — Claude Code Vault Installer ║${NC}\n" |
| 103 | + printf "${CYAN}╚══════════════════════════════════════╝${NC}\n\n" |
| 104 | + |
| 105 | + detect_os |
| 106 | + detect_arch |
| 107 | + info "Detected: ${OS}/${ARCH}" |
| 108 | + |
| 109 | + # Try binary download first, fall back to source |
| 110 | + install_binary 2>/dev/null || { |
| 111 | + warn "Binary download failed, building from source..." |
| 112 | + install_from_source |
| 113 | + } |
| 114 | + |
| 115 | + printf "\n${GREEN}Get started:${NC}\n" |
| 116 | + printf " cd your-project\n" |
| 117 | + printf " ccv init\n\n" |
| 118 | +} |
| 119 | + |
| 120 | +main |
0 commit comments