#!/usr/bin/env bash # lib/mackup.sh — Mackup install + backup/restore. # Note: upstream mackup is in low-maintenance mode; we keep it because it # remains the simplest way to sync dotfiles for a wide range of apps. The # user can swap engines via ~/.mackup.cfg without changing this script. ssr::mackup::ensure_installed() { if command -v mackup >/dev/null 2>&1; then return 0 fi ssr::log "Installing mackup via brew" brew install mackup } # Writes ~/.mackup.cfg pointing the engine at the cloud directory. # Idempotent: rewrites only if content differs. ssr::mackup::configure() { local mackup_dir="$1" local cfg="$HOME/.mackup.cfg" local desired desired="$(printf '[storage]\nengine = file_system\npath = %s\ndirectory = mackup\n' "$mackup_dir")" if [[ -f "$cfg" ]] && [[ "$(cat "$cfg")" == "$desired" ]]; then return 0 fi if [[ -L "$cfg" || -f "$cfg" ]]; then cp -f "$cfg" "$cfg.bak.$(date +%s)" 2>/dev/null || true rm -f "$cfg" fi printf '%s\n' "$desired" > "$cfg" ssr::ok "Wrote $cfg" } ssr::mackup::backup() { ssr::log "mackup backup" mackup -f backup } ssr::mackup::restore() { ssr::log "mackup restore" mackup restore }