8489180d51
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>
73 lines
2.1 KiB
Bash
Executable File
73 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ssr-restore — restore brew packages, mackup data, macOS defaults.
|
|
|
|
set -euo pipefail
|
|
SSR_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
# shellcheck source=../lib/common.sh
|
|
source "$SSR_ROOT/lib/common.sh"
|
|
# shellcheck source=../lib/cloud.sh
|
|
source "$SSR_ROOT/lib/cloud.sh"
|
|
# shellcheck source=../lib/brew.sh
|
|
source "$SSR_ROOT/lib/brew.sh"
|
|
# shellcheck source=../lib/mackup.sh
|
|
source "$SSR_ROOT/lib/mackup.sh"
|
|
# shellcheck source=../lib/macos.sh
|
|
source "$SSR_ROOT/lib/macos.sh"
|
|
# shellcheck source=../lib/macos-prefs.sh
|
|
source "$SSR_ROOT/lib/macos-prefs.sh"
|
|
|
|
ssr::require_macos
|
|
ssr::load_config
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: ssr restore [BREWFILE]
|
|
|
|
If BREWFILE is omitted, the latest cloud backup is used:
|
|
<cloud>/BACKUP/<host> - <uuid>/Brewfile
|
|
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)"
|
|
|
|
brewfile="${1:-$backup_dir/Brewfile}"
|
|
[[ -f "$brewfile" ]] || ssr::die "Brewfile not found: $brewfile"
|
|
ssr::log "Using Brewfile: $brewfile"
|
|
|
|
ssr::macos::disable_gatekeeper
|
|
ssr::macos::install_rosetta
|
|
|
|
ssr::brew::ensure_installed
|
|
ssr::brew::update
|
|
ssr::brew::restore "$brewfile"
|
|
|
|
ssr::mackup::ensure_installed
|
|
ssr::mackup::configure "$mackup_dir"
|
|
ssr::mackup::restore
|
|
|
|
ssr::macos::open_installed_casks
|
|
ssr::macos::apply_defaults
|
|
|
|
# Import the macOS pref snapshot AFTER the declarative defaults so the
|
|
# snapshot is the last writer (wins for accepted domains).
|
|
if [[ "${SSR_SNAPSHOT_MACOS_PREFS:-true}" == "true" ]]; then
|
|
ssr::macos::prefs_import "$backup_dir"
|
|
fi
|
|
|
|
ssr::ok "ssr restore completed"
|