Initial ssr repository

Convert the legacy system_sync.sh and system_restore.sh into a modular
shareable repository:

- bin/ssr CLI dispatcher with install/sync/restore/schedule/config/status
- lib/ split: common, cloud, brew, mackup, macos
- Cloud provider abstraction (icloud, dropbox, googledrive, onedrive, custom)
- launchd template for scheduled daily sync (renderable via sed)
- ssr.conf.example with whitelisted KEY=VALUE config loader
- macos-defaults.sh extracted from inline block, overridable
- install.sh bootstrap symlinks CLI into ~/.local/bin
- README with usage, config table, migration map, security notes
- Original scripts archived under legacy/ for reference

Fixes vs originals: set -euo pipefail, quoted vars, find -print0,
spctl --global-disable (was --master-disable), MACOS=".macos" bug,
zero-width char before ln, Apple Silicon brew shellenv, config injection
hardening.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-11 15:05:17 +02:00
commit 539a8fc28f
23 changed files with 1171 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# lib/cloud.sh — cloud storage provider abstraction.
# Resolves SSR_CLOUD_DIR based on SSR_CLOUD_PROVIDER from config.
ssr::cloud::resolve_dir() {
local provider="${SSR_CLOUD_PROVIDER:-icloud}" custom="${SSR_CLOUD_PATH:-}"
case "$provider" in
icloud)
printf '%s\n' "$HOME/Library/Mobile Documents/com~apple~CloudDocs"
;;
dropbox)
if [[ -d "$HOME/Library/CloudStorage" ]]; then
find "$HOME/Library/CloudStorage" -maxdepth 1 -type d -name 'Dropbox*' -print -quit 2>/dev/null \
|| printf '%s\n' "$HOME/Dropbox"
else
printf '%s\n' "$HOME/Dropbox"
fi
;;
googledrive)
find "$HOME/Library/CloudStorage" -maxdepth 1 -type d -name 'GoogleDrive-*' -print -quit 2>/dev/null \
|| ssr::die "Google Drive folder not found under ~/Library/CloudStorage"
;;
onedrive)
find "$HOME/Library/CloudStorage" -maxdepth 1 -type d -name 'OneDrive-*' -print -quit 2>/dev/null \
|| ssr::die "OneDrive folder not found under ~/Library/CloudStorage"
;;
custom)
[[ -n "$custom" ]] || ssr::die "SSR_CLOUD_PROVIDER=custom requires SSR_CLOUD_PATH"
printf '%s\n' "$custom"
;;
*)
ssr::die "Unknown SSR_CLOUD_PROVIDER: $provider (use: icloud|dropbox|googledrive|onedrive|custom)"
;;
esac
}
# Returns the per-host backup directory under the cloud root.
ssr::cloud::backup_dir() {
local cloud host uuid
cloud="$(ssr::cloud::resolve_dir)"
host="$(hostname -s)"
uuid="$(/usr/sbin/system_profiler SPHardwareDataType 2>/dev/null \
| awk '/Hardware UUID/ { print $3 }')"
[[ -n "$uuid" ]] || uuid="no-uuid"
local subdir="${SSR_BACKUP_SUBDIR:-BACKUP}"
printf '%s/%s/%s - %s\n' "$cloud" "$subdir" "$host" "$uuid"
}
# Mackup data lives at the cloud root in a fixed folder. Mackup itself
# resolves its engine via ~/.mackup.cfg which the install routine seeds.
ssr::cloud::mackup_dir() {
local cloud
cloud="$(ssr::cloud::resolve_dir)"
printf '%s/%s\n' "$cloud" "${SSR_MACKUP_SUBDIR:-Mackup}"
}
ssr::cloud::ensure_available() {
local cloud
cloud="$(ssr::cloud::resolve_dir)"
[[ -d "$cloud" ]] || ssr::die "Cloud directory not available: $cloud"
ssr::ok "Cloud provider: ${SSR_CLOUD_PROVIDER:-icloud}$cloud"
}