-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·351 lines (312 loc) · 10.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·351 lines (312 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env bash
#
# claude-cursor-proxy installer
#
# One-liner (macOS / Linux):
# curl -fsSL https://raw.githubusercontent.com/YeautyYE/claude-cursor-proxy/main/install.sh | bash
#
# Environment variables:
# GITHUB_REPO - Override owner/repo (default: YeautyYE/claude-cursor-proxy)
# CLAUDE_CURSOR_PROXY_VERSION - Pin a release tag (e.g. v0.1.22 or 0.1.22)
# CLAUDE_CURSOR_PROXY_INSTALL_DIR - Install directory (default: ~/.local/bin, or /usr/local/bin if writable)
# CLAUDE_CURSOR_PROXY_INSECURE_SKIP_CHECKSUM=1 - Skip checksum verify (not recommended)
#
# Legacy aliases (still accepted): CLAUDE_CURSOR_BRIDGE_*, CLAUDE_CODE_PROXY_*
#
set -euo pipefail
BIN_NAME="claude-cursor-proxy"
REPO="${GITHUB_REPO:-YeautyYE/claude-cursor-proxy}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { printf '%b==>%b %s\n' "$BLUE" "$NC" "$1"; }
log_success() { printf '%b==>%b %s\n' "$GREEN" "$NC" "$1"; }
log_warning() { printf '%b==>%b %s\n' "$YELLOW" "$NC" "$1"; }
log_error() { printf '%bError:%b %s\n' "$RED" "$NC" "$1" >&2; }
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
log_error "Required command not found: $1"
exit 1
fi
}
download() {
local url="$1"
local out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL --retry 3 --retry-connrefused --connect-timeout 10 --max-time 120 -o "$out" "$url"
elif command -v wget >/dev/null 2>&1; then
wget --tries=3 --timeout=120 -q -O "$out" "$url"
else
log_error "Neither curl nor wget found"
exit 1
fi
}
detect_platform() {
local os arch
case "$(uname -s)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
MINGW*|MSYS*|CYGWIN*)
log_error "Please use the Windows .zip from GitHub Releases, or install via WSL."
echo " https://github.com/${REPO}/releases"
exit 1
;;
*)
log_error "Unsupported operating system: $(uname -s)"
echo "${BIN_NAME} ships prebuilt binaries for macOS and Linux."
echo "Build from source: cargo install --git https://github.com/${REPO}"
exit 1
;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*)
log_error "Unsupported architecture: $(uname -m)"
echo "Prebuilt binaries: amd64 and arm64. Build from source with cargo."
exit 1
;;
esac
echo "${os}-${arch}"
}
# Normalize to a GitHub release tag (vX.Y.Z) while keeping bare version for assets.
normalize_tag() {
local raw="$1"
raw="${raw#refs/tags/}"
if [[ "$raw" == v* ]]; then
echo "$raw"
else
echo "v${raw}"
fi
}
pinned_version() {
# Prefer new env; accept legacy BRIDGE / CODE_PROXY aliases.
if [ -n "${CLAUDE_CURSOR_PROXY_VERSION:-}" ]; then
echo "${CLAUDE_CURSOR_PROXY_VERSION}"
elif [ -n "${CLAUDE_CURSOR_BRIDGE_VERSION:-}" ]; then
echo "${CLAUDE_CURSOR_BRIDGE_VERSION}"
elif [ -n "${CLAUDE_CODE_PROXY_VERSION:-}" ]; then
echo "${CLAUDE_CODE_PROXY_VERSION}"
else
echo ""
fi
}
resolve_version() {
local pinned
pinned="$(pinned_version)"
if [ -n "$pinned" ]; then
normalize_tag "$pinned"
return
fi
log_info "Fetching latest release..."
local latest_url="https://api.github.com/repos/${REPO}/releases/latest"
local tmp
tmp="$(mktemp)"
if ! download "$latest_url" "$tmp"; then
rm -f "$tmp"
log_error "Failed to query GitHub Releases"
echo "Set a version explicitly: CLAUDE_CURSOR_PROXY_VERSION=v0.1.22 bash install.sh"
exit 1
fi
# Prefer python/jq if present; fall back to sed
local version=""
if command -v jq >/dev/null 2>&1; then
version="$(jq -r '.tag_name // empty' "$tmp")"
elif command -v python3 >/dev/null 2>&1; then
version="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("tag_name",""))' "$tmp")"
else
version="$(grep '"tag_name"' "$tmp" | head -1 | sed -E 's/.*"tag_name":[[:space:]]*"([^"]+)".*/\1/')"
fi
rm -f "$tmp"
if [ -z "$version" ] || [ "$version" = "null" ]; then
log_error "No GitHub release found for ${REPO}"
echo "Create a release (tag vX.Y.Z) first, or pin CLAUDE_CURSOR_PROXY_VERSION."
exit 1
fi
normalize_tag "$version"
}
skip_checksum() {
[ "${CLAUDE_CURSOR_PROXY_INSECURE_SKIP_CHECKSUM:-}" = "1" ] \
|| [ "${CLAUDE_CURSOR_BRIDGE_INSECURE_SKIP_CHECKSUM:-}" = "1" ] \
|| [ "${CLAUDE_CODE_PROXY_INSECURE_SKIP_CHECKSUM:-}" = "1" ]
}
verify_checksum() {
local checksum_file="$1"
if skip_checksum; then
log_warning "Skipping checksum verification (INSECURE_SKIP_CHECKSUM=1)"
return 0
fi
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "$checksum_file" >/dev/null
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "$checksum_file" >/dev/null
else
log_error "Neither sha256sum nor shasum found; cannot verify download"
echo "Install coreutils/shasum, or set CLAUDE_CURSOR_PROXY_INSECURE_SKIP_CHECKSUM=1 (not recommended)."
exit 1
fi
}
ad_hoc_codesign() {
local binary="$1"
[[ "$(uname -s)" == "Darwin" ]] || return 0
if command -v xattr >/dev/null 2>&1; then
xattr -d com.apple.quarantine "$binary" 2>/dev/null || true
fi
if command -v codesign >/dev/null 2>&1; then
# Fresh ad-hoc signature — copying unsigned/broken Mach-O can yield "Killed: 9"
codesign --remove-signature "$binary" 2>/dev/null || true
if ! codesign --force -s - "$binary" 2>/dev/null; then
log_warning "codesign failed; if the binary dies with Killed: 9, run:"
echo " codesign --force -s - \"$binary\""
fi
fi
}
install_from_release() {
local platform="$1"
local tmp_dir
tmp_dir="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf '$tmp_dir'" EXIT
local version
version="$(resolve_version)"
local bare_version="${version#v}"
log_info "Installing version: ${version}"
# Prefer versioned asset; fall back to platform-only alias
local archive_versioned="${BIN_NAME}-${bare_version}-${platform}.tar.gz"
local archive_alias="${BIN_NAME}-${platform}.tar.gz"
local archive_name=""
cd "$tmp_dir"
if download "https://github.com/${REPO}/releases/download/${version}/${archive_versioned}" "$archive_versioned" 2>/dev/null; then
archive_name="$archive_versioned"
elif download "https://github.com/${REPO}/releases/download/${version}/${archive_alias}" "$archive_alias" 2>/dev/null; then
archive_name="$archive_alias"
else
log_error "Download failed for ${platform}"
echo "Tried:"
echo " https://github.com/${REPO}/releases/download/${version}/${archive_versioned}"
echo " https://github.com/${REPO}/releases/download/${version}/${archive_alias}"
echo "Releases: https://github.com/${REPO}/releases"
echo "Note: Linux prebuilts are glibc (ubuntu-latest / 24.04). Alpine/musl users should build from source."
exit 1
fi
log_info "Downloaded ${archive_name}"
local checksum_file="${archive_name%.tar.gz}.sha256"
local checksum_url="https://github.com/${REPO}/releases/download/${version}/${checksum_file}"
# Also try platform-only checksum if versioned missing
if ! download "$checksum_url" "$checksum_file" 2>/dev/null; then
checksum_file="${BIN_NAME}-${platform}.sha256"
checksum_url="https://github.com/${REPO}/releases/download/${version}/${checksum_file}"
if ! download "$checksum_url" "$checksum_file" 2>/dev/null; then
log_error "Failed to download checksum file"
exit 1
fi
fi
log_info "Verifying checksum..."
if ! verify_checksum "$checksum_file"; then
log_error "Checksum verification failed"
exit 1
fi
log_success "Checksum verified"
log_info "Extracting..."
tar -xzf "$archive_name"
if [ ! -f "${BIN_NAME}" ]; then
log_error "Archive did not contain ${BIN_NAME}"
exit 1
fi
chmod +x "${BIN_NAME}"
local install_dir="${CLAUDE_CURSOR_PROXY_INSTALL_DIR:-${CLAUDE_CURSOR_BRIDGE_INSTALL_DIR:-${CLAUDE_CODE_PROXY_INSTALL_DIR:-}}}"
if [ -z "$install_dir" ]; then
if [ -w /usr/local/bin ] 2>/dev/null; then
install_dir="/usr/local/bin"
else
install_dir="${HOME}/.local/bin"
mkdir -p "$install_dir"
fi
else
mkdir -p "$install_dir"
fi
log_info "Installing to ${install_dir}..."
local dest="${install_dir}/${BIN_NAME}"
local tmp_binary="${dest}.tmp.$$"
if [ -w "$install_dir" ]; then
cp "${BIN_NAME}" "$tmp_binary"
chmod +x "$tmp_binary"
ad_hoc_codesign "$tmp_binary"
mv -f "$tmp_binary" "$dest"
else
need_cmd sudo
sudo cp "${BIN_NAME}" "$tmp_binary"
sudo chmod +x "$tmp_binary"
# codesign before final move when possible
if [[ "$(uname -s)" == "Darwin" ]] && command -v codesign >/dev/null 2>&1; then
sudo codesign --remove-signature "$tmp_binary" 2>/dev/null || true
sudo codesign --force -s - "$tmp_binary" 2>/dev/null || true
fi
sudo mv -f "$tmp_binary" "$dest"
ad_hoc_codesign "$dest"
fi
# Re-sign final path on macOS (mv can invalidate in some edge cases)
ad_hoc_codesign "$dest"
log_success "${BIN_NAME} installed to ${dest}"
# Optional compatibility symlinks for previous binary names
for old_name in claude-cursor-bridge claude-code-proxy; do
link="${install_dir}/${old_name}"
if [ -e "$link" ] && [ ! -L "$link" ]; then
log_warning "Skipping symlink ${link} (exists and is not a symlink)"
continue
fi
if [ -w "$install_dir" ]; then
ln -sfn "${BIN_NAME}" "$link" 2>/dev/null || true
elif command -v sudo >/dev/null 2>&1; then
sudo ln -sfn "${BIN_NAME}" "$link" 2>/dev/null || true
fi
done
if [[ ":${PATH}:" != *":${install_dir}:"* ]]; then
log_warning "${install_dir} is not in your PATH"
echo ""
echo "Add this to your shell profile (~/.zshrc or ~/.bashrc):"
echo " export PATH=\"\$PATH:${install_dir}\""
echo ""
fi
INSTALL_DIR="$install_dir"
cd - >/dev/null || true
}
print_next_steps() {
local install_dir="$1"
local bin="${install_dir}/${BIN_NAME}"
log_success "${BIN_NAME} is ready"
echo ""
"$bin" --version
echo ""
echo "Next steps:"
echo " 1. Log in to Cursor:"
echo " ${BIN_NAME} cursor auth login"
echo " 2. Start the bridge:"
echo " ${BIN_NAME} serve"
echo " 3. Point Claude Code at it (Fable 5):"
echo " export ANTHROPIC_BASE_URL=http://127.0.0.1:18765"
echo " export ANTHROPIC_AUTH_TOKEN=unused"
echo " export ANTHROPIC_MODEL=claude-fable-5[1m]"
echo " export ANTHROPIC_SMALL_FAST_MODEL=claude-fable-5[1m]"
echo " export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1"
echo " export CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1"
echo " claude"
echo ""
echo "Docs: https://github.com/${REPO}"
echo ""
}
main() {
echo ""
echo "${BIN_NAME} installer"
echo "repo: ${REPO}"
echo ""
log_info "Detecting platform..."
local platform
platform="$(detect_platform)"
log_info "Platform: ${platform}"
install_from_release "$platform"
print_next_steps "$INSTALL_DIR"
}
main "$@"