commit - aa80e86893dc9e53db688d6b1adc5f758b84b995
commit + 353cceddc78b4c1ddea71ccb31e13308f0c6830e
blob - /dev/null
blob + 90b325ee339ec82fe7fc12d24b1e914c37400539 (mode 755)
--- /dev/null
+++ bin/nextcloud-sync
+#!/bin/sh
+# Headless Nextcloud sync via nextcloudcmd (no GUI client needed).
+# New machine: clone dot_files, run this once, ~/org appears; then
+# ~/org/tech/bootstrap-git.sh does the repos. Re-run (or cron) to sync.
+#
+# Cron (every 10 min): */10 * * * * $HOME/Code/dot_files/bin/nextcloud-sync
+# For cron, rbw must be unlocked, or set NC_PASSWORD_FILE to a chmod-600
+# file containing an app password (Settings > Security > Devices & sessions).
+
+set -u
+
+NC_URL=https://nc.fugu.farm
+NC_USER=isaac
+PASS_CMD="rbw get nc.fugu.farm"
+
+# local-dir : remote-folder pairs
+SYNCS="
+$HOME/org org
+"
+
+# --- OS / install check ---
+if ! command -v nextcloudcmd >/dev/null 2>&1; then
+ case "$(uname -s)" in
+ OpenBSD) echo 'nextcloudcmd missing — run: doas pkg_add nextcloudclient' ;;
+ Linux) echo 'nextcloudcmd missing — Debian/Ubuntu: sudo apt install nextcloud-desktop-cmd' ;;
+ *) echo "unsupported OS: $(uname -s)" ;;
+ esac >&2
+ exit 1
+fi
+
+# --- password: file override, else rbw ---
+if [ -n "${NC_PASSWORD_FILE:-}" ] && [ -f "$NC_PASSWORD_FILE" ]; then
+ PASS=$(cat "$NC_PASSWORD_FILE")
+else
+ PASS=$($PASS_CMD) || { echo 'could not get password (rbw locked?)' >&2; exit 1; }
+fi
+
+# --- lock so cron runs don't overlap ---
+LOCK=${TMPDIR:-/tmp}/nextcloud-sync.lock
+if [ -e "$LOCK" ]; then
+ echo "already running (rm $LOCK if stale)" >&2; exit 0
+fi
+trap 'rm -f "$LOCK"' EXIT INT TERM
+: > "$LOCK"
+
+rc=0
+echo "$SYNCS" | while read -r local remote; do
+ [ -z "$local" ] && continue
+ mkdir -p "$local"
+ printf '== sync %s <-> %s/%s\n' "$local" "$NC_URL" "$remote"
+ nextcloudcmd --non-interactive --silent \
+ --user "$NC_USER" --password "$PASS" \
+ --path "/$remote" "$local" "$NC_URL" || { echo " !! sync failed: $local" >&2; rc=1; }
+done
+exit $rc