Files
System-Sync-Restore/bin/ssr-restore
T
Oliver Surke 5ed6279b51 Snapshot and restore macOS preference domains
Adds a round-trip mechanism for macOS system preferences that are not
covered by Homebrew or Mackup (Dock layout, Finder options, global
keyboard shortcuts, input sources, Spaces config, menu-bar clock,
NSGlobalDomain).

sync: `ssr sync` exports each configured domain with `defaults export`
and writes one plist per domain to <backup_dir>/macos-prefs/.  Export is
soft-fail per domain so one bad domain doesn't abort the sync. Gated by
SSR_SNAPSHOT_MACOS_PREFS=true (default on).

restore: `ssr restore` replays the snapshot with `defaults import` after
the declarative config/macos-defaults.sh runs, so the snapshot is the
last writer and wins for accepted domains.  Before importing, the restore
detects domains that both the snapshot and macos-defaults.sh touch and
prompts interactively:

  Domain `com.apple.dock`:
    Snapshot will OVERRIDE values set by macos-defaults.sh.
    [A]ccept snapshot / [r]eject (keep declarative)? [A/r]:

Non-TTY (launchd, CI) falls back to SSR_PREFS_CONFLICT_DEFAULT (default
"accept"). SSR_ASSUME_YES=true skips all prompts. After import, Dock,
Finder, SystemUIServer and cfprefsd are restarted once.

New config keys: SSR_SNAPSHOT_MACOS_PREFS, SSR_MACOS_PREF_DOMAINS,
SSR_MACOS_PREF_DOMAINS_EXTRA, SSR_PREFS_CONFLICT_DEFAULT, SSR_ASSUME_YES.

ssr-status surfaces the snapshotted-domain count.
README documents the snapshot flow, default domain table, conflict UX,
and the five new config keys.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 20:19:49 +02:00

66 lines
1.8 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"
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::confirm "Configure iCloud / cloud drive and proceed with restore?" 60 \
|| ssr::die "Aborted by user"
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"