diff --git a/bin/ssr-restore b/bin/ssr-restore index a6cd74a..233619d 100755 --- a/bin/ssr-restore +++ b/bin/ssr-restore @@ -31,6 +31,16 @@ EOF [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]] && { usage; exit 0; } ssr::log "ssr restore starting" + +# Resolve cloud dir early so we can check availability before prompting. +_cloud_dir="$(ssr::cloud::resolve_dir 2>/dev/null)" || true +if [[ -z "$_cloud_dir" || ! -d "$_cloud_dir" ]]; then + ssr::warn "Cloud directory not yet accessible: ${_cloud_dir:-}" + ssr::warn "Sign in to ${SSR_CLOUD_PROVIDER:-iCloud} and ensure the drive is mounted, then press Enter." + ssr::confirm "Cloud drive ready — proceed with restore?" 120 \ + || ssr::die "Aborted by user" +fi + ssr::cloud::ensure_available backup_dir="$(ssr::cloud::backup_dir)" mackup_dir="$(ssr::cloud::mackup_dir)" @@ -39,9 +49,6 @@ brewfile="${1:-$backup_dir/Brewfile}" [[ -f "$brewfile" ]] || ssr::die "Brewfile not found: $brewfile" ssr::log "Using Brewfile: $brewfile" -ssr::confirm "Configure iCloud / cloud drive and proceed with restore?" 60 \ - || ssr::die "Aborted by user" - ssr::macos::disable_gatekeeper ssr::macos::install_rosetta diff --git a/lib/brew.sh b/lib/brew.sh index e627219..ea4dcd2 100644 --- a/lib/brew.sh +++ b/lib/brew.sh @@ -5,7 +5,19 @@ ssr::brew::ensure_installed() { if command -v brew >/dev/null 2>&1; then return 0 fi - ssr::log "Homebrew not found — installing (non-interactive)" + + # Homebrew's install script requires sudo on macOS to write to /opt/homebrew + # (Apple Silicon) or /usr/local (Intel). Check before running it so we can + # give a clear error instead of a cryptic failure. + if ! sudo -n true 2>/dev/null; then + ssr::warn "Homebrew is not installed and sudo access is required to install it." + ssr::warn "Please run the following as an admin user and re-run ssr restore:" + ssr::warn " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" + ssr::die "Cannot install Homebrew without sudo access." + fi + + ssr::log "Homebrew not found — installing" + # NONINTERACTIVE=1 skips the confirmation prompt; sudo is available (checked above). NONINTERACTIVE=1 /bin/bash -c \ "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"