|
| 1 | +#!/bin/sh |
| 2 | +set -eu |
| 3 | + |
| 4 | +REPO="${CLAUDEFORM_REPO:-peterschmidt85/claudeform}" |
| 5 | +INSTALL_DIR="${CLAUDEFORM_INSTALL_DIR:-$HOME/.local/bin}" |
| 6 | +VERSION="${CLAUDEFORM_VERSION:-latest}" |
| 7 | + |
| 8 | +usage() { |
| 9 | + cat <<'EOF' |
| 10 | +Claudeform installer |
| 11 | +
|
| 12 | +Usage: |
| 13 | + sh install.sh [--version <tag>] [--install-dir <path>] [--repo <owner/name>] |
| 14 | +
|
| 15 | +Environment overrides: |
| 16 | + CLAUDEFORM_VERSION Tag to install (example: v0.1.0, v0.2.0-rc.1) |
| 17 | + CLAUDEFORM_INSTALL_DIR Destination directory (default: ~/.local/bin) |
| 18 | + CLAUDEFORM_REPO GitHub repo (default: peterschmidt85/claudeform) |
| 19 | +
|
| 20 | +Examples: |
| 21 | + curl -fsSL https://raw.githubusercontent.com/peterschmidt85/claudeform/main/install.sh | sh |
| 22 | + CLAUDEFORM_VERSION=v0.2.0-rc.1 curl -fsSL https://raw.githubusercontent.com/peterschmidt85/claudeform/main/install.sh | sh |
| 23 | +EOF |
| 24 | +} |
| 25 | + |
| 26 | +while [ "$#" -gt 0 ]; do |
| 27 | + case "$1" in |
| 28 | + --version) |
| 29 | + [ "$#" -ge 2 ] || { echo "error: --version requires a value" >&2; exit 1; } |
| 30 | + VERSION="$2" |
| 31 | + shift 2 |
| 32 | + ;; |
| 33 | + --version=*) |
| 34 | + VERSION="${1#*=}" |
| 35 | + shift |
| 36 | + ;; |
| 37 | + --install-dir) |
| 38 | + [ "$#" -ge 2 ] || { echo "error: --install-dir requires a value" >&2; exit 1; } |
| 39 | + INSTALL_DIR="$2" |
| 40 | + shift 2 |
| 41 | + ;; |
| 42 | + --install-dir=*) |
| 43 | + INSTALL_DIR="${1#*=}" |
| 44 | + shift |
| 45 | + ;; |
| 46 | + --repo) |
| 47 | + [ "$#" -ge 2 ] || { echo "error: --repo requires a value" >&2; exit 1; } |
| 48 | + REPO="$2" |
| 49 | + shift 2 |
| 50 | + ;; |
| 51 | + --repo=*) |
| 52 | + REPO="${1#*=}" |
| 53 | + shift |
| 54 | + ;; |
| 55 | + -h|--help) |
| 56 | + usage |
| 57 | + exit 0 |
| 58 | + ;; |
| 59 | + *) |
| 60 | + echo "error: unknown argument: $1" >&2 |
| 61 | + usage >&2 |
| 62 | + exit 1 |
| 63 | + ;; |
| 64 | + esac |
| 65 | +done |
| 66 | + |
| 67 | +detect_os() { |
| 68 | + case "$(uname -s)" in |
| 69 | + Linux) echo "linux" ;; |
| 70 | + Darwin) echo "darwin" ;; |
| 71 | + *) |
| 72 | + echo "error: unsupported OS: $(uname -s)" >&2 |
| 73 | + exit 1 |
| 74 | + ;; |
| 75 | + esac |
| 76 | +} |
| 77 | + |
| 78 | +detect_arch() { |
| 79 | + case "$(uname -m)" in |
| 80 | + x86_64|amd64) echo "x86_64" ;; |
| 81 | + arm64|aarch64) echo "aarch64" ;; |
| 82 | + *) |
| 83 | + echo "error: unsupported architecture: $(uname -m)" >&2 |
| 84 | + exit 1 |
| 85 | + ;; |
| 86 | + esac |
| 87 | +} |
| 88 | + |
| 89 | +sha256_file() { |
| 90 | + file="$1" |
| 91 | + if command -v shasum >/dev/null 2>&1; then |
| 92 | + shasum -a 256 "$file" | awk '{print $1}' |
| 93 | + return |
| 94 | + fi |
| 95 | + if command -v sha256sum >/dev/null 2>&1; then |
| 96 | + sha256sum "$file" | awk '{print $1}' |
| 97 | + return |
| 98 | + fi |
| 99 | + if command -v openssl >/dev/null 2>&1; then |
| 100 | + openssl dgst -sha256 "$file" | awk '{print $NF}' |
| 101 | + return |
| 102 | + fi |
| 103 | + echo "error: no SHA-256 tool found (need shasum, sha256sum, or openssl)" >&2 |
| 104 | + exit 1 |
| 105 | +} |
| 106 | + |
| 107 | +fetch_latest_stable_tag() { |
| 108 | + api_url="https://api.github.com/repos/${REPO}/releases/latest" |
| 109 | + tag="$(curl -fsSL "$api_url" | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)" |
| 110 | + if [ -z "$tag" ]; then |
| 111 | + echo "error: could not resolve latest stable release tag from $api_url" >&2 |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + echo "$tag" |
| 115 | +} |
| 116 | + |
| 117 | +normalize_tag() { |
| 118 | + raw="$1" |
| 119 | + case "$raw" in |
| 120 | + v*) echo "$raw" ;; |
| 121 | + *) echo "v$raw" ;; |
| 122 | + esac |
| 123 | +} |
| 124 | + |
| 125 | +os="$(detect_os)" |
| 126 | +arch="$(detect_arch)" |
| 127 | + |
| 128 | +if [ "$VERSION" = "latest" ]; then |
| 129 | + tag="$(fetch_latest_stable_tag)" |
| 130 | +else |
| 131 | + tag="$(normalize_tag "$VERSION")" |
| 132 | +fi |
| 133 | + |
| 134 | +asset="claudeform_${os}_${arch}.tar.gz" |
| 135 | +base_url="https://github.com/${REPO}/releases/download/${tag}" |
| 136 | +asset_url="${base_url}/${asset}" |
| 137 | +checksums_url="${base_url}/SHA256SUMS" |
| 138 | + |
| 139 | +tmp_dir="$(mktemp -d)" |
| 140 | +trap 'rm -rf "$tmp_dir"' EXIT INT TERM |
| 141 | + |
| 142 | +echo "Installing Claudeform ${tag} from ${REPO}" |
| 143 | +echo "Detected target: ${os}/${arch}" |
| 144 | +echo "Downloading: ${asset}" |
| 145 | + |
| 146 | +curl -fL "$asset_url" -o "${tmp_dir}/${asset}" |
| 147 | +curl -fL "$checksums_url" -o "${tmp_dir}/SHA256SUMS" |
| 148 | + |
| 149 | +expected="$(awk -v n="$asset" '$2 == n {print $1}' "${tmp_dir}/SHA256SUMS" | head -n 1)" |
| 150 | +if [ -z "$expected" ]; then |
| 151 | + echo "error: checksum for ${asset} not found in SHA256SUMS" >&2 |
| 152 | + exit 1 |
| 153 | +fi |
| 154 | + |
| 155 | +actual="$(sha256_file "${tmp_dir}/${asset}")" |
| 156 | +if [ "$expected" != "$actual" ]; then |
| 157 | + echo "error: checksum mismatch for ${asset}" >&2 |
| 158 | + echo "expected: $expected" >&2 |
| 159 | + echo "actual: $actual" >&2 |
| 160 | + exit 1 |
| 161 | +fi |
| 162 | + |
| 163 | +mkdir -p "$INSTALL_DIR" |
| 164 | +tar -xzf "${tmp_dir}/${asset}" -C "$tmp_dir" |
| 165 | + |
| 166 | +install -m 0755 "${tmp_dir}/claudeform" "${INSTALL_DIR}/claudeform" |
| 167 | +install -m 0755 "${tmp_dir}/cf" "${INSTALL_DIR}/cf" |
| 168 | + |
| 169 | +echo "Installed:" |
| 170 | +echo " ${INSTALL_DIR}/claudeform" |
| 171 | +echo " ${INSTALL_DIR}/cf" |
| 172 | +echo |
| 173 | +echo "If needed, add to PATH:" |
| 174 | +echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" |
0 commit comments