跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

install-macos-cli.sh

114 行 · 6.0 KB历史下载
1#!/bin/bash
2# Offline installation. Only Cage-owned guest tools are published.
3set -euo pipefail
4export PATH=/usr/bin:/bin:/usr/sbin:/sbin
5[[ ( $# == 1 || ( $# == 2 && $2 == --components ) ) && $1 == /* && $EUID == 0 && $(sysctl -n hw.model) =~ ^VirtualMac[0-9]+,[0-9]+$ ]]
6components=${2:-}
7marker=/var/db/cage-guest-os
8[[ ! -L $marker && -f $marker && $(stat -f %u "$marker") == 0 && $(cat "$marker") == macos ]]
9mode=$(stat -f %OLp "$marker")
10(( (8#$mode & 022) == 0 ))
11kit=$(cd -P "$1" && pwd)
12# Local helper sources are supplied by the trusted host, not by the GUI guest user.
13[[ -z $(find "$kit" \( -type l -o ! -user root -o -perm -0020 -o -perm -0002 \) -print -quit) ]]
14parent=$kit
15while [[ $parent != / ]]; do
16 mode=$(stat -f %Op "$parent")
17 [[ $(stat -f %u "$parent") == 0 ]] || exit 1
18 (( (8#$mode & 022) == 0 || (8#$mode & 01000) != 0 )) || exit 1
19 parent=$(dirname "$parent")
20done
21umask 022
22base=/usr/local/libexec
23mkdir -p "$base" /usr/local/bin
24work=$(mktemp -d "$base/.cage-cli-install.XXXXXXXX")
25trap 'rm -rf "$work"' EXIT
26cd "$work"
27cp "$kit"/{macos-cli.py,cli_channel.py,cli_channel.resume.md,claude_account_resume.md,claude-account.py} .
28runtime="$base/cage-cli-runtime-2.1.311-py3.13.18-git2.56.0"
29if [[ $components == --components ]]; then
30 [[ -x $runtime/bin/python3 && -x $runtime/bin/claude && -x $runtime/bin/git ]] || { echo '请先更新环境工具,再同步组件。' >&2; exit 1; }
31else
32cp "$kit"/{claude,uv.tar.gz,python.tar.gz,git.tar.gz} .
33check() { [[ $(shasum -a 256 "$2" | cut -d' ' -f1) == "$1" ]]; }
34check 85d8c08707fcfd1e78ffa0204eefbc6ec9e4fe22f375fb2767ef85d957ed3161 claude
35check 81b811b57e4624df7ed3aac148e0359100d9962f3d9dce00aec533dc2e086731 uv.tar.gz
36check 8392b6ea51d94391befb2c31ebe75463f045d0b69dfcf5e1bb3234e1f5fa3405 python.tar.gz
37check 1110de343de11cc6f469b782b60f36217b9199b5e06875dd65baa26dd60563c7 git.tar.gz
38chmod 755 claude
39codesign --verify --strict --architecture arm64 -R '=anchor apple generic and identifier "com.anthropic.claude-code" and certificate leaf[subject.OU] = "Q6L2SF6YDW"' claude
40fi
41# Use rename(2), which never nests the staged directory inside a
42# concurrently completed installation.
43publish_dir() {
44 /usr/bin/perl -e 'rename($ARGV[0], $ARGV[1]) || -d $ARGV[1] || die "publish: $!"' "$1" "$2"
45}
46if [[ ! -d $runtime ]]; then
47 tar -xzf uv.tar.gz --no-same-owner
48 mkdir -p tools/bin
49 # uv recognizes the distribution format from the archive filename.
50 mv python.tar.gz cpython-3.13.18-aarch64-apple-darwin.tar.gz
51 cat > python.json <<JSON
52{"cpython-3.13.18-darwin-aarch64-none":{"name":"cpython","arch":{"family":"aarch64","variant":null},"os":"darwin","libc":"none","major":3,"minor":13,"patch":18,"prerelease":"","url":"file://$work/cpython-3.13.18-aarch64-apple-darwin.tar.gz","sha256":"8392b6ea51d94391befb2c31ebe75463f045d0b69dfcf5e1bb3234e1f5fa3405","variant":null,"build":"20261026"}}
53JSON
54 UV_CACHE_DIR="$work/cache" ./uv-aarch64-apple-darwin/uv python install 3.13.18 --install-dir "$work/tools/python" --no-bin --no-config --offline --python-downloads-json-url "$work/python.json"
55 ln -s ../python/cpython-3.13.18-macos-aarch64-none/bin/python3.13 tools/bin/python3
56 tools/bin/python3 -I -c 'import sys, ssl; assert sys.version_info[:3] == (3,13,18)'
57 mv claude tools/bin/
58 mkdir tools/git
59 tar -xzf git.tar.gz -C tools/git --no-same-owner
60 [[ $(tools/git/bin/git --version) == 'git version 2.56.0' ]]
61 # This GitHub Desktop distribution is relocatable. Its remote helpers
62 # and templates must be resolved from the same pinned distribution.
63 cat > tools/bin/git <<GIT
64#!/bin/sh
65export GIT_EXEC_PATH="\${GIT_EXEC_PATH:-$runtime/git/libexec/git-core}"
66export GIT_TEMPLATE_DIR="\${GIT_TEMPLATE_DIR:-$runtime/git/share/git-core/templates}"
67export GIT_CONFIG_SYSTEM="\${GIT_CONFIG_SYSTEM:-$runtime/git/etc/gitconfig}"
68exec "$runtime/git/bin/git" "\$@"
69GIT
70 chmod 755 tools/bin/git
71 chmod -R a+rX,go-w tools
72 publish_dir tools "$runtime"
73fi
74revision=$(shasum -a 256 macos-cli.py cli_channel.py cli_channel.resume.md claude_account_resume.md claude-account.py | shasum -a 256 | cut -c1-16)
75target="$base/cage-cli-2.1.311-git2.56.0-$revision"
76if [[ -d $target ]]; then
77 intact=yes
78 for name in macos-cli.py cli_channel.py cli_channel.resume.md; do
79 if ! cmp -s "$name" "$target/$name"; then intact=no; fi
80 done
81 if ! cmp -s claude_account_resume.md "$target/cli_channel.account-resume.md" ||
82 ! cmp -s <(sed "1s@.*@#!$runtime/bin/python3 -I@" claude-account.py) "$target/bin/cage-claude-account"; then intact=no; fi
83 for name in python3 claude git; do
84 if [[ ! -L $target/bin/$name || $(readlink "$target/bin/$name") != "$runtime/bin/$name" ]]; then intact=no; fi
85 done
86 if [[ $intact == no ]]; then
87 # Keep the damaged directory available for rollback while publishing a
88 # fresh helper set for the same application revision.
89 target="$target-repair-${work##*.}"
90 fi
91fi
92if [[ ! -d $target ]]; then
93 mkdir -p helpers/bin
94 for name in python3 claude git; do ln -s "$runtime/bin/$name" "helpers/bin/$name"; done
95 install -m 644 macos-cli.py cli_channel.py cli_channel.resume.md helpers/
96 install -m 644 claude_account_resume.md helpers/cli_channel.account-resume.md
97 sed "1s@.*@#!$runtime/bin/python3 -I@" claude-account.py > helpers/bin/cage-claude-account
98 chmod 755 helpers/bin/cage-claude-account
99 ln -s cage-claude-account helpers/bin/cage-open
100 publish_dir helpers "$target"
101fi
102current="$base/cage-cli"
103if [[ -e $current || -L $current ]]; then
104 [[ -L $current && $(readlink "$current") == "$base"/cage-cli-2.* ]]
105fi
106ln -s "$target" "$work/current"
107mv -fh "$work/current" "$current"
108account=/usr/local/bin/cage-claude-account
109if [[ ! -e $account && ! -L $account ]]; then ln -s "$current/bin/cage-claude-account" "$account"; fi
110[[ -L $account && $(readlink "$account") == "$current/bin/cage-claude-account" ]]
111for name in claude git; do
112 if [[ ! -e /usr/local/bin/$name && ! -L /usr/local/bin/$name ]]; then ln -s "$current/bin/$name" "/usr/local/bin/$name"; fi
113done
114"$current/bin/claude" --version