#!/usr/bin/env bash # Bootstrap: installs Homebrew + gh, authenticates with GitHub (2FA), clones # the private personal-config repo, then hands off to setup_mac.sh. # Prerequisites: Install Xcode from the App Store before running this. set -euo pipefail if [[ "${EUID:-$(id -u)}" == "0" ]]; then echo "Do not run this setup with sudo. Run it as your macOS user so GitHub SSH keys are created under your account." exit 1 fi SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519}" REPO="$HOME/.personal-config" ensure_github_auth() { gh auth status >/dev/null 2>&1 || \ gh auth login --hostname github.com --web gh auth refresh --hostname github.com --scopes admin:public_key >/dev/null 2>&1 || true gh config set git_protocol ssh >/dev/null } ensure_github_ssh_config() { local ssh_config marker_begin marker_end ssh_config="$HOME/.ssh/config" marker_begin="# personal-config github.com begin" marker_end="# personal-config github.com end" mkdir -p "$HOME/.ssh" chmod 700 "$HOME/.ssh" if [[ -f "$ssh_config" ]] && grep -qF "$marker_begin" "$ssh_config"; then return 0 fi cat >> "$ssh_config" </dev/null 2>&1 || ssh-add "$SSH_KEY" >/dev/null 2>&1 || true if [[ -f "$SSH_KEY.pub" ]]; then key_material="$(awk '{print $2}' "$SSH_KEY.pub")" if ! gh ssh-key list 2>/dev/null | grep -qF "$key_material"; then gh ssh-key add "$SSH_KEY.pub" --title "$(scutil --get ComputerName 2>/dev/null || hostname)" || true fi fi } xcode-select -p >/dev/null 2>&1 || { echo "Install Xcode from the App Store first."; exit 1; } ORIGINAL_PATH="$PATH" command -v brew >/dev/null 2>&1 || \ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" eval "$(/opt/homebrew/bin/brew shellenv 2>/dev/null)" 2>/dev/null || \ eval "$(/usr/local/bin/brew shellenv 2>/dev/null)" export PATH="$ORIGINAL_PATH:$PATH" command -v gh >/dev/null 2>&1 || brew install gh ensure_github_auth ensure_github_ssh_key [ -d "$REPO/.git" ] \ && git -C "$REPO" pull --ff-only \ || gh repo clone shaunporwal/personal-config "$REPO" exec "$REPO/scripts/setup_mac.sh"