提交记录新增cmd/cage/host_download.go+22 −0看文件
修改cmd/cage/mac_guest_install_darwin_arm64.go+2 −0看文件
修改cmd/cage/main.go+8 −0看文件
修改docs/guide/installation.md+1 −1看文件
修改docs/guide/network.md+4 −2看文件
修改internal/cage/debian-mirrors.sh+5 −1看文件
修改internal/cage/debian_mirrors_test.go+9 −3看文件
修改internal/cage/guest-tools.sh+10 −4看文件
修改internal/cage/guest_mise_test.go+9 −4看文件
修改internal/cage/guest_versions_test.go+1 −4看文件
新增internal/guestos/host_download_test.go+69 −0看文件
修改internal/guestos/maintenance_macos.go+5 −1看文件
新增internal/hostproxy/download.go+119 −0看文件
新增internal/hostproxy/download_test.go+63 −0看文件
修改internal/hostproxy/transport.go+18 −1看文件
修改internal/hostproxy/transport_test.go+26 −0看文件
修改internal/vm/lima.go+1 −1看文件
修改internal/vm/lima_test.go+1 −1看文件
修改internal/workbench/setup_progress.go+31 −12看文件
修改internal/workbench/setup_progress_test.go+17 −0看文件
修改scripts/guest-os/prepare-macos-cli-kit.sh+10 −2看文件
修改scripts/guest-os/prepare-macos-media.sh+10 −2看文件
| @@ -0,0 +1,22 @@ | ||
| 1 | 新增:package main | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "context" | |
| 5 | 新增: "errors" | |
| 6 | 新增: "io" | |
| 7 | 新增: | |
| 8 | 新增: "github.com/sylvinus/agent-vm/internal/hostproxy" | |
| 9 | 新增:) | |
| 10 | 新增: | |
| 11 | 新增:// Private subprocess entry for host installers. Proxy settings are resolved in | |
| 12 | 新增:// Go for every HTTPS request, including redirects and PAC host rules. | |
| 13 | 新增:func hostDownload(ctx context.Context, args []string, out io.Writer) error { | |
| 14 | 新增: if len(args) != 3 && len(args) != 4 { | |
| 15 | 新增: return errors.New("host-download requires URL, staging path, component name and optional Accept value") | |
| 16 | 新增: } | |
| 17 | 新增: accept := "" | |
| 18 | 新增: if len(args) == 4 { | |
| 19 | 新增: accept = args[3] | |
| 20 | 新增: } | |
| 21 | 新增: return hostproxy.Download(ctx, args[0], args[1], args[2], accept, out) | |
| 22 | 新增:} | |
| @@ -17,6 +17,7 @@ import ( | ||
| 17 | 17 | |
| 18 | 18 | "al.essio.dev/pkg/shellescape" |
| 19 | 19 | "github.com/sylvinus/agent-vm/internal/guestos" |
| 20 | 新增: "github.com/sylvinus/agent-vm/internal/hostproxy" | |
| 20 | 21 | "github.com/sylvinus/agent-vm/internal/vm" |
| 21 | 22 | ) |
| 22 | 23 | |
| @@ -64,6 +65,7 @@ func installMacWorkbench(ctx context.Context, profile, state string, l *vm.Lima) | ||
| 64 | 65 | } |
| 65 | 66 | local := func(name string, args ...string) error { |
| 66 | 67 | cmd := exec.CommandContext(ctx, name, args...) |
| 68 | 新增: cmd.Env = append(append(os.Environ(), hostproxy.DownloadEnvironment()...), "CAGE_HOST_DOWNLOADER="+exe) | |
| 67 | 69 | cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr |
| 68 | 70 | return cmd.Run() |
| 69 | 71 | } |
| @@ -88,6 +88,14 @@ func run() int { | ||
| 88 | 88 | os.Unsetenv(name) |
| 89 | 89 | } |
| 90 | 90 | args := os.Args[1:] |
| 91 | 新增: if len(args) > 0 && args[0] == "host-download" { | |
| 92 | 新增: ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) | |
| 93 | 新增: defer cancel() | |
| 94 | 新增: if err := hostDownload(ctx, args[1:], os.Stdout); err != nil { | |
| 95 | 新增: return fail(err) | |
| 96 | 新增: } | |
| 97 | 新增: return 0 | |
| 98 | 新增: } | |
| 91 | 99 | if len(args) == 0 || args[0] == "help" || args[0] == "--help" { |
| 92 | 100 | fmt.Print(help) |
| 93 | 101 | return 0 |
| @@ -60,7 +60,7 @@ Git 保护会修改当前主机用户的全局 `safe.bareRepository=explicit`, | ||
| 60 | 60 | |
| 61 | 61 | 首次安装内容取决于客机系统。克隆入口优先复用已校验的匹配材料,缺少时下载官方镜像。macOS 使用 Apple IPSW;Windows 克隆使用匹配的 Microsoft ESD,手动安装可选择官方 ISO;Linux 克隆使用对应发行版的云镜像。Debian 13 基础镜像约 320–325 MiB,开发工具另行安装。镜像来源、系统许可和存储要求见[客机系统指南](guest-systems.md#下载量与磁盘空间)。 |
| 62 | 62 | |
| 63 | 删除:系统镜像与镜像版本目录通过主机网络下载,遵循主机代理设置,不使用 Cage 为客机选择的节点。使用 Clash 等软件时,先开启其系统代理或 TUN;实际出口仍由该软件对镜像网站的规则决定。已选择的主机代理连接失败、明确配置的 PAC 解析失败时,下载会报错,保留已有文件,不自动回退直连。客机内的进程和开发工具继续使用 Cage 的独立代理,具体平台设置见[系统镜像的下载网络](network.md#系统镜像的下载网络)。 | |
| 63 | 新增:系统镜像、镜像版本目录和在主机上预备的 macOS 应用与开发工具包通过主机网络下载,遵循主机代理设置;未配置代理时直连官方源。使用 Clash 等软件时,可开启其系统代理或 TUN,实际出口由该软件对下载网站的规则决定。已选择的主机代理连接失败、明确配置的 PAC 解析失败时,下载会报错,不自动回退直连。客机内的进程和下载任务使用 Cage 的独立代理,官方源与备用镜像的选择及平台设置见[系统镜像的下载网络](network.md#系统镜像的下载网络)。 | |
| 64 | 64 | |
| 65 | 65 | Debian 初始虚拟磁盘容量上限为 24 GiB,macOS 和 Windows 需为系统及开发工具留出更多空间。实际占用随安装和使用增加,创建前查看所选版本的要求。Claude Desktop 按需单独下载。随后启动会复用工具、文件与登录资料。 |
| 66 | 66 | |
| @@ -69,7 +69,7 @@ Hysteria2 节点可使用 `mport` 指定端口跳跃范围、`pinSHA256` 指定 | ||
| 69 | 69 | |
| 70 | 70 | ## 系统镜像的下载网络 |
| 71 | 71 | |
| 72 | 删除:系统镜像和镜像版本目录使用主机网络,与 Cage 客机的代理节点分开。Clash 等软件只开启“系统代理”也可以接管镜像下载,无需为了 Cage 下载镜像而开启 TUN;下载连接不绑定物理网卡,也不会修改代理软件的节点或规则。镜像网站若被主机代理规则设为直连,Cage 遵循该规则。 | |
| 72 | 新增:系统镜像、镜像版本目录以及在主机上预备的 macOS 应用和开发工具包使用主机网络,与 Cage 客机的代理节点分开。Clash 等软件只开启“系统代理”也可以接管这些下载,无需开启 TUN;下载连接不绑定物理网卡,也不会修改代理软件的节点或规则。下载网站若被主机代理规则设为直连,Cage 遵循该规则;主机未配置代理时使用直连。 | |
| 73 | 73 | |
| 74 | 74 | - macOS:读取系统 HTTP、HTTPS、SOCKS 代理及 PAC,每次请求和重定向按目标地址解析。 |
| 75 | 75 | - Windows:读取当前用户的系统代理;PAC 与自动检测通过 WinHTTP 按目标地址解析。 |
| @@ -77,7 +77,9 @@ Hysteria2 节点可使用 `mport` 指定端口跳跃范围、`pinSHA256` 指定 | ||
| 77 | 77 | |
| 78 | 78 | 从终端启动时,目标协议对应的 `HTTP_PROXY`、`HTTPS_PROXY` 优先于系统设置,`ALL_PROXY` 作为缺省代理,并遵循对应的 `NO_PROXY` 例外。这些主机设置不会传入客机。代理连不上或已配置的 PAC 解析失败时,下载停止,不因失败切换直连;修复主机代理后,在初始化界面继续安装,已有下载会尝试续传。 |
| 79 | 79 | |
| 80 | 删除:客机进程和开发工具安装继续走 Cage 的独立代理。系统镜像下载成功不代表客机网络检查通过,进入工作台仍需完成客机的网络与隔离检查。 | |
| 80 | 新增:系统镜像和开发工具优先使用官方源。Debian 镜像下载失败后尝试提供同一固定版本的国内镜像;Debian 软件源和 Linux 工具在官方源不可用时尝试备用镜像。各下载路径保留原有的摘要、软件包签名或应用签名检查,自定义 Debian 软件源保持原样。 | |
| 81 | 新增: | |
| 82 | 新增:客机进程和在客机内下载的开发工具继续走 Cage 的独立代理。系统镜像下载成功不代表客机网络检查通过,进入工作台仍需完成客机的网络与隔离检查。 | |
| 81 | 83 | |
| 82 | 84 | ## 时区、语言与出口规则 |
| 83 | 85 | |
| @@ -28,7 +28,11 @@ for repository in debian debian-security; do | ||
| 28 | 28 | suite=$(. /etc/os-release; printf '%s' "${VERSION_CODENAME:-trixie}") |
| 29 | 29 | [ "$repository" != debian-security ] || suite="$suite-security" |
| 30 | 30 | priority=0 |
| 31 | 删除: if [ "$preference" = auto ]; then | |
| 31 | 新增: # Prefer the official CDN when it works through the guest's configured | |
| 32 | 新增: # network. Probe domestic mirrors only after the official source fails. | |
| 33 | 新增: if [ "$preference" = auto ] && ! timeout 8 /usr/lib/apt/apt-helper -o Acquire::Retries=0 \ | |
| 34 | 新增: -o Acquire::http::Timeout=5 -o Acquire::https::Timeout=5 \ | |
| 35 | 新增: download-file "$official/dists/$suite/InRelease" "$probe" >/dev/null 2>&1; then | |
| 32 | 36 | for mirror in "https://mirrors.nju.edu.cn/$repository" "https://mirrors.ustc.edu.cn/$repository"; do |
| 33 | 37 | rm -f "$probe" |
| 34 | 38 | if timeout 8 /usr/lib/apt/apt-helper -o Acquire::Retries=0 \ |
| @@ -10,7 +10,7 @@ import ( | ||
| 10 | 10 | |
| 11 | 11 | func TestDebianMirrorFailureFallbackAndPreference(t *testing.T) { |
| 12 | 12 | old := "https://mirrors.nju.edu.cn/debian\tpriority:1\nhttps://mirrors.ustc.edu.cn/debian\tpriority:2\nhttps://deb.debian.org/debian\tpriority:3\n" |
| 13 | 删除: for _, mode := range []string{"reachable", "bookworm", "tls-failure", "nju-failure", "official", "custom", "old", "reboot", "invalid"} { | |
| 13 | 新增: for _, mode := range []string{"reachable", "bookworm", "tls-failure", "official-failure", "nju-failure", "official", "custom", "old", "reboot", "invalid"} { | |
| 14 | 14 | t.Run(mode, func(t *testing.T) { |
| 15 | 15 | dir := t.TempDir() |
| 16 | 16 | mirrors := filepath.Join(dir, "mirrors") |
| @@ -37,7 +37,10 @@ func TestDebianMirrorFailureFallbackAndPreference(t *testing.T) { | ||
| 37 | 37 | "apt-helper": `#!/bin/sh |
| 38 | 38 | printf '%s\n' "$*" >> "$FIXTURE/probes" |
| 39 | 39 | [ "$MODE" != tls-failure ] || exit 1 |
| 40 | 删除:case "$*" in *mirrors.nju*) [ "$MODE" != nju-failure ] || exit 1;; esac | |
| 40 | 新增:case "$*" in | |
| 41 | 新增: *deb.debian.org*) [ "$MODE" != nju-failure ] && [ "$MODE" != official-failure ] || exit 1;; | |
| 42 | 新增: *mirrors.nju*) [ "$MODE" != nju-failure ] || exit 1;; | |
| 43 | 新增:esac | |
| 41 | 44 | exit 0 |
| 42 | 45 | `, |
| 43 | 46 | "timeout": "#!/bin/sh\nshift\nexec \"$@\"\n", |
| @@ -78,7 +81,7 @@ exit 0 | ||
| 78 | 81 | if got != content { |
| 79 | 82 | t.Fatal("custom source overwritten") |
| 80 | 83 | } |
| 81 | 删除: case "official", "tls-failure": | |
| 84 | 新增: case "official", "tls-failure", "reachable", "bookworm", "old", "reboot": | |
| 82 | 85 | if strings.Contains(got, "mirrors.") || !strings.Contains(got, "deb.debian.org") { |
| 83 | 86 | t.Fatal(got) |
| 84 | 87 | } |
| @@ -101,6 +104,9 @@ exit 0 | ||
| 101 | 104 | if err != nil || !strings.Contains(string(probes), "/dists/"+suite+"/InRelease") || !strings.Contains(string(probes), "/dists/"+suite+"-security/InRelease") { |
| 102 | 105 | t.Fatalf("wrong distribution probes: %s, %v", probes, err) |
| 103 | 106 | } |
| 107 | 新增: if strings.Contains(string(probes), "mirrors.") { | |
| 108 | 新增: t.Fatal("reachable official source still contacted domestic mirrors") | |
| 109 | 新增: } | |
| 104 | 110 | } |
| 105 | 111 | if out, err := run(); err != nil { |
| 106 | 112 | t.Fatalf("repeat: %v %s", err, out) |
| @@ -82,7 +82,7 @@ cage_download_tool() ( | ||
| 82 | 82 | for ((attempt=1; attempt<=attempts; attempt++)); do |
| 83 | 83 | url="$upstream" |
| 84 | 84 | part="$artifact.part" |
| 85 | 删除: if [ "$attempt" = 1 ] && [ -n "$mirror" ] && [ ! -s "$part" ]; then | |
| 85 | 新增: if [ "$attempt" = 2 ] && [ -n "$mirror" ] && [ ! -s "$part" ]; then | |
| 86 | 86 | url="$mirror" |
| 87 | 87 | part="$artifact.mirror.part" |
| 88 | 88 | fi |
| @@ -118,6 +118,10 @@ cage_download_tool() ( | ||
| 118 | 118 | fi |
| 119 | 119 | continue |
| 120 | 120 | fi |
| 121 | 新增: if [ "$attempt" = 1 ] && [ -n "$mirror" ] && [ ! -s "$part" ]; then | |
| 122 | 新增: echo 'Official download unavailable; trying the fallback mirror.' >&2 | |
| 123 | 新增: continue | |
| 124 | 新增: fi | |
| 121 | 125 | case "$status" in |
| 122 | 126 | 33|36) rm -f "$artifact.part" ;; # Server cannot resume: next attempt starts at zero. |
| 123 | 127 | 5|6|7|18|28|35|52|55|56|92) ;; # Connection, partial body, TLS EOF or timeout. |
| @@ -163,7 +167,9 @@ cage_install_mise() ( | ||
| 163 | 167 | npm_arch=arm64 |
| 164 | 168 | npm_sum="$CAGE_MISE_NPM_ARM64_SHA256" |
| 165 | 169 | fi |
| 166 | 删除: if [ ! -f "$archive" ] && [ ! -s "$archive.part" ]; then | |
| 170 | 新增: # The GitHub release is preferred. The independently pinned npm archive is | |
| 171 | 新增: # a fallback, including when the official connection cannot make progress. | |
| 172 | 新增: if ! cage_download_tool "$release_url" "$release_sum" "$archive" sha256sum '' 1; then | |
| 167 | 173 | npm_url="https://cdn.npmmirror.com/packages/%40jdxcode/mise-linux-$npm_arch/$wanted/mise-linux-$npm_arch-$wanted.tgz" |
| 168 | 174 | npm_archive="$cache/$npm_sum/mise.tar.gz" |
| 169 | 175 | mkdir -p "${npm_archive%/*}" |
| @@ -171,10 +177,10 @@ cage_install_mise() ( | ||
| 171 | 177 | archive="$npm_archive" |
| 172 | 178 | member=package/bin/mise |
| 173 | 179 | else |
| 174 | 删除: echo 'mise mirror unavailable or failed verification; trying the official release.' >&2 | |
| 180 | 新增: echo 'mise mirror unavailable or failed verification; retrying the official release.' >&2 | |
| 175 | 181 | fi |
| 176 | 182 | fi |
| 177 | 删除: if [ "$member" = mise/bin/mise ]; then | |
| 183 | 新增: if [ "$member" = mise/bin/mise ] && [ ! -f "$archive" ]; then | |
| 178 | 184 | cage_download_tool "$release_url" "$release_sum" "$archive" || return $? |
| 179 | 185 | fi |
| 180 | 186 | if [ "${CAGE_SETUP_PROGRESS:-}" = 1 ]; then echo 'Installing mise...'; fi |
| @@ -36,10 +36,11 @@ func miseArchive(t *testing.T, member, content string) ([]byte, string) { | ||
| 36 | 36 | |
| 37 | 37 | func TestMiseArchivesHaveIndependentPinsResumeAndFallback(t *testing.T) { |
| 38 | 38 | for _, tc := range []struct{ arch, mode, sources string }{ |
| 39 | 删除: {"amd64", "fresh", "npm:0"}, {"arm64", "fresh", "npm:0"}, | |
| 40 | 删除: {"amd64", "bad-mirror", "npm:0 release:0"}, | |
| 41 | 删除: {"arm64", "cached-release", ""}, {"amd64", "partial-release", "release:7"}, {"arm64", "partial-npm", "npm:7"}, | |
| 42 | 删除: {"amd64", "both-corrupt", "npm:0 release:0"}, | |
| 39 | 新增: {"amd64", "fresh", "release:0"}, {"arm64", "fresh", "release:0"}, | |
| 40 | 新增: {"amd64", "official-failure", "release:0 npm:0"}, | |
| 41 | 新增: {"amd64", "bad-mirror", "release:0 npm:0 release:0"}, | |
| 42 | 新增: {"arm64", "cached-release", ""}, {"amd64", "partial-release", "release:7"}, {"arm64", "partial-npm", "release:0 npm:7"}, | |
| 43 | 新增: {"amd64", "both-corrupt", "release:0 npm:0 release:0"}, | |
| 43 | 44 | } { |
| 44 | 45 | t.Run(tc.arch+"/"+tc.mode, func(t *testing.T) { |
| 45 | 46 | dir := t.TempDir() |
| @@ -86,6 +87,10 @@ done | ||
| 86 | 87 | n=0 |
| 87 | 88 | if [ -f "$out" ]; then n=$(wc -c <"$out" | tr -d ' '); fi |
| 88 | 89 | printf '%s:%s\n' "$src" "$n" >> "$HOME/sources" |
| 90 | 新增:if [ "$src" = release ]; then | |
| 91 | 新增: case "$TEST_MODE" in official-failure|partial-npm) printf 503; exit 22;; esac | |
| 92 | 新增: if [ "$TEST_MODE" = bad-mirror ] && [ "$(wc -l < "$HOME/sources" | tr -d ' ')" = 1 ]; then printf 503; exit 22; fi | |
| 93 | 新增:fi | |
| 89 | 94 | if [ "$TEST_MODE" = both-corrupt ] || { [ "$src" = npm ] && [ "$TEST_MODE" = bad-mirror ]; }; then |
| 90 | 95 | printf wrong-archive >"$out" |
| 91 | 96 | else |
| @@ -279,10 +279,7 @@ esac | ||
| 279 | 279 | if _, err := os.Stat(filepath.Join(dir, "installed")); err != nil { |
| 280 | 280 | t.Fatal(err) |
| 281 | 281 | } |
| 282 | 删除: want := "mirror\n" | |
| 283 | 删除: if arch == "amd64" { | |
| 284 | 删除: want += "upstream\n" | |
| 285 | 删除: } | |
| 282 | 新增: want := "upstream\n" | |
| 286 | 283 | if got, err := os.ReadFile(filepath.Join(dir, "sources")); err != nil || string(got) != want { |
| 287 | 284 | t.Fatalf("sources: %q, want %q (%v)", got, want, err) |
| 288 | 285 | } |
| @@ -0,0 +1,69 @@ | ||
| 1 | 新增:package guestos | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "crypto/sha256" | |
| 5 | 新增: "fmt" | |
| 6 | 新增: "os" | |
| 7 | 新增: "os/exec" | |
| 8 | 新增: "path/filepath" | |
| 9 | 新增: "regexp" | |
| 10 | 新增: "strings" | |
| 11 | 新增: "testing" | |
| 12 | 新增:) | |
| 13 | 新增: | |
| 14 | 新增:// Run both real shell entry points, including concurrent CLI downloads and the | |
| 15 | 新增:// GitHub asset fallback. A host helper path with spaces must remain one command. | |
| 16 | 新增:func TestMacMediaUsesHostDownloaderForEveryPackage(t *testing.T) { | |
| 17 | 新增: if _, err := exec.LookPath("bash"); err != nil { | |
| 18 | 新增: t.Skip("bash unavailable") | |
| 19 | 新增: } | |
| 20 | 新增: dir := t.TempDir() | |
| 21 | 新增: digest := fmt.Sprintf("%x", sha256.Sum256([]byte("fixture"))) | |
| 22 | 新增: for _, name := range []string{"prepare-macos-media.sh", "prepare-macos-cli-kit.sh"} { | |
| 23 | 新增: data, err := os.ReadFile(filepath.Join("..", "..", "scripts", "guest-os", name)) | |
| 24 | 新增: if err != nil { | |
| 25 | 新增: t.Fatal(err) | |
| 26 | 新增: } | |
| 27 | 新增: data = regexp.MustCompile(`[a-f0-9]{64}`).ReplaceAll(data, []byte(digest)) | |
| 28 | 新增: if err := os.WriteFile(filepath.Join(dir, name), data, 0700); err != nil { | |
| 29 | 新增: t.Fatal(err) | |
| 30 | 新增: } | |
| 31 | 新增: } | |
| 32 | 新增: for _, name := range []string{"macos-cli.py", "install-macos-cli.sh", "claude-account.py", "cli_channel.py", "cli_channel.resume.md", "claude_account_resume.md"} { | |
| 33 | 新增: if err := os.WriteFile(filepath.Join(dir, name), []byte("fixture"), 0600); err != nil { | |
| 34 | 新增: t.Fatal(err) | |
| 35 | 新增: } | |
| 36 | 新增: } | |
| 37 | 新增: helper := filepath.Join(dir, "Cage helper") | |
| 38 | 新增: body := `#!/bin/sh | |
| 39 | 新增:set -eu | |
| 40 | 新增:test "$1" = host-download | |
| 41 | 新增:printf '%s %s %s\n' "$2" "$4" "${5:-}" >> "$FIXTURE_DOWNLOADS" | |
| 42 | 新增:case "$2" in https://github.com/*) exit 1;; esac | |
| 43 | 新增:case "$2" in https://api.github.com/*) test "$5" = application/octet-stream;; esac | |
| 44 | 新增:printf fixture > "$3" | |
| 45 | 新增:printf 'CAGE_HOST_BYTES %s 7 7\n' "$4" | |
| 46 | 新增:` | |
| 47 | 新增: if err := os.WriteFile(helper, []byte(body), 0700); err != nil { | |
| 48 | 新增: t.Fatal(err) | |
| 49 | 新增: } | |
| 50 | 新增: media := filepath.Join(dir, "media") | |
| 51 | 新增: cmd := exec.CommandContext(t.Context(), "bash", filepath.Join(dir, "prepare-macos-media.sh"), media) | |
| 52 | 新增: cmd.Env = append(os.Environ(), "CAGE_HOST_DOWNLOADER="+helper, "CAGE_REFRESH_TOOLS=1", "FIXTURE_DOWNLOADS="+filepath.Join(dir, "requests")) | |
| 53 | 新增: output, err := cmd.CombinedOutput() | |
| 54 | 新增: if err != nil { | |
| 55 | 新增: t.Fatalf("%v\n%s", err, output) | |
| 56 | 新增: } | |
| 57 | 新增: requests, _ := os.ReadFile(filepath.Join(dir, "requests")) | |
| 58 | 新增: for _, name := range []string{"editor.tgz", "playwright.tgz", "node.tgz", "chrome.dmg", "macos-cli-claude", "macos-cli-uv.tar.gz", "macos-cli-python.tar.gz", "macos-cli-git.tar.gz"} { | |
| 59 | 新增: if !strings.Contains(string(requests), " "+name+" ") || !strings.Contains(string(output), "CAGE_HOST_BYTES "+name+" 7 7") { | |
| 60 | 新增: t.Fatalf("component bypassed host download helper: %s\n%s", name, requests) | |
| 61 | 新增: } | |
| 62 | 新增: } | |
| 63 | 新增: for _, name := range []string{"claude", "uv.tar.gz", "python.tar.gz", "git.tar.gz"} { | |
| 64 | 新增: data, err := os.ReadFile(filepath.Join(media, "cli", name)) | |
| 65 | 新增: if err != nil || string(data) != "fixture" { | |
| 66 | 新增: t.Fatalf("CLI kit not published: %s %v", name, err) | |
| 67 | 新增: } | |
| 68 | 新增: } | |
| 69 | 新增:} | |
| @@ -62,8 +62,12 @@ func MaintainMacOSComponents(ctx context.Context, profile, kit, manifestPath str | ||
| 62 | 62 | cache := filepath.Join(profile, "state", "guest-media", MacOS) |
| 63 | 63 | if tools { |
| 64 | 64 | mode = "tools" |
| 65 | 新增: exe, err := os.Executable() | |
| 66 | 新增: if err != nil { | |
| 67 | 新增: return err | |
| 68 | 新增: } | |
| 65 | 69 | command := exec.CommandContext(ctx, "/bin/bash", filepath.Join(kit, "prepare-macos-media.sh"), cache) |
| 66 | 删除: command.Env = append(os.Environ(), "CAGE_REFRESH_TOOLS=1") | |
| 70 | 新增: command.Env = append(os.Environ(), "CAGE_REFRESH_TOOLS=1", "CAGE_HOST_DOWNLOADER="+exe) | |
| 67 | 71 | command.Stdout, command.Stderr = stdout, stderr |
| 68 | 72 | if err = command.Run(); err != nil { |
| 69 | 73 | return fmt.Errorf("准备原生工具包失败:%w", err) |
| @@ -0,0 +1,119 @@ | ||
| 1 | 新增:package hostproxy | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "context" | |
| 5 | 新增: "errors" | |
| 6 | 新增: "fmt" | |
| 7 | 新增: "io" | |
| 8 | 新增: "net/http" | |
| 9 | 新增: "os" | |
| 10 | 新增: "sync" | |
| 11 | 新增: "time" | |
| 12 | 新增:) | |
| 13 | 新增: | |
| 14 | 新增:// Download prepares host-side application media. The caller owns staging and | |
| 15 | 新增:// checksum verification; this transport never enters a guest environment. | |
| 16 | 新增:func Download(ctx context.Context, address, target, name, accept string, out io.Writer) error { | |
| 17 | 新增: transport := NewTransport() | |
| 18 | 新增: defer transport.CloseIdleConnections() | |
| 19 | 新增: client := &http.Client{Transport: transport, CheckRedirect: func(req *http.Request, previous []*http.Request) error { | |
| 20 | 新增: if req.URL.Scheme != "https" || len(previous) >= 5 { | |
| 21 | 新增: return errors.New("下载重定向无效:只允许 HTTPS,最多跳转五次") | |
| 22 | 新增: } | |
| 23 | 新增: return nil | |
| 24 | 新增: }} | |
| 25 | 新增: var err error | |
| 26 | 新增: for attempt := 0; attempt < 3; attempt++ { | |
| 27 | 新增: err = downloadOnce(ctx, client, address, target, name, accept, out, 60*time.Second) | |
| 28 | 新增: if ctx.Err() != nil { | |
| 29 | 新增: return ctx.Err() | |
| 30 | 新增: } | |
| 31 | 新增: if err == nil { | |
| 32 | 新增: return err | |
| 33 | 新增: } | |
| 34 | 新增: if attempt < 2 { | |
| 35 | 新增: select { | |
| 36 | 新增: case <-ctx.Done(): | |
| 37 | 新增: return ctx.Err() | |
| 38 | 新增: case <-time.After(time.Duration(attempt+1) * time.Second): | |
| 39 | 新增: } | |
| 40 | 新增: } | |
| 41 | 新增: } | |
| 42 | 新增: // Do not include signed redirect URLs or proxy credentials in job output. | |
| 43 | 新增: return errors.New("主机下载失败,请检查主机代理或网络后继续安装;已有安装文件已保留") | |
| 44 | 新增:} | |
| 45 | 新增: | |
| 46 | 新增:func downloadOnce(parent context.Context, client *http.Client, address, target, name, accept string, out io.Writer, idle time.Duration) error { | |
| 47 | 新增: ctx, cancel := context.WithCancel(parent) | |
| 48 | 新增: defer cancel() | |
| 49 | 新增: req, err := http.NewRequestWithContext(ctx, http.MethodGet, address, nil) | |
| 50 | 新增: if err != nil || req.URL.Scheme != "https" || req.URL.User != nil { | |
| 51 | 新增: return errors.New("主机安装材料必须通过 HTTPS 下载") | |
| 52 | 新增: } | |
| 53 | 新增: if accept != "" { | |
| 54 | 新增: req.Header.Set("Accept", accept) | |
| 55 | 新增: } | |
| 56 | 新增: req.Header.Set("Accept-Encoding", "identity") | |
| 57 | 新增: response, err := client.Do(req) | |
| 58 | 新增: if err != nil { | |
| 59 | 新增: return err | |
| 60 | 新增: } | |
| 61 | 新增: defer response.Body.Close() | |
| 62 | 新增: if response.StatusCode != http.StatusOK { | |
| 63 | 新增: return fmt.Errorf("下载返回 HTTP %d", response.StatusCode) | |
| 64 | 新增: } | |
| 65 | 新增: file, err := os.OpenFile(target, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) | |
| 66 | 新增: if err != nil { | |
| 67 | 新增: return err | |
| 68 | 新增: } | |
| 69 | 新增: defer file.Close() | |
| 70 | 新增: // Check the latest activity while holding the same lock used by the body | |
| 71 | 新增: // reader, so a timer already queued cannot cancel a resumed stream. | |
| 72 | 新增: var mu sync.Mutex | |
| 73 | 新增: stopped := false | |
| 74 | 新增: last := time.Now() | |
| 75 | 新增: var timer *time.Timer | |
| 76 | 新增: var check func() | |
| 77 | 新增: check = func() { | |
| 78 | 新增: mu.Lock() | |
| 79 | 新增: defer mu.Unlock() | |
| 80 | 新增: if stopped { | |
| 81 | 新增: return | |
| 82 | 新增: } | |
| 83 | 新增: if remaining := idle - time.Since(last); remaining > 0 { | |
| 84 | 新增: timer.Reset(remaining) | |
| 85 | 新增: } else { | |
| 86 | 新增: cancel() | |
| 87 | 新增: } | |
| 88 | 新增: } | |
| 89 | 新增: timer = time.AfterFunc(idle, check) | |
| 90 | 新增: defer func() { mu.Lock(); defer mu.Unlock(); stopped = true; timer.Stop() }() | |
| 91 | 新增: var received int64 | |
| 92 | 新增: total := max(response.ContentLength, 0) | |
| 93 | 新增: report := func() { fmt.Fprintf(out, "CAGE_HOST_BYTES %s %d %d\n", name, received, total) } | |
| 94 | 新增: report() | |
| 95 | 新增: reported := time.Now() | |
| 96 | 新增: buffer := make([]byte, 128<<10) | |
| 97 | 新增: for { | |
| 98 | 新增: n, readErr := response.Body.Read(buffer) | |
| 99 | 新增: if n > 0 { | |
| 100 | 新增: mu.Lock() | |
| 101 | 新增: last = time.Now() | |
| 102 | 新增: mu.Unlock() | |
| 103 | 新增: if _, err = file.Write(buffer[:n]); err != nil { | |
| 104 | 新增: return err | |
| 105 | 新增: } | |
| 106 | 新增: received += int64(n) | |
| 107 | 新增: } | |
| 108 | 新增: if time.Since(reported) >= time.Second || readErr != nil { | |
| 109 | 新增: report() | |
| 110 | 新增: reported = time.Now() | |
| 111 | 新增: } | |
| 112 | 新增: if readErr == io.EOF { | |
| 113 | 新增: return file.Close() | |
| 114 | 新增: } | |
| 115 | 新增: if readErr != nil { | |
| 116 | 新增: return readErr | |
| 117 | 新增: } | |
| 118 | 新增: } | |
| 119 | 新增:} | |
| @@ -0,0 +1,63 @@ | ||
| 1 | 新增:package hostproxy | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "bytes" | |
| 5 | 新增: "context" | |
| 6 | 新增: "io" | |
| 7 | 新增: "net/http" | |
| 8 | 新增: "net/http/httptest" | |
| 9 | 新增: "os" | |
| 10 | 新增: "path/filepath" | |
| 11 | 新增: "strings" | |
| 12 | 新增: "testing" | |
| 13 | 新增: "time" | |
| 14 | 新增:) | |
| 15 | 新增: | |
| 16 | 新增:func TestHostDownloadRedirectProgressAndAccept(t *testing.T) { | |
| 17 | 新增: server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| 18 | 新增: if r.Header.Get("Accept") != "application/octet-stream" { | |
| 19 | 新增: t.Error("GitHub asset Accept header lost") | |
| 20 | 新增: } | |
| 21 | 新增: if r.URL.Path == "/release" { | |
| 22 | 新增: http.Redirect(w, r, "/asset", http.StatusFound) | |
| 23 | 新增: return | |
| 24 | 新增: } | |
| 25 | 新增: io.WriteString(w, "verified by caller") | |
| 26 | 新增: })) | |
| 27 | 新增: defer server.Close() | |
| 28 | 新增: file := filepath.Join(t.TempDir(), "archive") | |
| 29 | 新增: var output bytes.Buffer | |
| 30 | 新增: if err := downloadOnce(t.Context(), server.Client(), server.URL+"/release", file, "macos-cli-uv.tar.gz", "application/octet-stream", &output, time.Second); err != nil { | |
| 31 | 新增: t.Fatal(err) | |
| 32 | 新增: } | |
| 33 | 新增: got, _ := os.ReadFile(file) | |
| 34 | 新增: if string(got) != "verified by caller" || !strings.Contains(output.String(), "CAGE_HOST_BYTES macos-cli-uv.tar.gz 18 18") { | |
| 35 | 新增: t.Fatalf("body=%q progress=%s", got, &output) | |
| 36 | 新增: } | |
| 37 | 新增:} | |
| 38 | 新增: | |
| 39 | 新增:func TestHostDownloadStallAndCancellation(t *testing.T) { | |
| 40 | 新增: server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| 41 | 新增: w.WriteHeader(200) | |
| 42 | 新增: w.(http.Flusher).Flush() | |
| 43 | 新增: <-r.Context().Done() | |
| 44 | 新增: })) | |
| 45 | 新增: defer server.Close() | |
| 46 | 新增: ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second) | |
| 47 | 新增: defer cancel() | |
| 48 | 新增: start := time.Now() | |
| 49 | 新增: err := downloadOnce(ctx, server.Client(), server.URL, filepath.Join(t.TempDir(), "archive"), "chrome.dmg", "", io.Discard, 30*time.Millisecond) | |
| 50 | 新增: if err == nil || time.Since(start) >= time.Second { | |
| 51 | 新增: t.Fatalf("stalled body did not stop promptly: %v", err) | |
| 52 | 新增: } | |
| 53 | 新增: cancel() | |
| 54 | 新增: if err := Download(ctx, server.URL, filepath.Join(t.TempDir(), "archive"), "chrome.dmg", "", io.Discard); err != context.Canceled { | |
| 55 | 新增: t.Fatalf("cancellation was not preserved: %v", err) | |
| 56 | 新增: } | |
| 57 | 新增:} | |
| 58 | 新增: | |
| 59 | 新增:func TestHostDownloadRejectsPlainHTTP(t *testing.T) { | |
| 60 | 新增: if err := downloadOnce(t.Context(), http.DefaultClient, "http://example.invalid/archive", filepath.Join(t.TempDir(), "archive"), "chrome.dmg", "", io.Discard, time.Second); err == nil { | |
| 61 | 新增: t.Fatal("unencrypted host download accepted") | |
| 62 | 新增: } | |
| 63 | 新增:} | |
| @@ -1,4 +1,4 @@ | ||
| 1 | 删除:// Package hostproxy routes host-side system image requests through the host's | |
| 1 | 新增:// Package hostproxy routes host-side image and application requests through the host's | |
| 2 | 2 | // proxy settings. Guest traffic must continue to use cage.Egress instead. |
| 3 | 3 | package hostproxy |
| 4 | 4 | |
| @@ -56,6 +56,23 @@ func NewTransport() *http.Transport { | ||
| 56 | 56 | return transport(©, systemProxy) |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 新增:// DownloadEnvironment restores only the captured proxy variables for a host | |
| 60 | 新增:// downloader subprocess. Callers must not pass these into guest operations. | |
| 61 | 新增:func DownloadEnvironment() []string { | |
| 62 | 新增: environment.Lock() | |
| 63 | 新增: defer environment.Unlock() | |
| 64 | 新增: cfg := environment.config | |
| 65 | 新增: if cfg == nil { | |
| 66 | 新增: cfg = readEnvironment() | |
| 67 | 新增: } | |
| 68 | 新增: return []string{ | |
| 69 | 新增: "HTTP_PROXY=" + cfg.HTTPProxy, "http_proxy=" + cfg.HTTPProxy, | |
| 70 | 新增: "HTTPS_PROXY=" + cfg.HTTPSProxy, "https_proxy=" + cfg.HTTPSProxy, | |
| 71 | 新增: "NO_PROXY=" + cfg.NoProxy, "no_proxy=" + cfg.NoProxy, | |
| 72 | 新增: "ALL_PROXY=", "all_proxy=", | |
| 73 | 新增: } | |
| 74 | 新增:} | |
| 75 | 新增: | |
| 59 | 76 | func transport(env *httpproxy.Config, system func(*http.Request) (*url.URL, error)) *http.Transport { |
| 60 | 77 | envProxy := env.ProxyFunc() |
| 61 | 78 | return &http.Transport{ |
| @@ -126,6 +126,32 @@ func TestHTTPOnlyEnvironmentKeepsHTTPSSystemProxy(t *testing.T) { | ||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 新增:func TestHostDownloadSubprocessKeepsCapturedProxyAfterGuestSanitization(t *testing.T) { | |
| 130 | 新增: environment.Lock() | |
| 131 | 新增: previous := environment.config | |
| 132 | 新增: environment.config = nil | |
| 133 | 新增: environment.Unlock() | |
| 134 | 新增: t.Cleanup(func() { environment.Lock(); environment.config = previous; environment.Unlock() }) | |
| 135 | 新增: t.Setenv("HTTPS_PROXY", "http://127.0.0.1:7896") | |
| 136 | 新增: t.Setenv("HTTP_PROXY", "http://127.0.0.1:7896") | |
| 137 | 新增: t.Setenv("NO_PROXY", "skip.invalid") | |
| 138 | 新增: t.Setenv("no_proxy", "skip.invalid") | |
| 139 | 新增: t.Setenv("https_proxy", "") | |
| 140 | 新增: t.Setenv("http_proxy", "") | |
| 141 | 新增: CaptureEnvironment() | |
| 142 | 新增: t.Setenv("HTTPS_PROXY", "") | |
| 143 | 新增: t.Setenv("HTTP_PROXY", "") | |
| 144 | 新增: t.Setenv("NO_PROXY", "") | |
| 145 | 新增: t.Setenv("no_proxy", "") | |
| 146 | 新增: got := strings.Join(DownloadEnvironment(), "\n") | |
| 147 | 新增: if !strings.Contains(got, "HTTPS_PROXY=http://127.0.0.1:7896") || !strings.Contains(got, "NO_PROXY=skip.invalid") { | |
| 148 | 新增: t.Fatalf("host subprocess lost captured proxy settings: %s", got) | |
| 149 | 新增: } | |
| 150 | 新增: if os.Getenv("HTTPS_PROXY") != "" { | |
| 151 | 新增: t.Fatal("host settings were restored into the guest process environment") | |
| 152 | 新增: } | |
| 153 | 新增:} | |
| 154 | 新增: | |
| 129 | 155 | // Run manually to verify the real system proxy without changing host settings. |
| 130 | 156 | func TestLiveSystemProxyDownload(t *testing.T) { |
| 131 | 157 | if testing.Short() { |
| @@ -357,7 +357,7 @@ func cageDebianImages(images []limatype.Image) ([]byte, error) { | ||
| 357 | 357 | if !ok || img.Variant != "genericcloud" || img.Digest.Validate() != nil || img.Digest.Algorithm() != "sha512" { |
| 358 | 358 | continue |
| 359 | 359 | } |
| 360 | 删除: for _, base := range []string{"https://mirrors.nju.edu.cn/debian-cdimage/cloud/", "https://mirrors.ustc.edu.cn/debian-cdimage/cloud/", upstream} { | |
| 360 | 新增: for _, base := range []string{upstream, "https://mirrors.nju.edu.cn/debian-cdimage/cloud/", "https://mirrors.ustc.edu.cn/debian-cdimage/cloud/"} { | |
| 361 | 361 | candidate := img |
| 362 | 362 | candidate.Location = base + suffix |
| 363 | 363 | candidates = append(candidates, candidate) |
| @@ -86,7 +86,7 @@ func TestCageDebianMirrors(t *testing.T) { | ||
| 86 | 86 | if len(images) != 3 { |
| 87 | 87 | t.Fatalf("%s: expected two mirrors and one upstream, got %+v", arch, images) |
| 88 | 88 | } |
| 89 | 删除: for i, base := range []string{"https://mirrors.nju.edu.cn/debian-cdimage/cloud/", "https://mirrors.ustc.edu.cn/debian-cdimage/cloud/", "https://cloud.debian.org/images/cloud/"} { | |
| 89 | 新增: for i, base := range []string{"https://cloud.debian.org/images/cloud/", "https://mirrors.nju.edu.cn/debian-cdimage/cloud/", "https://mirrors.ustc.edu.cn/debian-cdimage/cloud/"} { | |
| 90 | 90 | if !strings.HasPrefix(images[i].Location, base) || images[i].Digest != images[2].Digest || images[i].Digest.Validate() != nil { |
| 91 | 91 | t.Fatalf("unexpected image or missing pin: %+v", images[i]) |
| 92 | 92 | } |
| @@ -20,6 +20,24 @@ type SetupProgress struct { | ||
| 20 | 20 | // continues through the existing redacted operation log. |
| 21 | 21 | func parseSetupProgress(line string) *SetupProgress { |
| 22 | 22 | line = strings.TrimSpace(line) |
| 23 | 新增: if strings.HasPrefix(line, "CAGE_HOST_BYTES ") { | |
| 24 | 新增: fields := strings.Fields(line) | |
| 25 | 新增: if len(fields) != 4 { | |
| 26 | 新增: return nil | |
| 27 | 新增: } | |
| 28 | 新增: label := macOSDownloadLabel(fields[1]) | |
| 29 | 新增: received, err := strconv.ParseInt(fields[2], 10, 64) | |
| 30 | 新增: total, te := strconv.ParseInt(fields[3], 10, 64) | |
| 31 | 新增: if label == "" || err != nil || te != nil || received < 0 || total < 0 || total > 0 && received > total { | |
| 32 | 新增: return nil | |
| 33 | 新增: } | |
| 34 | 新增: return &SetupProgress{Phase: "image", Label: label, System: "macos", Operation: "download", Received: &received, Total: total} | |
| 35 | 新增: } | |
| 36 | 新增: if strings.HasPrefix(line, "下载 ") { | |
| 37 | 新增: if label := macOSDownloadLabel(strings.TrimPrefix(line, "下载 ")); label != "" { | |
| 38 | 新增: return &SetupProgress{Phase: "image", Label: label, System: "macos"} | |
| 39 | 新增: } | |
| 40 | 新增: } | |
| 23 | 41 | if strings.HasPrefix(line, "CAGE_GUEST_BYTES ") { |
| 24 | 42 | fields := strings.Fields(line) |
| 25 | 43 | if len(fields) != 5 { |
| @@ -107,18 +125,6 @@ func parseSetupProgress(line string) *SetupProgress { | ||
| 107 | 125 | return p |
| 108 | 126 | } |
| 109 | 127 | switch line { |
| 110 | 删除: case "下载 editor.tgz": | |
| 111 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载 macOS 网页编辑器", System: "macos"} | |
| 112 | 删除: case "下载 playwright.tgz": | |
| 113 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载浏览器控制组件", System: "macos"} | |
| 114 | 删除: case "下载 node.tgz": | |
| 115 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载 Node.js", System: "macos"} | |
| 116 | 删除: case "下载 macfuse.dmg": | |
| 117 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载 macFUSE 文件共享组件", System: "macos"} | |
| 118 | 删除: case "下载 claude.dmg": | |
| 119 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载 Claude Desktop", System: "macos"} | |
| 120 | 删除: case "下载 chrome.dmg": | |
| 121 | 删除: return &SetupProgress{Phase: "image", Label: "正在下载 Chrome 浏览器", System: "macos"} | |
| 122 | 128 | case "CAGE_IMAGE_READY": |
| 123 | 129 | return &SetupProgress{Phase: "image", Label: "正在启动 Linux 基础环境"} |
| 124 | 130 | case "CAGE_IMAGE_VERIFY": |
| @@ -144,6 +150,19 @@ func parseSetupProgress(line string) *SetupProgress { | ||
| 144 | 150 | return nil |
| 145 | 151 | } |
| 146 | 152 | |
| 153 | 新增:func macOSDownloadLabel(name string) string { | |
| 154 | 新增: component := map[string]string{ | |
| 155 | 新增: "editor.tgz": "macOS 网页编辑器", "playwright.tgz": "浏览器控制组件", "node.tgz": "Node.js", | |
| 156 | 新增: "macfuse.dmg": "macFUSE 文件共享组件", "claude.dmg": "Claude Desktop", "chrome.dmg": "Chrome 浏览器", | |
| 157 | 新增: "macos-cli-claude": "Claude Code", "macos-cli-uv.tar.gz": "uv 开发工具", | |
| 158 | 新增: "macos-cli-python.tar.gz": "Python", "macos-cli-git.tar.gz": "Git", | |
| 159 | 新增: }[name] | |
| 160 | 新增: if component == "" { | |
| 161 | 新增: return "" | |
| 162 | 新增: } | |
| 163 | 新增: return "正在下载 " + component | |
| 164 | 新增:} | |
| 165 | 新增: | |
| 147 | 166 | func guestProgressName(system string) string { |
| 148 | 167 | return map[string]string{"macos": "macOS", "windows-11": "Windows 11", "debian-12": "Debian 12", "debian-13": "Debian 13", "ubuntu-22.04": "Ubuntu 22.04", "ubuntu-24.04": "Ubuntu 24.04"}[system] |
| 149 | 168 | } |
| @@ -93,3 +93,20 @@ func TestToolProgressUsesOnlyKnownPackageNames(t *testing.T) { | ||
| 93 | 93 | t.Fatalf("excess bytes entered UI: %+v", p) |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 新增: | |
| 97 | 新增:func TestMacHostDownloadsReplacePreviousComponentProgress(t *testing.T) { | |
| 98 | 新增: for _, name := range []string{"chrome.dmg", "macos-cli-claude", "macos-cli-uv.tar.gz", "macos-cli-python.tar.gz", "macos-cli-git.tar.gz"} { | |
| 99 | 新增: p := parseSetupProgress("CAGE_HOST_BYTES " + name + " 25 100") | |
| 100 | 新增: if p == nil || p.System != "macos" || p.Total != 100 || *p.Received != 25 { | |
| 101 | 新增: t.Fatalf("missing host component progress: %s %+v", name, p) | |
| 102 | 新增: } | |
| 103 | 新增: if p := parseSetupProgress("下载 " + name); p == nil || p.Received != nil { | |
| 104 | 新增: t.Fatalf("missing component start: %s %+v", name, p) | |
| 105 | 新增: } | |
| 106 | 新增: } | |
| 107 | 新增: for _, line := range []string{"CAGE_HOST_BYTES unknown 1 2", "CAGE_HOST_BYTES chrome.dmg 3 2", "CAGE_HOST_BYTES chrome.dmg -1 2"} { | |
| 108 | 新增: if p := parseSetupProgress(line); p != nil { | |
| 109 | 新增: t.Fatalf("invalid host progress: %s", line) | |
| 110 | 新增: } | |
| 111 | 新增: } | |
| 112 | 新增:} | |
| @@ -7,6 +7,13 @@ umask 077 | ||
| 7 | 7 | src=$(cd "$(dirname "$0")" && pwd) |
| 8 | 8 | stage=$(mktemp -d "$(dirname "$1")/.cage-cli-kit.XXXXXXXX") |
| 9 | 9 | trap 'rm -rf "$stage"' EXIT |
| 10 | 新增:fetch() { | |
| 11 | 新增: if [[ -n ${CAGE_HOST_DOWNLOADER:-} ]]; then | |
| 12 | 新增: "$CAGE_HOST_DOWNLOADER" host-download "$1" "$2" "macos-cli-$3" "${4:-}" | |
| 13 | 新增: else | |
| 14 | 新增: curl --disable --proto '=https' --proto-redir '=https' --location --fail --silent --show-error --connect-timeout 15 --speed-time 60 --speed-limit 1 --retry 2 -H "Accept: ${4:-*/*}" "$1" -o "$2" | |
| 15 | 新增: fi | |
| 16 | 新增:} | |
| 10 | 17 | download() { |
| 11 | 18 | local name=$1 url=$2 digest=$3 api=$4 |
| 12 | 19 | # An existing guest may already have the exact signed release archives. |
| @@ -15,9 +22,10 @@ download() { | ||
| 15 | 22 | cp "$cache/$name" "$stage/$name" |
| 16 | 23 | if [[ $(shasum -a 256 "$stage/$name" | cut -d' ' -f1) == "$digest" ]]; then return; fi |
| 17 | 24 | fi |
| 18 | 删除: if ! curl --proto '=https' --proto-redir '=https' --location --fail --silent --show-error --connect-timeout 15 --max-time 600 --retry 2 "$url" -o "$stage/$name"; then | |
| 25 | 新增: printf '下载 macos-cli-%s\n' "$name" | |
| 26 | 新增: if ! fetch "$url" "$stage/$name" "$name"; then | |
| 19 | 27 | [[ -n $api ]] || return 1 |
| 20 | 删除: curl --proto '=https' --proto-redir '=https' --location --fail --silent --show-error --connect-timeout 15 --max-time 600 --retry 2 -H 'Accept: application/octet-stream' "$api" -o "$stage/$name" | |
| 28 | 新增: fetch "$api" "$stage/$name" "$name" application/octet-stream | |
| 21 | 29 | fi |
| 22 | 30 | [[ $(shasum -a 256 "$stage/$name" | cut -d' ' -f1) == "$digest" ]] |
| 23 | 31 | } |
| @@ -6,6 +6,14 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin | ||
| 6 | 6 | media=$1 |
| 7 | 7 | src=$(cd "$(dirname "$0")" && pwd) |
| 8 | 8 | mkdir -p "$media" |
| 9 | 新增:fetch() { | |
| 10 | 新增: if [[ -n ${CAGE_HOST_DOWNLOADER:-} ]]; then | |
| 11 | 新增: "$CAGE_HOST_DOWNLOADER" host-download "$1" "$2" "$3" "${4:-}" | |
| 12 | 新增: else | |
| 13 | 新增: # Standalone source builds can supply curl proxy environment variables. | |
| 14 | 新增: curl --disable -fsSL --proto '=https' --proto-redir '=https' --retry 2 --connect-timeout 15 --speed-time 60 --speed-limit 1 -H "Accept: ${4:-*/*}" "$1" -o "$2" | |
| 15 | 新增: fi | |
| 16 | 新增:} | |
| 9 | 17 | download() { |
| 10 | 18 | local name=$1 url=$2 expected=$3 api=${4:-} |
| 11 | 19 | local target="$media/$name" temporary |
| @@ -15,8 +23,8 @@ download() { | ||
| 15 | 23 | fi |
| 16 | 24 | printf '下载 %s\n' "$name" |
| 17 | 25 | temporary=$(mktemp "$media/.$name.XXXXXXXX") |
| 18 | 删除: if ! curl --disable -fsSL --proto '=https' --proto-redir '=https' --retry 2 --connect-timeout 15 --speed-time 90 --speed-limit 1024 "$url" -o "$temporary"; then | |
| 19 | 删除: if [[ -z $api ]] || ! curl --disable -fsSL --proto '=https' --proto-redir '=https' --retry 2 --connect-timeout 15 --speed-time 90 --speed-limit 1024 -H 'Accept: application/octet-stream' "$api" -o "$temporary"; then | |
| 26 | 新增: if ! fetch "$url" "$temporary" "$name"; then | |
| 27 | 新增: if [[ -z $api ]] || ! fetch "$api" "$temporary" "$name" application/octet-stream; then | |
| 20 | 28 | rm "$temporary" |
| 21 | 29 | return 1 |
| 22 | 30 | fi |

