跳到主要内容

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

浏览文件

install-macos-project-tools.sh

94 行 · 5.1 KB历史下载
1#!/bin/bash
2# Run as root inside a Cage macOS guest. The supplied directory contains the
3# verified macFUSE 5.5.0 installer and the three project tools from this build.
4set -euo pipefail
5export PATH=/usr/bin:/bin:/usr/sbin:/sbin
6fail() { printf '%s\n' "$*" >&2; exit 1; }
7[[ $# == 1 && $1 == /* ]] || fail 'Usage: install-macos-project-tools.sh /path/to/root-owned-guest-project-kit'
8[[ $(uname -sm) == 'Darwin arm64' && $(sysctl -n hw.model) =~ ^VirtualMac[0-9]+,[0-9]+$ && $(id -u) == 0 ]] ||
9 fail 'Run this installer in the target arm64 Cage guest as administrator.'
10marker=/var/db/cage-guest-os
11[[ -f $marker && ! -L $marker && $(stat -f %u "$marker") == 0 && $(cat "$marker") == macos ]] ||
12 fail 'Missing the root-owned Cage guest marker.'
13mode=$(stat -f %OLp "$marker")
14(( (8#$mode & 022) == 0 )) || fail 'The guest marker is writable by another account.'
15
16# Copy before verification, so a source directory cannot change after checks.
17# Root-owned inputs are required because unsigned development builds can use a
18# local ad-hoc signature. No downloaded code is executed to verify identity.
19kit=$(cd -P "$1" && pwd)
20[[ $(stat -f %u "$kit") == 0 && -z $(find "$kit" \( -type l -o ! -user root -o -perm -0020 -o -perm -0002 \) -print -quit) ]] ||
21 fail 'Use a root-owned kit with no symlinks or group/other-writable members.'
22parent=$(dirname "$kit")
23while [[ $parent != / ]]; do
24 mode=$(stat -f %Op "$parent")
25 [[ $(stat -f %u "$parent") == 0 ]] && (( (8#$mode & 022) == 0 || (8#$mode & 01000) != 0 )) ||
26 fail 'The kit can be replaced through an untrusted parent directory.'
27 parent=$(dirname "$parent")
28done
29for file in macfuse.pkg cage-sshfs cage-macos-terminal; do [[ -f $kit/$file ]] || fail "Missing $file"; done
30[[ -d $kit/CageProjectAccess.app ]] || fail 'Missing CageProjectAccess.app.'
31umask 077
32work=$(mktemp -d /private/var/tmp/cage-project-kit.XXXXXXXX)
33trap 'rm -rf "$work"' EXIT
34for file in macfuse.pkg cage-sshfs cage-macos-terminal; do cp "$kit/$file" "$work/$file"; done
35ditto "$kit/CageProjectAccess.app" "$work/CageProjectAccess.app"
36pkg="$work/macfuse.pkg"
37[[ $(shasum -a 256 "$pkg" | cut -d' ' -f1) == 5acf9e30bab227707de8d15eb28472a0cc9ed45709846b3e067d283294dc7f9e ]] ||
38 fail 'The macFUSE installer SHA-256 does not match the pinned release.'
39pkgutil --check-signature "$pkg" | grep -F 'Developer ID Installer: Benjamin Fleischer (3T5GSNBU6W)' >/dev/null ||
40 fail 'Unexpected macFUSE installer signer.'
41for file in cage-sshfs cage-macos-terminal; do
42 codesign --verify --strict --architecture arm64 "$work/$file"
43done
44access_id=dev.cage.guest.project-access
45codesign --verify --strict -R "=identifier \"$access_id\"" "$work/CageProjectAccess.app"
46macfuse_requirement='anchor apple generic and identifier "io.macfuse.app" and certificate leaf[subject.OU] = "3T5GSNBU6W"'
47driver=/Library/Filesystems/macfuse.fs
48vendor_app="$driver/Contents/Resources/macfuse.app"
49installed=''
50if [[ -e $driver ]]; then
51 codesign --verify --strict -R "=$macfuse_requirement" "$vendor_app"
52 installed=$(plutil -extract CFBundleShortVersionString raw -o - "$driver/Contents/Info.plist")
53fi
54up_to_date=no
55if [[ -n $installed ]]; then
56 [[ $installed =~ ^([0-9]+)\.([0-9]+)(\.[0-9]+)?$ ]] || fail 'Unrecognized installed macFUSE version.'
57 if (( 10#${BASH_REMATCH[1]} > 5 || (10#${BASH_REMATCH[1]} == 5 && 10#${BASH_REMATCH[2]} >= 5) )); then up_to_date=yes; fi
58fi
59if [[ $up_to_date == no ]]; then
60 installer -pkg "$pkg" -target /
61fi
62codesign --verify --strict -R "=$macfuse_requirement" "$vendor_app"
63
64install_app() {
65 local source=$1 target=$2 requirement=$3 stage
66 if [[ -e $target || -L $target ]]; then
67 [[ ! -L $target && -d $target ]] || fail "Unexpected application at $target"
68 codesign --verify --strict -R "=$requirement" "$target"
69 if diff -qr "$source" "$target" >/dev/null; then return; fi
70 fail "A different verified build is already installed at $target. Stop and update that application before retrying."
71 fi
72 stage=$(mktemp -d /Applications/.cage-project-install.XXXXXXXX)
73 if ditto "$source" "$stage/app" && chmod -R a+rX,go-w "$stage/app" &&
74 codesign --verify --strict -R "=$requirement" "$stage/app" && mv "$stage/app" "$target"; then
75 rmdir "$stage"
76 else
77 rm -rf "$stage"
78 fail "Could not install $target"
79 fi
80}
81install_app "$vendor_app" /Applications/macFUSE.app "$macfuse_requirement"
82install_app "$work/CageProjectAccess.app" /Applications/CageProjectAccess.app "identifier \"$access_id\""
83libexec=/usr/local/libexec
84mkdir -p "$libexec"
85for file in cage-sshfs cage-macos-terminal; do
86 [[ ! -L $libexec/$file ]] || fail "Refusing to replace a linked executable: $file"
87 if [[ -f $libexec/$file ]] && cmp -s "$work/$file" "$libexec/$file"; then continue; fi
88 stage=$(mktemp "$libexec/.cage-tool.XXXXXXXX")
89 if install -o root -g wheel -m 755 "$work/$file" "$stage" && mv -f "$stage" "$libexec/$file"; then :; else
90 rm -f "$stage"
91 fail "Could not install $file"
92 fi
93done
94printf '%s\n' 'Project tools are ready. In the guest user session, open macFUSE.app once, then enable both macFUSE and macFUSE (local) under By Category > File System Extensions.'