Fix ssr restore: skip iCloud prompt when available, bail early on missing sudo

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 <cursoragent@cursor.com>
This commit is contained in:
2026-05-11 20:51:18 +02:00
parent 5ed6279b51
commit 8489180d51
2 changed files with 23 additions and 4 deletions
+10 -3
View File
@@ -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:-<unknown>}"
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
+13 -1
View File
@@ -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)"