#!/usr/bin/env bash # shellcheck disable=SC2015,SC2016 # `run ... && ok ... || fail ...`: ok only prints; the PATH lines are written with their $ for the shell that reads them # DIY Platform: development machine setup for macOS (51.40-T28). # # Makes a Mac ready to work on DIY's projects with coding agents: Homebrew, git, Python, the pinned Rust toolchain, Node.js and pnpm at the # versions DIY builds with, and the agent CLIs DIY drives. It sets up a development machine only: DIY Platform itself has no macOS build yet # (a later release), so the app is not installed here. # # curl -fsSL https://install.vibedout.app/diy-setup-macos.sh | bash # curl -fsSL https://install.vibedout.app/diy-setup-macos.sh | bash -s -- --check # bash diy-setup-macos.sh --agents gemini,opencode # these extra agents besides the three always installed (default extras: gemini and pi) # bash diy-setup-macos.sh --dry-run # say what would run, change nothing # bash diy-setup-macos.sh --remove # undo what this script installed (it says what it leaves) # # Sections, in order: # xcode the Command Line Tools (the compilers git, Homebrew and Rust need): macOS asks you in a window, once # brew Homebrew (its own installer), then git, python@3.13, uv, jq and gh from it # rust rustup with Rust RUST_VERSION (and clippy, rustfmt), checked against the sha256 rustup publishes # node Node.js NODE_VERSION (checked against the sha256 below) under ~/.local/share/diy-dev, and pnpm PNPM_VERSION # agents Claude Code, Codex and the Antigravity CLI (agy), always; Gemini CLI and pi, or the extras --agents names (gemini pi opencode) # # Every step checks first and skips what is there, so it is safe to run again. One failed step does not stop the others; the summary at # the end lists it. Run it as yourself, not with sudo. Homebrew needs your password once, the first time: this script asks for it (sudo) # before Homebrew's installer runs, which then installs without asking. # Nothing personal is in this file: no names, no addresses, no keys. It writes PATH lines to ~/.zprofile, marked "# DIY dev". # # Exit: 0 done (or, with --check, nothing missing); 1 something failed or is missing; 2 a usage mistake. set -uo pipefail usage() { # the header above, also when the script is piped (there is no file to read then) cat <<'USAGE' DIY Platform: development machine setup for macOS (51.40-T28). Makes a Mac ready to work on DIY's projects with coding agents: Homebrew, git, Python, the pinned Rust toolchain, Node.js and pnpm at the versions DIY builds with, and the agent CLIs DIY drives. It sets up a development machine only: DIY Platform itself has no macOS build yet (a later release), so the app is not installed here. curl -fsSL https://install.vibedout.app/diy-setup-macos.sh | bash curl -fsSL https://install.vibedout.app/diy-setup-macos.sh | bash -s -- --check bash diy-setup-macos.sh --agents gemini,opencode # these extra agents besides the three always installed (default extras: gemini and pi) bash diy-setup-macos.sh --dry-run # say what would run, change nothing bash diy-setup-macos.sh --remove # undo what this script installed (it says what it leaves) Sections, in order: xcode the Command Line Tools (the compilers git, Homebrew and Rust need): macOS asks you in a window, once brew Homebrew (its own installer), then git, python@3.13, uv, jq and gh from it rust rustup with Rust RUST_VERSION (and clippy, rustfmt), checked against the sha256 rustup publishes node Node.js NODE_VERSION (checked against the sha256 below) under ~/.local/share/diy-dev, and pnpm PNPM_VERSION agents Claude Code, Codex and the Antigravity CLI (agy), always; Gemini CLI and pi, or the extras --agents names (gemini pi opencode) Every step checks first and skips what is there, so it is safe to run again. One failed step does not stop the others; the summary at the end lists it. Run it as yourself, not with sudo. Homebrew needs your password once, the first time: this script asks for it (sudo) before Homebrew's installer runs, which then installs without asking. Nothing personal is in this file: no names, no addresses, no keys. It writes PATH lines to ~/.zprofile, marked "# DIY dev". Exit: 0 done (or, with --check, nothing missing); 1 something failed or is missing; 2 a usage mistake. USAGE } # Everything runs from main, called on the last line: a download cut short is a syntax error and runs nothing (51.40 review 1). # The last line passes --end-of-script after the arguments: a cut inside that line, even at `main` itself, runs nothing (review 2, N6). main() { if [ "$#" -eq 0 ] || [ "${!#}" != --end-of-script ]; then echo "diy-setup-macos.sh: this copy is cut short (the download did not finish): nothing was done. Download it again." >&2 exit 1 fi set -- "${@:1:$#-1}" RUST_VERSION="1.97.1" NODE_VERSION="24.12.0" NODE_SHA256_ARM64="4db2a7842267d4d99e35284289b241c43465b08a28ece4fcb6a9460ce7e4c68c" NODE_SHA256_X64="1e4d54f706e0a3613d6415ffe2ccdfd4095d3483971dbbaa4ff909fac5fc211c" PNPM_VERSION="10.28.1" BREW_FORMULAE="git python@3.13 uv jq gh" CORE_AGENTS="claude codex agy" EXTRA_AGENTS_DEFAULT="gemini,pi" if [ -t 1 ]; then B=$'\e[1m'; G=$'\e[32m'; Y=$'\e[33m'; R=$'\e[31m'; N=$'\e[0m'; else B='' G='' Y='' R='' N=''; fi say() { printf '%s\n' "$*"; } head_() { printf '\n%s-- %s --%s\n' "$B" "$*" "$N"; } ok() { printf ' %sok%s %s\n' "$G" "$N" "$*"; } todo() { printf ' %s->%s %s\n' "$Y" "$N" "$*"; } bad() { printf ' %sx%s %s\n' "$R" "$N" "$*"; } FAILED=() MISSING=() NOTES=() fail() { bad "$*"; FAILED+=("$*"); } need() { todo "$1"; MISSING+=("$1 (fix: $2)"); } CHECK=0 REMOVE=0 DRY=0 AGENTS="${DIY_AGENTS:-$EXTRA_AGENTS_DEFAULT}" while [ $# -gt 0 ]; do case "$1" in --check) CHECK=1 ;; --remove) REMOVE=1 ;; --dry-run) DRY=1 ;; --agents) AGENTS="${2:?--agents needs a list}"; shift ;; --agents=*) AGENTS="${1#*=}" ;; -h|--help) usage; exit 0 ;; *) say "unknown option: $1 (try --help)" >&2; exit 2 ;; esac shift done for a in ${AGENTS//,/ }; do case " $CORE_AGENTS gemini pi opencode " in *" $a "*) ;; *) say "unknown agent: $a (extras: gemini pi opencode)" >&2; exit 2 ;; esac; done [ "$CHECK" = 1 ] && [ "$REMOVE" = 1 ] && { say "--check and --remove do not go together" >&2; exit 2; } [ "$(uname -s)" = Darwin ] || { say "This script is for macOS. Linux: https://install.vibedout.app/diy-setup.sh" >&2; exit 2; } [ "$(id -u)" != 0 ] || { say "Run it as yourself, not with sudo: Homebrew refuses root, and everything else goes into your home folder." >&2; exit 1; } case "$(uname -m)" in arm64) NARCH=arm64; NODE_SHA="$NODE_SHA256_ARM64"; TRIPLE=aarch64-apple-darwin; BREW_PREFIX=/opt/homebrew ;; x86_64) NARCH=x64; NODE_SHA="$NODE_SHA256_X64"; TRIPLE=x86_64-apple-darwin; BREW_PREFIX=/usr/local ;; *) say "$(uname -m) is not one this script knows (arm64, x86_64)" >&2; exit 1 ;; esac BREW_PREFIX="${DIY_BREW_PREFIX:-$BREW_PREFIX}" # where the agents' and Rust's own installers put their commands export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" run() { if [ "$DRY" = 1 ]; then say " would run: $*" >&2; return 0; fi; "$@"; } have() { command -v "$1" >/dev/null 2>&1; } ver() { "$@" 2>/dev/null | head -n 1; } DEV="$HOME/.local/share/diy-dev" NODE_DIR="$DEV/node-v$NODE_VERSION-darwin-$NARCH" STATE_DIR="$HOME/.local/state/diy-dev-macos" STATE="$STATE_DIR/state" state_has() { [ -f "$STATE" ] && grep -qxF "$1" "$STATE"; } state_add() { [ "$DRY" = 1 ] && return 0; mkdir -p "$STATE_DIR"; state_has "$1" || printf '%s\n' "$1" >> "$STATE"; } WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT sha_of() { if have shasum; then shasum -a 256 "$1" | cut -d' ' -f1; else sha256sum "$1" | cut -d' ' -f1; fi; } fetch() { # url file [sha256]: a download that does not match is deleted run curl -fsSL --retry 3 --proto '=https' -o "$2" "$1" || return 1 if [ "$DRY" = 1 ] || [ -z "${3:-}" ]; then return 0; fi local got; got="$(sha_of "$2")" [ "$got" = "$3" ] || { rm -f "$2"; fail "the sha256 of $1 is $got, expected $3: nothing was installed from it"; return 1; } } # PATH lines in ~/.zprofile, each once, marked zprofile_line() { local line="$1 # DIY dev" f="$HOME/.zprofile" grep -qxF "$line" "$f" 2>/dev/null && return 0 if [ "$DRY" = 1 ]; then say " would add to ~/.zprofile: $1"; return 0; fi printf '%s\n' "$line" >> "$f" } brew_path() { [ -x "$BREW_PREFIX/bin/brew" ] && export PATH="$BREW_PREFIX/bin:$PATH"; } want_agent() { case " $CORE_AGENTS " in *" $1 "*) return 0 ;; esac; case ",$AGENTS," in *",$1,"*) return 0 ;; esac; return 1; } # ---- sections ------------------------------------------------------------------------------------------------------------------------ section_xcode() { head_ "Command Line Tools" if xcode-select -p >/dev/null 2>&1; then ok "$(xcode-select -p)"; return; fi if [ "$CHECK" = 1 ]; then need "the Command Line Tools" "xcode-select --install"; return; fi run xcode-select --install >/dev/null 2>&1 || true fail "macOS opened a window to install the Command Line Tools: finish it, then run this script again" } section_brew() { head_ "Homebrew" brew_path if have brew; then ok "$(ver brew --version)" elif [ "$CHECK" = 1 ]; then need "Homebrew" "run this script"; return else local s="$WORK/brew-install.sh" fetch https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh "$s" || { fail "could not download Homebrew's installer"; return; } # Homebrew's installer, run unattended, stops unless sudo is ready: ask for the password here, on the terminal (also when this # script came through curl | bash), then let it run (51.40 review 1) say " Homebrew needs your Mac password once (sudo):" # shellcheck disable=SC2024 # the redirect is the point: sudo reads the password from the terminal, not from the piped script if [ "$DRY" = 0 ]; then if (exec /dev/null; then sudo -v /dev/null; then fail "Homebrew needs sudo, and there is no terminal to ask for the password on: run this in Terminal"; return; fi fi run env NONINTERACTIVE=1 /bin/bash "$s" || { fail "Homebrew's installer failed (above)"; return; } state_add "brew=1"; brew_path have brew || [ "$DRY" = 1 ] || { fail "Homebrew is not on PATH after its installer"; return; } fi [ "$CHECK" = 1 ] || zprofile_line "eval \"\$($BREW_PREFIX/bin/brew shellenv)\"" local f for f in $BREW_FORMULAE; do if [ "$DRY" = 0 ] && brew list --formula "$f" >/dev/null 2>&1; then ok "$f" elif [ "$CHECK" = 1 ]; then need "$f" "brew install $f" else todo "brew install $f"; run brew install -q "$f" >/dev/null && { ok "$f"; state_add "formula=$f"; } || fail "brew install $f"; fi done } section_rust() { head_ "Rust $RUST_VERSION" local rup="$HOME/.cargo/bin/rustup" if [ -x "$HOME/.cargo/bin/rustc" ] && "$HOME/.cargo/bin/rustc" --version 2>/dev/null | grep -q "^rustc $RUST_VERSION "; then ok "$(ver "$HOME/.cargo/bin/rustc" --version)" elif [ "$CHECK" = 1 ]; then need "Rust $RUST_VERSION" "run this script" elif [ -x "$rup" ]; then run "$rup" toolchain install "$RUST_VERSION" --profile minimal -c clippy -c rustfmt && run "$rup" default "$RUST_VERSION" && ok "Rust $RUST_VERSION" || fail "rustup could not install $RUST_VERSION" else fetch "https://static.rust-lang.org/rustup/dist/$TRIPLE/rustup-init.sha256" "$WORK/rustup-init.sha256" || { fail "could not download rustup's checksum"; return; } local want=""; [ "$DRY" = 1 ] || want="$(cut -d' ' -f1 "$WORK/rustup-init.sha256")" fetch "https://static.rust-lang.org/rustup/dist/$TRIPLE/rustup-init" "$WORK/rustup-init" "$want" || return run chmod +x "$WORK/rustup-init" run "$WORK/rustup-init" -y --no-modify-path --profile minimal --default-toolchain "$RUST_VERSION" -c clippy -c rustfmt >/dev/null && { ok "Rust $RUST_VERSION"; state_add "rustup=1"; } || fail "rustup-init failed" fi [ "$CHECK" = 1 ] || zprofile_line 'export PATH="$HOME/.cargo/bin:$PATH"' } section_node() { head_ "Node.js $NODE_VERSION and pnpm $PNPM_VERSION" if [ -x "$NODE_DIR/bin/node" ]; then ok "Node $NODE_VERSION in ${NODE_DIR/#$HOME/~}" elif [ "$CHECK" = 1 ]; then need "Node $NODE_VERSION" "run this script" else fetch "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-$NARCH.tar.xz" "$WORK/node.tar.xz" "$NODE_SHA" || return run mkdir -p "$DEV" && run tar -C "$DEV" -xJf "$WORK/node.tar.xz" && { ok "Node $NODE_VERSION"; state_add "node=$NODE_DIR"; } || { fail "could not unpack Node"; return; } fi [ "$CHECK" = 1 ] || zprofile_line "export PATH=\"$NODE_DIR/bin:\$PATH\"" export PATH="$NODE_DIR/bin:$PATH" if [ -x "$NODE_DIR/bin/pnpm" ] && [ "$("$NODE_DIR/bin/pnpm" --version 2>/dev/null)" = "$PNPM_VERSION" ]; then ok "pnpm $PNPM_VERSION" elif [ "$CHECK" = 1 ]; then need "pnpm $PNPM_VERSION" "run this script" else run "$NODE_DIR/bin/npm" install -g --no-fund --no-audit "pnpm@$PNPM_VERSION" >/dev/null && ok "pnpm $PNPM_VERSION" || fail "npm install -g pnpm@$PNPM_VERSION"; fi } npm_agent() { # command package label if have "$1"; then ok "$3 $(ver "$1" --version)" elif [ "$CHECK" = 1 ]; then need "$3" "npm install -g $2" elif [ ! -x "$NODE_DIR/bin/npm" ] && [ "$DRY" = 0 ]; then fail "$3 needs npm (the node section)" else run "$NODE_DIR/bin/npm" install -g --no-fund --no-audit "$2" >/dev/null && ok "$3" || fail "npm install -g $2"; fi } installer_agent() { # command url label if have "$1"; then ok "$3 $(ver "$1" --version)"; return; fi if [ "$CHECK" = 1 ]; then need "$3" "curl -fsSL $2 | bash"; return; fi fetch "$2" "$WORK/$1-install.sh" || { fail "could not download $3's installer"; return; } if run bash "$WORK/$1-install.sh" >"$WORK/$1-install.log" 2>&1; then ok "$3"; state_add "installer=$1" else fail "$3's installer failed: $(tail -n 3 "$WORK/$1-install.log" 2>/dev/null | tr '\n' ' ')"; fi } section_agents() { head_ "coding agents" installer_agent claude https://claude.ai/install.sh "Claude Code" npm_agent codex @openai/codex "Codex CLI" installer_agent agy https://antigravity.google/cli/install.sh "Antigravity CLI (agy)" if want_agent gemini; then npm_agent gemini @google/gemini-cli "Gemini CLI"; fi if want_agent pi; then npm_agent pi @earendil-works/pi-coding-agent "pi coding agent"; fi if want_agent opencode; then npm_agent opencode opencode-ai "OpenCode"; fi [ "$CHECK" = 1 ] || zprofile_line 'export PATH="$HOME/.local/bin:$PATH"' NOTES+=("Sign in to each agent once (claude, codex, agy$(for a in ${AGENTS//,/ }; do case " $CORE_AGENTS " in *" $a "*) ;; *) printf ', %s' "$a" ;; esac; done)).") } do_remove() { head_ "remove what this script installed" [ -f "$STATE" ] || { say " nothing to remove: this script has not installed anything here (no $STATE)"; return; } local v v="$(sed -n 's/^node=//p' "$STATE")"; [ -z "$v" ] || { case "$v" in "$DEV"/node-v*) run rm -rf "$v"; ok "Node and the agents npm put beside it" ;; esac; } if state_has "rustup=1" && [ -x "$HOME/.cargo/bin/rustup" ]; then run "$HOME/.cargo/bin/rustup" self uninstall -y >/dev/null && ok "rustup and its toolchains"; fi if state_has "installer=claude"; then run rm -rf "$HOME/.local/bin/claude" "$HOME/.local/share/claude" && ok "Claude Code"; fi if state_has "installer=agy"; then NOTES+=("The Antigravity CLI was installed by its own installer: remove it as its documentation says."); fi brew_path while read -r v; do run brew uninstall -q "$v" >/dev/null 2>&1 && ok "brew uninstall $v" || fail "brew uninstall $v"; done < <(sed -n 's/^formula=//p' "$STATE") # written in place, so a ~/.zprofile that is a link (a dotfiles manager) stays a link if [ -f "$HOME/.zprofile" ] && [ "$DRY" = 0 ]; then grep -v ' # DIY dev$' "$HOME/.zprofile" > "$WORK/zprofile"; cat "$WORK/zprofile" > "$HOME/.zprofile"; ok "the PATH lines in ~/.zprofile"; fi state_has "brew=1" && NOTES+=("Homebrew stays (other things use it). Its own uninstaller removes it: https://github.com/Homebrew/install#uninstall-homebrew") NOTES+=("The Command Line Tools stay: sudo rm -rf /Library/Developer/CommandLineTools removes them.") run rm -rf "$STATE_DIR" } # ---- run ------------------------------------------------------------------------------------------------------------------------------- [ "$CHECK" = 1 ] && say "--check: reporting only, nothing will be installed" [ "$DRY" = 1 ] && say "--dry-run: saying what would run, nothing will be changed" if [ "$REMOVE" = 1 ]; then do_remove else section_xcode section_brew section_rust section_node section_agents fi head_ "summary" if [ "$CHECK" = 1 ]; then if [ ${#MISSING[@]} -eq 0 ]; then ok "nothing missing"; else for m in "${MISSING[@]}"; do todo "$m"; done; say " Run without --check to install them."; fi fi for f in "${FAILED[@]+"${FAILED[@]}"}"; do bad "$f"; done [ ${#FAILED[@]} -eq 0 ] || say " Fix the cause and run the script again: finished steps are skipped." for n in "${NOTES[@]+"${NOTES[@]}"}"; do say " ${Y}*${N} $n"; done if [ "$CHECK" = 0 ] && [ "$REMOVE" = 0 ] && [ "$DRY" = 0 ] && [ ${#FAILED[@]} -eq 0 ]; then ok "done. Open a new terminal (so ~/.zprofile is read)."; fi [ ${#FAILED[@]} -eq 0 ] && { [ "$CHECK" = 0 ] || [ ${#MISSING[@]} -eq 0 ]; } } main "$@" --end-of-script