|
25 | 25 |
|
26 | 26 | # === CLEANUP TRAP === |
27 | 27 | cleanup() { |
28 | | - rm -f "${_TMPDIR}/claude-update" 2>/dev/null || true |
29 | | - rm -f "${_TMPDIR}/claude-update-manifest.json" 2>/dev/null || true |
30 | 28 | rm -rf "$LOCK_FILE" 2>/dev/null || true |
31 | 29 | } |
32 | 30 | trap cleanup EXIT |
33 | 31 |
|
34 | | -# === VERIFY CLAUDE IS INSTALLED === |
35 | | -if ! command -v claude &>/dev/null; then |
36 | | - log "Claude Code not found, skipping update" |
37 | | - exit 0 |
38 | | -fi |
| 32 | +# === NATIVE BINARY === |
| 33 | +NATIVE_BIN="$HOME/.local/bin/claude" |
39 | 34 |
|
40 | | -# === ENSURE NATIVE BINARY EXISTS === |
41 | | -# 'claude install' puts the binary at ~/.local/bin/claude (symlink to ~/.local/share/claude/versions/*) |
42 | | -# Legacy manual installs used /usr/local/bin/claude — check both, prefer ~/.local |
43 | | -if [ -x "$HOME/.local/bin/claude" ]; then |
44 | | - NATIVE_BIN="$HOME/.local/bin/claude" |
45 | | -elif [ -x "/usr/local/bin/claude" ]; then |
46 | | - NATIVE_BIN="/usr/local/bin/claude" |
47 | | -else |
48 | | - NATIVE_BIN="" |
| 35 | +if [ ! -x "$NATIVE_BIN" ]; then |
| 36 | + log "ERROR: Native binary not found at ${NATIVE_BIN}" |
| 37 | + log " The claude-code-native feature should install this during container build." |
| 38 | + log " Try rebuilding the container or running: curl -fsSL https://claude.ai/install.sh | sh" |
| 39 | + exit 1 |
49 | 40 | fi |
50 | | -if [ -z "$NATIVE_BIN" ]; then |
51 | | - log "Native binary not found, installing..." |
52 | | - if claude install 2>&1 | tee -a "$LOG_FILE"; then |
53 | | - log "Native binary installed successfully" |
| 41 | + |
| 42 | +# === TRANSITIONAL: Remove leftover npm installation === |
| 43 | +NPM_CLAUDE="$(npm config get prefix 2>/dev/null)/lib/node_modules/@anthropic-ai/claude-code" |
| 44 | +if [ -d "$NPM_CLAUDE" ]; then |
| 45 | + log "Removing leftover npm installation at ${NPM_CLAUDE}..." |
| 46 | + if sudo npm uninstall -g @anthropic-ai/claude-code 2>/dev/null; then |
| 47 | + log "Removed leftover npm installation" |
54 | 48 | else |
55 | | - log "WARNING: 'claude install' failed, skipping" |
56 | | - exit 0 |
| 49 | + log "WARNING: Could not remove npm installation (non-blocking)" |
57 | 50 | fi |
58 | | - # Skip update check on first install — next start will handle it |
59 | | - exit 0 |
60 | 51 | fi |
61 | 52 |
|
62 | 53 | # === CHECK FOR UPDATES === |
63 | 54 | CURRENT_VERSION=$("$NATIVE_BIN" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown") |
64 | 55 | log "Current version: ${CURRENT_VERSION}" |
65 | 56 |
|
66 | | -# Use the official update command (handles download, verification, and versioned install) |
67 | | -if "$NATIVE_BIN" update 2>&1 | tee -a "$LOG_FILE"; then |
| 57 | +# Use the official update command with timeout (handles download, verification, and versioned install) |
| 58 | +if timeout 60 "$NATIVE_BIN" update 2>&1 | tee -a "$LOG_FILE"; then |
68 | 59 | UPDATED_VERSION=$("$NATIVE_BIN" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown") |
69 | 60 | if [ "$CURRENT_VERSION" != "$UPDATED_VERSION" ]; then |
70 | 61 | log "Updated Claude Code: ${CURRENT_VERSION} → ${UPDATED_VERSION}" |
71 | 62 | else |
72 | 63 | log "Already up to date (${CURRENT_VERSION})" |
73 | 64 | fi |
74 | 65 | else |
75 | | - log "WARNING: 'claude update' failed, skipping" |
| 66 | + log "WARNING: 'claude update' failed or timed out" |
76 | 67 | fi |
0 commit comments