feat: restore state/resume/report + single Spotlight index after mas installs
lib/brew.sh:
Set MAS_NO_AUTO_INDEX=1 before brew bundle install to suppress the
per-app mdimport call that mas otherwise runs after each App Store
installation. Run one mdimport /Applications batch pass afterwards.
lib/restore-state.sh (new):
Lightweight key=value state file (~/.local/state/ssr/restore-state).
ssr::rs::init / ssr::rs::run / ssr::rs::set/get / ssr::rs::error /
ssr::rs::report — tracks step outcomes and accumulated errors.
bin/ssr-restore:
--resume flag: skip steps already marked ok in state file.
Each step (brew_install, brew_restore, mackup_restore, macos_defaults,
prefs_import) wrapped in ssr::rs::run; errors accumulate without abort.
Formatted report printed at end of every run.
bin/ssr-status:
ssr status restore — full restore step report + error log
ssr status backup — Brewfile lines, unmanaged apps, prefs snapshot
ssr status — general view now shows one-line last-restore
summary and hint to run 'ssr status restore'
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+137
-35
@@ -1,5 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# ssr-status — print current state: config, cloud target, last sync, schedule.
|
||||
# ssr-status — print current state, or a detailed restore/backup report.
|
||||
#
|
||||
# Usage:
|
||||
# ssr status General status (cloud, last sync, schedule)
|
||||
# ssr status restore Detailed report of the last restore run
|
||||
# ssr status backup Summary of the last backup (sync) run
|
||||
|
||||
set -euo pipefail
|
||||
SSR_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
@@ -7,46 +12,143 @@ SSR_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
source "$SSR_ROOT/lib/common.sh"
|
||||
# shellcheck source=../lib/cloud.sh
|
||||
source "$SSR_ROOT/lib/cloud.sh"
|
||||
# shellcheck source=../lib/restore-state.sh
|
||||
source "$SSR_ROOT/lib/restore-state.sh"
|
||||
|
||||
ssr::load_config
|
||||
|
||||
cfg="${SSR_CONFIG:-$HOME/.config/ssr/ssr.conf}"
|
||||
provider="${SSR_CLOUD_PROVIDER:-icloud}"
|
||||
# ---------------------------------------------------------------------------
|
||||
# Sub-command dispatch
|
||||
# ---------------------------------------------------------------------------
|
||||
case "${1:-}" in
|
||||
restore)
|
||||
ssr::rs::report
|
||||
exit 0
|
||||
;;
|
||||
backup|sync)
|
||||
_status_backup
|
||||
exit 0
|
||||
;;
|
||||
""|general)
|
||||
# fall through to general status below
|
||||
;;
|
||||
*)
|
||||
printf 'Usage: ssr status [restore|backup]\n'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "ssr status"
|
||||
echo " repo: $SSR_ROOT"
|
||||
echo " config: $cfg $([[ -f "$cfg" ]] && echo '(present)' || echo '(missing)')"
|
||||
echo " provider: $provider"
|
||||
# ---------------------------------------------------------------------------
|
||||
# General status
|
||||
# ---------------------------------------------------------------------------
|
||||
_status_general() {
|
||||
local cfg provider cloud_dir backup_dir state_dir label service_target
|
||||
|
||||
if cloud_dir="$(ssr::cloud::resolve_dir 2>/dev/null)"; then
|
||||
echo " cloud dir: $cloud_dir $([[ -d "$cloud_dir" ]] && echo '(ok)' || echo '(unreachable)')"
|
||||
echo " backup dir: $(ssr::cloud::backup_dir 2>/dev/null || echo 'n/a')"
|
||||
fi
|
||||
cfg="${SSR_CONFIG:-$HOME/.config/ssr/ssr.conf}"
|
||||
provider="${SSR_CLOUD_PROVIDER:-icloud}"
|
||||
state_dir="${SSR_STATE_DIR:-$HOME/.local/state/ssr}"
|
||||
|
||||
state_dir="${SSR_STATE_DIR:-$HOME/.local/state/ssr}"
|
||||
if [[ -f "$state_dir/last-sync" ]]; then
|
||||
echo " last sync: $(cat "$state_dir/last-sync")"
|
||||
else
|
||||
echo " last sync: never"
|
||||
fi
|
||||
printf 'ssr status\n'
|
||||
printf ' repo: %s\n' "$SSR_ROOT"
|
||||
printf ' config: %s %s\n' "$cfg" "$([[ -f "$cfg" ]] && echo '(present)' || echo '(missing)')"
|
||||
printf ' provider: %s\n' "$provider"
|
||||
|
||||
# Surface unmanaged-app count and pref-snapshot summary from the last sync.
|
||||
if backup_dir="$(ssr::cloud::backup_dir 2>/dev/null)"; then
|
||||
if [[ -f "$backup_dir/unmanaged-apps.md" ]]; then
|
||||
n="$(grep -cE '^\| \[' "$backup_dir/unmanaged-apps.md" 2>/dev/null || echo 0)"
|
||||
echo " unmanaged: $n app(s) (see $backup_dir/unmanaged-apps.md)"
|
||||
if cloud_dir="$(ssr::cloud::resolve_dir 2>/dev/null)"; then
|
||||
printf ' cloud dir: %s %s\n' "$cloud_dir" \
|
||||
"$([[ -d "$cloud_dir" ]] && echo '(ok)' || echo '(unreachable)')"
|
||||
printf ' backup dir: %s\n' "$(ssr::cloud::backup_dir 2>/dev/null || echo 'n/a')"
|
||||
fi
|
||||
if [[ -d "$backup_dir/macos-prefs" ]]; then
|
||||
n="$(find "$backup_dir/macos-prefs" -name '*.plist' 2>/dev/null | wc -l | tr -d ' ')"
|
||||
echo " prefs snap: $n domain(s) (see $backup_dir/macos-prefs/)"
|
||||
fi
|
||||
fi
|
||||
|
||||
label="${SSR_LAUNCHD_LABEL:-de.surke.ssr.sync}"
|
||||
service_target="gui/$(id -u)/${label}"
|
||||
if launchctl print "$service_target" >/dev/null 2>&1 \
|
||||
|| launchctl list "$label" >/dev/null 2>&1; then
|
||||
echo " schedule: active ($label)"
|
||||
else
|
||||
echo " schedule: inactive"
|
||||
fi
|
||||
if [[ -f "$state_dir/last-sync" ]]; then
|
||||
printf ' last sync: %s\n' "$(cat "$state_dir/last-sync")"
|
||||
else
|
||||
printf ' last sync: never\n'
|
||||
fi
|
||||
|
||||
# Unmanaged apps + pref snapshot from last sync.
|
||||
if backup_dir="$(ssr::cloud::backup_dir 2>/dev/null)"; then
|
||||
if [[ -f "$backup_dir/unmanaged-apps.md" ]]; then
|
||||
local n
|
||||
n="$(grep -cE '^\| \[' "$backup_dir/unmanaged-apps.md" 2>/dev/null || echo 0)"
|
||||
printf ' unmanaged: %s app(s) → %s\n' "$n" "$backup_dir/unmanaged-apps.md"
|
||||
fi
|
||||
if [[ -d "$backup_dir/macos-prefs" ]]; then
|
||||
local n
|
||||
n="$(find "$backup_dir/macos-prefs" -name '*.plist' 2>/dev/null | wc -l | tr -d ' ')"
|
||||
printf ' prefs snap: %s domain(s) → %s/macos-prefs/\n' "$n" "$backup_dir"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Last restore summary (one line).
|
||||
local rs_state; rs_state="$(_ssr_rs_state_file)"
|
||||
if [[ -f "$rs_state" ]]; then
|
||||
local rs_started rs_finished rs_warns
|
||||
rs_started="$(grep '^started=' "$rs_state" | cut -d= -f2-)"
|
||||
rs_finished="$(grep '^finished=' "$rs_state" | cut -d= -f2-)"
|
||||
rs_warns="$(grep -cE '^step_[^=]+=(warn|fail)' "$rs_state" 2>/dev/null || echo 0)"
|
||||
printf ' last restore: %s' "${rs_started:-(unknown)}"
|
||||
[[ -n "$rs_finished" ]] && printf ' → %s' "$rs_finished"
|
||||
[[ "$rs_warns" -gt 0 ]] && printf ' (%s warning(s))' "$rs_warns" \
|
||||
|| printf ' (ok)'
|
||||
printf '\n'
|
||||
printf ' (run "ssr status restore" for full report)\n'
|
||||
fi
|
||||
|
||||
# Schedule.
|
||||
label="${SSR_LAUNCHD_LABEL:-de.surke.ssr.sync}"
|
||||
service_target="gui/$(id -u)/${label}"
|
||||
if launchctl print "$service_target" >/dev/null 2>&1 \
|
||||
|| launchctl list "$label" >/dev/null 2>&1; then
|
||||
printf ' schedule: active (%s)\n' "$label"
|
||||
else
|
||||
printf ' schedule: inactive\n'
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Backup / sync report
|
||||
# ---------------------------------------------------------------------------
|
||||
_status_backup() {
|
||||
local state_dir backup_dir
|
||||
state_dir="${SSR_STATE_DIR:-$HOME/.local/state/ssr}"
|
||||
|
||||
printf '\n%s\n' "── Backup (Sync) Report ────────────────────────"
|
||||
|
||||
if [[ -f "$state_dir/last-sync" ]]; then
|
||||
printf ' last sync : %s\n' "$(cat "$state_dir/last-sync")"
|
||||
else
|
||||
printf ' last sync : never\n'
|
||||
fi
|
||||
|
||||
if backup_dir="$(ssr::cloud::backup_dir 2>/dev/null)" && [[ -d "$backup_dir" ]]; then
|
||||
printf ' backup dir: %s\n' "$backup_dir"
|
||||
|
||||
if [[ -f "$backup_dir/Brewfile" ]]; then
|
||||
local lines
|
||||
lines="$(wc -l < "$backup_dir/Brewfile" | tr -d ' ')"
|
||||
local mtime
|
||||
mtime="$(date -r "$backup_dir/Brewfile" '+%Y-%m-%dT%H:%M:%S%z' 2>/dev/null || echo '?')"
|
||||
printf ' Brewfile : %s lines, modified %s\n' "$lines" "$mtime"
|
||||
else
|
||||
printf ' Brewfile : not found\n'
|
||||
fi
|
||||
|
||||
if [[ -f "$backup_dir/unmanaged-apps.md" ]]; then
|
||||
local n
|
||||
n="$(grep -cE '^\| \[' "$backup_dir/unmanaged-apps.md" 2>/dev/null || echo 0)"
|
||||
printf ' unmanaged : %s app(s) → %s\n' "$n" "$backup_dir/unmanaged-apps.md"
|
||||
fi
|
||||
|
||||
if [[ -d "$backup_dir/macos-prefs" ]]; then
|
||||
local n
|
||||
n="$(find "$backup_dir/macos-prefs" -name '*.plist' 2>/dev/null | wc -l | tr -d ' ')"
|
||||
printf ' prefs snap: %s domain(s)\n' "$n"
|
||||
fi
|
||||
else
|
||||
printf ' (backup directory not accessible)\n'
|
||||
fi
|
||||
|
||||
printf '%s\n\n' "────────────────────────────────────────────────"
|
||||
}
|
||||
|
||||
_status_general
|
||||
|
||||
Reference in New Issue
Block a user