539a8fc28f
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>
67 lines
2.0 KiB
Bash
Executable File
67 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ssr-schedule — manage the launchd scheduled sync job.
|
|
|
|
set -euo pipefail
|
|
SSR_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
# shellcheck source=../lib/common.sh
|
|
source "$SSR_ROOT/lib/common.sh"
|
|
|
|
ssr::require_macos
|
|
ssr::load_config
|
|
|
|
LABEL="${SSR_LAUNCHD_LABEL:-de.surke.ssr.sync}"
|
|
PLIST_SRC="$SSR_ROOT/launchd/${LABEL}.plist"
|
|
PLIST_DST="$HOME/Library/LaunchAgents/${LABEL}.plist"
|
|
LOG_DIR="${SSR_LOG_DIR:-$HOME/.local/state/ssr/logs}"
|
|
INTERVAL_HOUR="${SSR_SCHEDULE_HOUR:-9}"
|
|
INTERVAL_MIN="${SSR_SCHEDULE_MINUTE:-0}"
|
|
SSR_BIN="$SSR_ROOT/bin/ssr"
|
|
|
|
render_plist() {
|
|
ssr::ensure_dir "$LOG_DIR"
|
|
ssr::ensure_dir "$(dirname "$PLIST_DST")"
|
|
# Substitute placeholders from the template into the user's LaunchAgents dir.
|
|
sed \
|
|
-e "s|@@LABEL@@|${LABEL}|g" \
|
|
-e "s|@@SSR_BIN@@|${SSR_BIN}|g" \
|
|
-e "s|@@LOG_DIR@@|${LOG_DIR}|g" \
|
|
-e "s|@@HOUR@@|${INTERVAL_HOUR}|g" \
|
|
-e "s|@@MINUTE@@|${INTERVAL_MIN}|g" \
|
|
"$PLIST_SRC" > "$PLIST_DST"
|
|
chmod 600 "$PLIST_DST"
|
|
}
|
|
|
|
cmd_on() {
|
|
[[ -f "$PLIST_SRC" ]] || ssr::die "launchd template missing: $PLIST_SRC"
|
|
render_plist
|
|
# Reload to pick up changes if it was already loaded.
|
|
launchctl unload "$PLIST_DST" 2>/dev/null || true
|
|
launchctl load -w "$PLIST_DST"
|
|
ssr::ok "Scheduled sync enabled (${INTERVAL_HOUR}:$(printf '%02d' "$INTERVAL_MIN") daily) → $PLIST_DST"
|
|
}
|
|
|
|
cmd_off() {
|
|
if [[ -f "$PLIST_DST" ]]; then
|
|
launchctl unload "$PLIST_DST" 2>/dev/null || true
|
|
rm -f "$PLIST_DST"
|
|
ssr::ok "Scheduled sync disabled"
|
|
else
|
|
ssr::log "Scheduled sync was not installed"
|
|
fi
|
|
}
|
|
|
|
cmd_status() {
|
|
if [[ -f "$PLIST_DST" ]] && launchctl list | grep -q "$LABEL"; then
|
|
ssr::ok "Scheduled sync: active (label=$LABEL)"
|
|
else
|
|
ssr::log "Scheduled sync: inactive"
|
|
fi
|
|
}
|
|
|
|
case "${1:-status}" in
|
|
on|enable) cmd_on ;;
|
|
off|disable) cmd_off ;;
|
|
status) cmd_status ;;
|
|
*) ssr::die "Usage: ssr schedule [on|off|status]" ;;
|
|
esac
|