#!/bin/bash set -euo pipefail version=1.6.0 dmg_sha=3b9ca1ed2cc2524dc24b52fc395beac8798b481d8e7e33de9e2fe055a1b9d9be plugins_commit=faeebf5705ea68874fbbf5638545415ded06836e plugins_sha=530281d431c1ffd5ace24730701022f1615eefe61cfe99b7b609371cec6cba8b local_backend=http://127.0.0.1:8765 app_id=app.joebro.production requirement='=identifier "app.joebro.production" and anchor apple generic and certificate leaf[subject.OU] = "D9GFBLXV7L"' temp='' stage='' mounted=no destination='' lock='' if [ -t 1 ]; then c_v=$'\033[38;5;105m' c_d=$'\033[2m' c_b=$'\033[1m' c_0=$'\033[0m' else c_v='' c_d='' c_b='' c_0='' fi say() { printf ' %s›%s %s\n' "$c_v" "$c_0" "$*"; } banner() { printf '\n%s' "$c_v" printf '%s\n' \ ' .:-.' \ ' =%@@%=' \ ' -==-' \ '' \ ' :+**+' \ ' +%%%+' \ ' +%%%+' \ ' . +%%%+' \ ' +%+. .*%%%=' \ ' =#%%%%%#+.' printf '%s\n %sjoebro%s %s· the mac workspace for your agents%s\n\n' "$c_0" "$c_b" "$c_0" "$c_d" "$c_0" } fail() { printf 'JoeBro: %s\n' "$*" >&2; exit 1; } macos_version() { sw_vers -productVersion; } app_version() { /usr/libexec/PlistBuddy -c "Print :$2" "$1/Contents/Info.plist"; } app_running() { [ -n "$(/usr/bin/lsappinfo find "bundleID=$app_id" 2>/dev/null)" ]; } find_python() { local candidate for candidate in /Library/Developer/CommandLineTools/usr/bin/python3 \ /Applications/Xcode.app/Contents/Developer/usr/bin/python3 \ /opt/homebrew/bin/python3 /usr/local/bin/python3; do if [ -x "$candidate" ] && "$candidate" -c 'import sys; sys.exit(sys.version_info < (3, 9))'; then printf '%s\n' "$candidate" return fi done if xcode-select -p >/dev/null 2>&1 && /usr/bin/python3 -c 'import sys; sys.exit(sys.version_info < (3, 9))' 2>/dev/null; then printf '%s\n' /usr/bin/python3 return fi return 1 } require_python() { local attempt if python=$(find_python); then return fi say 'Apple Command Line Tools provide Python for JoeBro. Finish installation in the macOS dialog.' if ! xcode-select --install; then fail 'Install Apple Command Line Tools or Python 3.9+, then run this command again.' fi for ((attempt = 0; attempt < 120; attempt++)); do sleep 5 if python=$(find_python); then return fi done fail 'Apple Command Line Tools are still unavailable. Run this command again once the installation finishes.' } verified_download() { curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 --connect-timeout 15 --max-time 180 "$1" -o "$2" local actual actual=$(shasum -a 256 "$2") [ "${actual%% *}" = "$3" ] || fail "The checksum did not match for ${2##*/}." } cleanup() { if [ -n "$stage" ] && [ -d "$stage" ]; then if [ -e "$stage/previous.app" ] && [ ! -e "$destination" ]; then mv "$stage/previous.app" "$destination" || { printf 'Your previous app remains at %s\n' "$stage/previous.app" >&2 stage='' } fi [ -z "$stage" ] || rm -rf "$stage" fi if [ "$mounted" = yes ]; then if ! hdiutil detach "$temp/mount" -quiet && ! hdiutil detach "$temp/mount" -force -quiet; then printf 'JoeBro: eject the installer disk image in Finder.\n' >&2 else mounted=no fi fi if [ "$mounted" = no ] && [ -n "$temp" ]; then rm -rf "$temp" fi [ -z "$lock" ] || rmdir "$lock" } at_least_release() { "$python" - "$1" "$version" <<'PY' import re import sys def components(version): numeric = version.split('-')[0].split('.') if not all(re.fullmatch(r'[0-9]+', part) for part in numeric): raise ValueError(version) return tuple(map(int, (numeric + ['0', '0', '0'])[:3])) try: installed, release = map(components, sys.argv[1:]) except ValueError: sys.exit(1) sys.exit(installed < release) PY } wait_for_quit() { local attempt app_running || return 0 say 'Quit JoeBro from its menu so the installer can update it.' for ((attempt = 0; attempt < 60; attempt++)); do sleep 1 app_running || return 0 done fail 'JoeBro is still open. Quit it and run this command again.' } install_app() { local app_dir=/Applications installed='' candidate if [ -d "$HOME/Applications/JoeBro.app" ] || [ ! -w "$app_dir" ]; then app_dir="$HOME/Applications" fi destination="$app_dir/JoeBro.app" # Reuse an official current bundle wherever the user installed it. for candidate in "$HOME/Applications/JoeBro.app" /Applications/JoeBro.app; do if [ -d "$candidate" ] && codesign --verify --strict -R "$requirement" "$candidate" 2>/dev/null && installed=$(app_version "$candidate" CFBundleShortVersionString) && at_least_release "$installed"; then destination=$candidate say "JoeBro $installed is already installed." return fi done if [ -e "$destination" ] || [ -L "$destination" ]; then [ ! -L "$destination" ] && [ "$(app_version "$destination" CFBundleIdentifier)" = "$app_id" ] || fail "A different app is already at $destination." fi say "Downloading JoeBro $version…" verified_download "https://github.com/joexk1/JoeBro/releases/download/v$version/JoeBro-$version.dmg" "$temp/JoeBro.dmg" "$dmg_sha" mkdir "$temp/mount" hdiutil attach "$temp/JoeBro.dmg" -mountpoint "$temp/mount" -readonly -nobrowse -quiet mounted=yes codesign --verify --deep --strict -R "$requirement" "$temp/mount/JoeBro.app" mkdir -p "$app_dir" stage=$(mktemp -d "$app_dir/.joebro-install.XXXXXXXX") ditto "$temp/mount/JoeBro.app" "$stage/JoeBro.app" wait_for_quit if [ -e "$destination" ]; then mv "$destination" "$stage/previous.app" fi mv "$stage/JoeBro.app" "$destination" rm -rf "$stage" stage='' say "Installed $destination" } find_agents() { export PATH="$PATH:$HOME/.local/bin:$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.opencode/bin:$HOME/.claude/local:/opt/homebrew/bin:/usr/local/bin" claude_bin=$(command -v claude || true) if [ -z "$claude_bin" ] && [ -x "$HOME/.claude/local/claude" ]; then claude_bin="$HOME/.claude/local/claude" fi if [ -n "$claude_bin" ] || [ -d "$HOME/.claude" ]; then mkdir -p "$HOME/.claude" agents+=(--claude) fi if command -v codex >/dev/null || [ -d "$HOME/.codex" ]; then mkdir -p "$HOME/.codex" agents+=(--codex) fi if command -v opencode >/dev/null || [ -d "$HOME/.config/opencode" ]; then mkdir -p "$HOME/.config/opencode" agents+=(--opencode) fi } install_plugins() { local archive="$temp/joebro-plugins.tar.gz" local source="$temp/joebro-plugins-$plugins_commit" runner="$HOME/.local/bin/joebro-agents" if [ "${#agents[@]}" -eq 0 ]; then say 'No Claude Code, Codex, or OpenCode installation found. Run this command again after installing one.' return fi tar -xzf "$archive" -C "$temp" # Run from the checkout so the official installer can find the OpenCode plugin. "$python" "$source/bin/joebro-agents" install "${agents[@]}" if [ -n "$claude_bin" ]; then if ! "$claude_bin" mcp add --scope user joebro -- "$runner" mcp; then "$claude_bin" mcp get joebro >/dev/null 2>&1 || fail 'Claude Code hooks are installed, but Claude Code could not add the JoeBro MCP server.' fi elif [ -d "$HOME/.claude" ]; then say 'Claude Code hooks are installed. Once claude is on your PATH, run this installer again to add its MCP server.' fi } link_agents() { local attempt config="$HOME/.config/joebro" [ "${#agents[@]}" -gt 0 ] || return 0 if [ -f "$config/agents.json" ] || [ -f "$config/agent-report.json" ]; then say 'Kept your existing JoeBro connection.' return fi for ((attempt = 0; attempt < 20; attempt++)); do if curl --noproxy '*' -fsS --max-time 1 "$local_backend/api/health" >/dev/null 2>&1; then "$python" "$runner" link "$local_backend" return fi sleep 1 done fail "Agent plugins were installed, but the JoeBro backend did not start. Open JoeBro, then run this command again." } ask() { # curl | bash leaves stdin as the script, so read the answer from the terminal local reply='' { : /dev/null || return 1 printf ' %s?%s %s ' "$c_v" "$c_0" "$1" >/dev/tty IFS= read -r reply Settings > Accounts, 10 characters; leave blank to pick it in Xcode):') || team='' team=$(printf '%s' "$team" | tr -cd 'A-Z0-9') prefix="com.$(id -un | tr -cd 'a-zA-Z0-9' | tr 'A-Z' 'a-z').joebro" printf '// Written by the JoeBro installer. Gitignored.\nDEVELOPMENT_TEAM = %s\nBUNDLE_ID_PREFIX = %s\n' "$team" "$prefix" >"$config" say "Wrote $config (bundle ID prefix $prefix)." fi open "$dir/JoeBroMobile.xcodeproj" say 'In Xcode: plug in your iPhone, pick it at the top, and press Run.' [ -n "${team:-x}" ] || say 'Pick your team under Signing & Capabilities first.' say 'Then pair it: on the Mac, open JoeBro > Settings > Mobile, turn on "Let my phone connect", and scan the QR code.' } main() { local os python runner='' claude_bin='' lock_path local agents=() [ "$(uname -s)" = Darwin ] || fail 'This installer runs on macOS.' os=$(macos_version) [ "${os%%.*}" -ge 26 ] || fail 'JoeBro requires macOS 26 or later.' [ "$(id -u)" -ne 0 ] || fail 'Run this command from your normal account without sudo.' lock_path="${TMPDIR:-/tmp}/joebro-install-$(id -u).lock" mkdir "$lock_path" 2>/dev/null || fail 'Another JoeBro installer is already running.' lock=$lock_path trap 'exit 130' INT trap 'exit 143' TERM trap cleanup EXIT banner require_python temp=$(mktemp -d "${TMPDIR:-/tmp}/joebro-install.XXXXXXXX") find_agents if [ "${#agents[@]}" -gt 0 ]; then say 'Downloading the JoeBro agent plugins…' verified_download "https://codeload.github.com/joexk1/joebro-plugins/tar.gz/$plugins_commit" "$temp/joebro-plugins.tar.gz" "$plugins_sha" fi install_app install_plugins open "$destination" link_agents say 'JoeBro is ready. Restart any open coding agents to load their plugins.' offer_iphone cleanup trap - EXIT INT TERM } main "$@"