| 1 | #!/bin/bash |
| 2 | |
| 3 | set -euo pipefail |
| 4 | export PATH=/usr/bin:/bin:/usr/sbin:/sbin |
| 5 | [[ $# == 1 && $1 == /* ]] |
| 6 | media=$1 |
| 7 | src=$(cd "$(dirname "$0")" && pwd) |
| 8 | mkdir -p "$media" |
| 9 | export CAGE_HOST_DOWNLOAD_CACHE="$media/.downloads" |
| 10 | fetch() { |
| 11 | if [[ -n ${CAGE_HOST_DOWNLOADER:-} ]]; then |
| 12 | "$CAGE_HOST_DOWNLOADER" host-download "$1" "$2" "$3" "${4:-}" "$CAGE_HOST_DOWNLOAD_CACHE" "$5" |
| 13 | else |
| 14 | |
| 15 | 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" |
| 16 | fi |
| 17 | } |
| 18 | download() { |
| 19 | local name=$1 url=$2 expected=$3 api=${4:-} |
| 20 | local target="$media/$name" temporary |
| 21 | [[ ! -L $target && ( ! -e $target || -f $target ) ]] |
| 22 | if [[ -f $target && ! -L $target ]]; then |
| 23 | if [[ -z $expected && ${CAGE_REFRESH_TOOLS:-} != 1 ]] || [[ -n $expected && $(shasum -a 256 "$target" | cut -d' ' -f1) == "$expected" ]]; then return; fi |
| 24 | fi |
| 25 | printf '下载 %s\n' "$name" |
| 26 | temporary=$(mktemp "$media/.$name.XXXXXXXX") |
| 27 | if ! fetch "$url" "$temporary" "$name" "" "$expected"; then |
| 28 | if [[ -z $api ]] || ! fetch "$api" "$temporary" "$name" application/octet-stream "$expected"; then |
| 29 | rm "$temporary" |
| 30 | return 1 |
| 31 | fi |
| 32 | fi |
| 33 | if [[ -n $expected && $(shasum -a 256 "$temporary" | cut -d' ' -f1) != "$expected" ]]; then |
| 34 | rm "$temporary" |
| 35 | return 1 |
| 36 | fi |
| 37 | mv "$temporary" "$target" |
| 38 | } |
| 39 | download editor.tgz https://github.com/coder/code-server/releases/download/v4.145.0/code-server-4.145.0-macos-arm64.tar.gz a79774d8d34eed785c1f831bc0125f7534bc21a0039bef8e8a2aa32463f9421a https://api.github.com/repos/coder/code-server/releases/assets/711206948 |
| 40 | download playwright.tgz https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.0.tgz 315247c55a793ca760b2f05bdcee0e6a53fd65b1f22d1d3de8323c8c9395add3 |
| 41 | download node.tgz https://nodejs.org/dist/v24.22.2/node-v24.22.2-darwin-arm64.tar.gz aa9549349e47dffaa42dcf95d6e06ade8c4bdafc980979883b88767670df385a |
| 42 | if [[ ${CAGE_REFRESH_TOOLS:-} != 1 ]]; then |
| 43 | download macfuse.dmg https://github.com/macfuse/macfuse/releases/download/macfuse-5.5.0/macfuse-5.5.0.dmg 92c21ef2db4199bcf5bddc8e6efb57b23ecb9715f74ab38cba2c77ab226d3830 |
| 44 | if [[ ! -f $media/macfuse.pkg ]]; then bash "$src/macos-fuse-media.sh" "$media/macfuse.dmg" "$media/macfuse.pkg"; fi |
| 45 | download claude.dmg https://downloads.claude.ai/releases/darwin/universal/4.23118.0/Claude-8175c354eda704cea00fdeddfa69cea329dd321a.dmg 0e3d86a8b7ac6d7e6a3de011134db1717716fa6ecbe323f5ea4a5356fba62810 |
| 46 | fi |
| 47 | download chrome.dmg https://dl.google.com/chrome/mac/universal/stable/GGRO/googlechrome.dmg '' |
| 48 | if [[ ! -f $media/cli/git.tar.gz || ${CAGE_REFRESH_TOOLS:-} == 1 ]]; then |
| 49 | fresh=$(mktemp -d "$media/.cli-repair.XXXXXXXX") |
| 50 | if ! bash "$src/prepare-macos-cli-kit.sh" "$fresh/cli" "$media/cli"; then |
| 51 | rmdir "$fresh" |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | |
| 56 | if [[ -d $media/cli ]]; then mv "$media/cli" "$fresh/previous"; fi |
| 57 | mv "$fresh/cli" "$media/cli" |
| 58 | rm -rf "$fresh" |
| 59 | fi |
| 60 | |
| 61 | |
| 62 | |
| 63 | for name in install-macos-cli.sh macos-cli.py cli_channel.py cli_channel.resume.md claude_account_resume.md claude-account.py; do |
| 64 | if [[ -f $src/$name ]]; then |
| 65 | [[ ! -L $media/cli/$name ]] |
| 66 | cp "$src/$name" "$media/cli/$name" |
| 67 | fi |
| 68 | done |