-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcl
More file actions
54 lines (47 loc) · 1.86 KB
/
Copy pathcl
File metadata and controls
54 lines (47 loc) · 1.86 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
#!/data/data/com.termux/files/usr/bin/bash
# cl — self-healing Claude Code launcher for Termux
# Checks binary integrity, rebuilds if needed, launches via claude-termux
CLAUDE="$HOME/.local/bin/claude"
CLAUDE_TERMUX="$HOME/.local/bin/claude-termux"
LOADER_DIR="$HOME/bun-termux-loader"
GCS_BUCKET="https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases"
is_script() { head -c 2 "$1" 2>/dev/null | grep -q '#!'; }
rebuild() {
local SRC="$1"
echo "[cl] Rebuilding bun-termux-loader wrapper..."
(cd "$LOADER_DIR" && python3 build.py "$SRC" "$CLAUDE")
rm -rf "${TMPDIR:-$PREFIX/tmp}/bun-termux-cache"
echo "[cl] Cleared bun cache"
}
# Auto-update drops a raw native binary at the claude path — detect and rebuild
if [ -f "$CLAUDE" ] && is_script "$CLAUDE"; then
echo "[cl] claude is a script (auto-update overwrote binary). Rebuilding..."
mv "$CLAUDE" "$CLAUDE.update-tmp"
rebuild "$CLAUDE.update-tmp"
rm -f "$CLAUDE.update-tmp"
echo "[cl] Fixed."
fi
# Check claude binary exists and is executable
if [ ! -x "$CLAUDE" ]; then
echo "[cl] claude binary missing. Downloading latest..."
if [ ! -d "$LOADER_DIR" ]; then
echo "[cl] ERROR: bun-termux-loader not found at $LOADER_DIR" >&2
exit 1
fi
VERSION=$(curl -fsSL "$GCS_BUCKET/latest")
FRESH="${TMPDIR:-$PREFIX/tmp}/claude-fresh"
curl -fsSL -o "$FRESH" "$GCS_BUCKET/$VERSION/linux-arm64/claude"
chmod +x "$FRESH"
rebuild "$FRESH"
rm -f "$FRESH"
echo "[cl] Built Claude Code $VERSION."
fi
# Ensure claude-termux wrapper exists
if [ ! -f "$CLAUDE_TERMUX" ]; then
cat > "$CLAUDE_TERMUX" << 'WRAPPER'
#!/data/data/com.termux/files/usr/bin/bash
exec proot --bind=$PREFIX/tmp:/tmp --bind=$PREFIX/bin/bash:/bin/sh ~/.local/bin/claude "$@"
WRAPPER
chmod +x "$CLAUDE_TERMUX"
fi
exec claude-termux "$@"