跳到主要内容

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

浏览文件

configure-macos-session.sh

77 行 · 4.3 KB历史下载
1#!/bin/bash
2# Root configures only the installer-bound ordinary account inside a Cage VM.
3set -euo pipefail
4export PATH=/usr/bin:/bin:/usr/sbin:/sbin
5[[ $# == 2 && $EUID == 0 && $(uname -sm) == 'Darwin arm64' && $(sysctl -n hw.model) =~ ^VirtualMac[0-9]+,[0-9]+$ ]]
6user=$1
7installation=$2
8[[ $user =~ ^[a-z][a-z0-9_]{0,30}$ && $user != root && $user != cageprovision && $user != cagesetup ]]
9[[ -f /var/db/cage-guest-os && ! -L /var/db/cage-guest-os && $(stat -f %u /var/db/cage-guest-os) == 0 && $(cat /var/db/cage-guest-os) == macos ]]
10receipt=/var/db/cage-initial-setup/account.json
11[[ -f $receipt && ! -L $receipt && $(stat -f %u "$receipt") == 0 && $(plutil -extract installation raw "$receipt") == "$installation" ]]
12bound_user=$(plutil -extract user raw "$receipt" 2>/dev/null || echo cage)
13[[ $bound_user == "$user" ]]
14phase=$(plutil -extract state raw "$receipt")
15[[ $phase == ready ]]
16[[ $(dscl . -read /Users/$user NFSHomeDirectory) == "NFSHomeDirectory: /Users/$user" && " $(id -Gn "$user") " != *' admin '* ]]
17IFS= read -r password
18[[ -n $password ]]
19printf '%s\n' "$password" | dscl /Local/Default -authonly "$user" >/dev/null
20# FileVault prevents system automatic login; retain its protection and report it.
21if fdesetup status | grep -q 'FileVault is On'; then
22 echo 'FileVault 已启用,请使用客机密码登录。' >&2
23 exit 1
24fi
25existing=$(defaults read /Library/Preferences/com.apple.loginwindow autoLoginUser 2>/dev/null || true)
26[[ -z $existing || $existing == "$user" ]]
27umask 077
28tmp=$(mktemp /etc/cage-autologin.XXXXXXXX)
29trap 'rm -f "$tmp"' EXIT
30# macOS's system auto-login record is reversible and root-readable. The host
31# copy is separately encrypted with the Cage account key. No password argument.
32printf '%s\n' "$password" | /usr/bin/perl -e '
33 use strict; use warnings;
34 my $password = <STDIN>; chomp $password;
35 my @key = (0x7d,0x89,0x52,0x23,0xd2,0xbc,0xdd,0xea,0xa3,0xb9,0x1f);
36 my $plain = $password . "\0";
37 $plain .= "\0" while length($plain) % 12;
38 print pack("C*", map { ord(substr($plain,$_,1)) ^ $key[$_ % @key] } 0..length($plain)-1);
39' > "$tmp"
40unset password
41[[ ! -L /etc/kcpassword ]]
42chmod 600 "$tmp"
43mv -f "$tmp" /etc/kcpassword
44defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser -string "$user"
45defaults write /Library/Preferences/com.apple.loginwindow autoLoginUserUID -int "$(id -u "$user")"
46# Match Lima's first-login suppression for the ordinary account. Its generated
47# plist contains the current OS build/version stamps and no credentials.
48provision=cageprovision
49source=/Users/$provision/Library/Preferences/com.apple.SetupAssistant.plist
50if [[ -f $source && ! -L $source ]]; then
51 cat "$source" | sudo -Hu "$user" /bin/bash -ec '
52 umask 077
53 mkdir -p "$HOME/Library/Preferences"
54 target="$HOME/Library/Preferences/com.apple.SetupAssistant.plist"
55 [[ ! -L $target ]]
56 cat > "$target"
57 plutil -lint "$target" >/dev/null
58 '
59fi
60# Write the current OS stamps directly through the account's preference service.
61sudo -Hu "$user" /bin/bash -ec '
62 domain=com.apple.SetupAssistant
63 version=$(sw_vers -productVersion)
64 build=$(sw_vers -buildVersion)
65 for key in DidSeeAccessibility DidSeeActivationLock DidSeeAppStore DidSeeAppearanceSetup DidSeeApplePaySetup DidSeeCloudSetup DidSeeLockdownMode DidSeePrivacy DidSeeScreenTime DidSeeSetupSequence DidSeeSiriSetup DidSeeSyncSetup DidSeeSyncSetup2 DidSeeTermsOfAddress DidSeeTouchIDSetup DidSeeiCloudLoginForStorageServices SkipExpressSettingsUpdating SkipFirstLoginOptimization; do
66 defaults write "$domain" "$key" -bool true
67 done
68 for key in LastPreLoginTasksPerformedBuild LastSeenBuddyBuildVersion; do defaults write "$domain" "$key" -string "$build"; done
69 for key in LastPreLoginTasksPerformedVersion LastSeenAgeRangeSelectionProductVersion LastSeenCloudProductVersion LastSeenDiagnosticsProductVersion; do defaults write "$domain" "$key" -string "$version"; done
70 defaults write "$domain" MiniBuddyLaunchReason -int 0
71 defaults write "$domain" MiniBuddyShouldLaunchToResumeSetup -bool false
72 defaults -currentHost write com.apple.screensaver idleTime -int 0
73'
74# Cage owns guest lifetime; the hidden desktop should not sleep while the
75# workbench is running. These settings affect only this virtual Mac.
76pmset -a sleep 0 displaysleep 0
77echo '客机自动登录与首次设置已准备。'