Files
gitea-migration/setup/macbook.sh

123 lines
4.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# setup/macbook.sh — Install prerequisites on MacBook (runs locally)
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=../lib/common.sh
# shellcheck disable=SC1091
source "${SCRIPT_DIR}/../lib/common.sh"
log_info "=== MacBook Setup ==="
# --------------------------------------------------------------------------
# OS check — this script uses Homebrew, launchctl, Xcode tools (macOS only)
# --------------------------------------------------------------------------
require_local_os "Darwin" "macbook.sh must run on macOS — detected a non-macOS system"
# --------------------------------------------------------------------------
# Manifest — track what we install for rollback/cleanup
# --------------------------------------------------------------------------
manifest_init "macbook"
# --------------------------------------------------------------------------
# Homebrew
# --------------------------------------------------------------------------
if ! command -v brew &>/dev/null; then
log_error "Homebrew is not installed."
log_error "Install it manually: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
log_error "Then re-run this script."
exit 1
fi
log_success "Homebrew found"
# --------------------------------------------------------------------------
# Brew packages
# --------------------------------------------------------------------------
BREW_PACKAGES=(jq curl gettext shellcheck gh bitwarden-cli)
for pkg in "${BREW_PACKAGES[@]}"; do
if brew list "$pkg" &>/dev/null; then
log_success "$pkg already installed"
else
log_info "Installing $pkg..."
brew install "$pkg"
manifest_record "macbook" "brew_pkg" "$pkg"
log_success "$pkg installed"
fi
done
# --------------------------------------------------------------------------
# Minimum version checks for local tools
# --------------------------------------------------------------------------
log_info "Checking minimum versions..."
check_min_version "jq" "jq --version" "1.6"
check_min_version "curl" "curl --version" "7.70"
check_min_version "git" "git --version" "2.30"
check_min_version "shellcheck" "shellcheck --version" "0.8"
check_min_version "gh" "gh --version" "2.0"
# --------------------------------------------------------------------------
# Verify built-in tools
# --------------------------------------------------------------------------
BUILTINS=(ssh git scp)
for tool in "${BUILTINS[@]}"; do
if command -v "$tool" &>/dev/null; then
log_success "$tool found"
else
log_error "$tool not found — this should be built into macOS"
exit 1
fi
done
# Verify envsubst specifically (comes from gettext)
if command -v envsubst &>/dev/null; then
log_success "envsubst found (from gettext)"
else
log_error "envsubst not found. Try: brew link --force gettext"
exit 1
fi
# --------------------------------------------------------------------------
# Xcode Command Line Tools
# --------------------------------------------------------------------------
if xcode-select -p &>/dev/null; then
log_success "Xcode Command Line Tools found"
else
log_info "Installing Xcode Command Line Tools..."
xcode-select --install
manifest_record "macbook" "xcode_cli" "xcode-select"
log_warn "Xcode CLI Tools installation started. Wait for it to finish, then re-run this script."
exit 0
fi
# --------------------------------------------------------------------------
# Network access check (if .env exists)
# --------------------------------------------------------------------------
if [[ -f "${SCRIPT_DIR}/../.env" ]]; then
load_env
if [[ -n "${UNRAID_IP:-}" ]]; then
if ssh_check UNRAID; then
log_success "SSH to Unraid ($UNRAID_IP) OK"
else
log_warn "Cannot SSH to Unraid ($UNRAID_IP) — check SSH config"
fi
fi
if [[ -n "${FEDORA_IP:-}" ]]; then
if ssh_check FEDORA; then
log_success "SSH to Fedora ($FEDORA_IP) OK"
else
log_warn "Cannot SSH to Fedora ($FEDORA_IP) — check SSH config"
fi
fi
else
log_info "No .env file — skipping network checks. Run setup/configure_env.sh first."
fi
# --------------------------------------------------------------------------
# Summary
# --------------------------------------------------------------------------
log_success "All MacBook prerequisites satisfied"