From 8489180d5145a72d6013aa7674c5697980f14a00 Mon Sep 17 00:00:00 2001 From: "Oliver Surke (Gitea)" Date: Mon, 11 May 2026 20:51:18 +0200 Subject: [PATCH] Fix ssr restore: skip iCloud prompt when available, bail early on missing sudo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lib/brew.sh: - Before running the Homebrew installer, check `sudo -n true`. If sudo is not available, print a clear actionable error message with the manual install command and exit instead of running NONINTERACTIVE=1 and crashing with "Need sudo access ... Administrator!" mid-way. bin/ssr-restore: - Drop the unconditional "Configure iCloud / cloud drive?" prompt. Instead check whether the cloud directory is already mounted; if it is, proceed silently (the common case on an already-configured Mac). The prompt only appears when the directory is missing, i.e. iCloud is not yet signed in or the drive is not mounted — with an appropriate message explaining what to do. Co-authored-by: Cursor --- bin/ssr-restore | 13 ++++++++++--- lib/brew.sh | 14 +++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) 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)"