| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -euo pipefail |
| 4 | cd "$(dirname "$0")/.." |
| 5 | if [[ "$(uname -s)" != Darwin || "$(uname -m)" != arm64 ]]; then |
| 6 | echo 'The supported release target is Apple Silicon macOS 14+.' >&2; exit 1 |
| 7 | fi |
| 8 | case "${1:-}" in ''|--from-notarized-app) ;; *) echo 'Usage: scripts/package-macos.sh [--from-notarized-app]' >&2; exit 2 ;; esac |
| 9 | : "${CAGE_SIGNING_IDENTITY:?Set CAGE_SIGNING_IDENTITY to your Developer ID Application identity.}" |
| 10 | : "${CAGE_NOTARY_PROFILE:?Set CAGE_NOTARY_PROFILE to a notarytool keychain profile.}" |
| 11 | notary_credentials=(--keychain-profile "$CAGE_NOTARY_PROFILE") |
| 12 | if [[ -n "${CAGE_NOTARY_KEYCHAIN:-}" ]]; then |
| 13 | notary_credentials+=(--keychain "$CAGE_NOTARY_KEYCHAIN") |
| 14 | fi |
| 15 | if [[ "$CAGE_SIGNING_IDENTITY" == - ]]; then echo 'Release packages require a Developer ID identity.' >&2; exit 1; fi |
| 16 | version="$(tr -d '\n\r' < VERSION)" |
| 17 | release="$PWD/_output/releases/$version" |
| 18 | bundle="$PWD/_output/Cage.app" |
| 19 | mkdir -p "$release" |
| 20 | if [[ "${1:-}" != --from-notarized-app ]]; then |
| 21 | bash scripts/build-app.sh |
| 22 | ditto -c -k --keepParent "$bundle" "$release/Cage-notarization.zip" |
| 23 | xcrun notarytool submit "$release/Cage-notarization.zip" \ |
| 24 | "${notary_credentials[@]}" --wait --timeout 20m \ |
| 25 | --output-format json > "$release/app-notarization.json" |
| 26 | node -e 'const r=JSON.parse(require("fs").readFileSync(process.argv[1])); if(r.status!=="Accepted") throw new Error(`Apple notarization: ${r.status}; submission ${r.id}`)' "$release/app-notarization.json" |
| 27 | xcrun stapler staple "$bundle" |
| 28 | fi |
| 29 | actual_version="$(/usr/libexec/PlistBuddy -c 'Print :CageVersion' "$bundle/Contents/Info.plist")" |
| 30 | if [[ "$actual_version" != "$version" ]]; then echo 'App version differs from VERSION; rebuild before packaging.' >&2; exit 1; fi |
| 31 | codesign --verify --deep --strict --verbose=2 "$bundle" |
| 32 | xcrun stapler validate "$bundle" |
| 33 | spctl --assess --type execute --verbose=2 "$bundle" |
| 34 | guest_source="cage-macos-guest-$version-source.tar.gz" |
| 35 | guest_materials="$bundle/Contents/Resources/guest-os/sources/$guest_source" |
| 36 | node scripts/guest-os/collect-macos-sshfs-sources.mjs verify "$guest_materials" \ |
| 37 | "$bundle/Contents/Resources/guest-os/project/cage-sshfs" "$version" |
| 38 | |
| 39 | |
| 40 | cp "$guest_materials" "$release/$guest_source" |
| 41 | |
| 42 | stage="$(mktemp -d "$PWD/_output/dmg-stage.XXXXXX")" |
| 43 | trap 'rm -rf "$stage"' EXIT |
| 44 | ditto "$bundle" "$stage/Cage.app" |
| 45 | ln -s /Applications "$stage/Applications" |
| 46 | cat > "$stage/安装说明 - Read Me.txt" <<'EOF' |
| 47 | Cage — 本机隔离编码工作区 |
| 48 | |
| 49 | 1. 将 Cage.app 拖入 Applications(应用程序)。 |
| 50 | 2. 从应用程序打开 Cage,设置本地账户,并按首次引导选择客机系统、存储位置和代理。 |
| 51 | 3. 添加自己的 Clash/Mihomo YAML 订阅或配置并选择节点,创建和启动环境。首次需下载系统镜像和工具,请保持网络连接。 |
| 52 | 4. 打开项目或新建终端,输入 claude,并在 Cage 浏览器内登录自己的 Claude 账户。 |
| 53 | |
| 54 | 需要 Apple Silicon Mac、macOS 14 或更新版本。无需安装 Go、Node.js 或 Clash。 |
| 55 | 代理服务与 Claude 账户需自行准备。具体版本与发布状态以发行说明为准。 |
| 56 | 共享项目中的文件修改会直接写回 Mac;请备份重要项目。 |
| 57 | 升级前请退出 Cage 并停止环境,再替换应用程序;配置与项目文件会保留。 |
| 58 | |
| 59 | Drag Cage.app into Applications, then open it from Applications. |
| 60 | Complete the local account and environment setup, add your own Clash/Mihomo |
| 61 | YAML subscription or configuration, select a node, and start the environment. |
| 62 | Initial setup downloads the selected guest system and developer tools. |
| 63 | Requires Apple Silicon and macOS 14+. Your own proxy and Claude account are required. |
| 64 | |
| 65 | 入门 / Getting started: |
| 66 | https://github.com/Lee-xeo/Claude-Cage/blob/main/docs/getting-started.md |
| 67 | 问题反馈 / Issues: |
| 68 | https://github.com/Lee-xeo/Claude-Cage/issues |
| 69 | EOF |
| 70 | artifact="Cage-$version-macos-arm64.dmg" |
| 71 | hdiutil create -volname Cage -srcfolder "$stage" -ov -format UDZO "$release/$artifact" |
| 72 | codesign --force --sign "$CAGE_SIGNING_IDENTITY" --timestamp "$release/$artifact" |
| 73 | xcrun notarytool submit "$release/$artifact" "${notary_credentials[@]}" \ |
| 74 | --wait --timeout 20m --output-format json > "$release/dmg-notarization.json" |
| 75 | node -e 'const r=JSON.parse(require("fs").readFileSync(process.argv[1])); if(r.status!=="Accepted") throw new Error(`Apple notarization: ${r.status}; submission ${r.id}`)' "$release/dmg-notarization.json" |
| 76 | xcrun stapler staple "$release/$artifact" |
| 77 | xcrun stapler validate "$release/$artifact" |
| 78 | spctl --assess --type open --context context:primary-signature --verbose=2 "$release/$artifact" |
| 79 | |
| 80 | |
| 81 | core_version="$(sed -n 's/^version=//p' scripts/fetch-proxy-core.sh)" |
| 82 | core_source="mihomo-$core_version-source.tar.gz" |
| 83 | curl --fail --location --retry 2 --connect-timeout 15 --max-time 180 \ |
| 84 | "https://github.com/MetaCubeX/mihomo/archive/refs/tags/$core_version.tar.gz" \ |
| 85 | -o "$release/$core_source.part" |
| 86 | mv "$release/$core_source.part" "$release/$core_source" |
| 87 | tar -tzf "$release/$core_source" > /dev/null |
| 88 | (cd "$release" && shasum -a 256 "$artifact" "$core_source" "$guest_source" > SHA256SUMS) |
| 89 | node scripts/cleanup-apps.mjs --keep "$bundle" --root "$PWD/_output" |
| 90 | printf 'Verified release artifacts:\n%s/%s\n%s/%s\n%s/%s\n%s/SHA256SUMS\n' "$release" "$artifact" "$release" "$core_source" "$release" "$guest_source" "$release" |