#!/usr/bin/env bash set -euo pipefail umask 077 [[ "$(uname -s)" == Darwin ]] || { echo 'Run this installer on your Mac.' >&2; exit 1; } bb_runtime="$HOME/Library/Application Support/BoxBridge/runtime" bb_node="$bb_runtime/bin/node" if [[ "${1:-}" == --check ]]; then echo 'BoxBridge guided installer: macOS, per-user Node runtime, CLI, Orca and cloud setup.' exit 0 fi mkdir -p "$bb_runtime/bin" bb_stage="$(mktemp -d "$bb_runtime/.first-install.XXXXXX")" trap 'rm -rf "$bb_stage"' EXIT bb_fetch() { /usr/bin/curl --proto '=https' --tlsv1.2 --fail --location --silent --show-error --connect-timeout 20 --max-time 900 "$1" --output "$2"; } if [[ ! -x "$bb_node" ]] || ! "$bb_node" -e 'const [a,b]=process.versions.node.split(".").map(Number);process.exit(a>22||a===22&&b>=16?0:1)' >/dev/null 2>&1; then case "$(uname -m)" in arm64) bb_arch=arm64; bb_hash=c9e1dbc748b33ed2d14f42445191ecaf14c56259c7a9a26d0042c49ec2b66428 ;; x86_64) bb_arch=x64; bb_hash=efcc2b0db6f94bf53eddb038fe2b370277a042bd29e4f19b8f8e23598795b819 ;; *) echo 'Supported Mac architectures: arm64 and x64.' >&2; exit 1 ;; esac echo 'Preparing private Node.js runtime…' >&2 bb_fetch "https://nodejs.org/dist/v22.23.4/node-v22.23.4-darwin-$bb_arch.tar.gz" "$bb_stage/node.tgz" [[ "$(/usr/bin/shasum -a 256 "$bb_stage/node.tgz" | /usr/bin/awk '{print $1}')" == "$bb_hash" ]] || { echo 'Node checksum mismatch; installation stopped.' >&2; exit 1; } /usr/bin/tar -xzf "$bb_stage/node.tgz" -C "$bb_stage" /bin/cp "$bb_stage/node-v22.23.4-darwin-$bb_arch/bin/node" "$bb_stage/node.pending" /bin/chmod 755 "$bb_stage/node.pending" /bin/mv "$bb_stage/node.pending" "$bb_node" fi bb_fetch https://lanshuagent.com/boxbridge/bootstrap-cli.mjs "$bb_stage/bootstrap.mjs" [[ "$(/usr/bin/shasum -a 256 "$bb_stage/bootstrap.mjs" | /usr/bin/awk '{print $1}')" == 3db6733a135d15fe06f958e48cfa1217a00333fcb222ed09a848eeb32dec980f ]] || { echo 'Installer checksum mismatch; installation stopped.' >&2; exit 1; } "$bb_node" "$bb_stage/bootstrap.mjs" "$@"