From cbe45d8d0e808c524d0b6112dd266f4814b6ff3a Mon Sep 17 00:00:00 2001 From: schmeeve Date: Sat, 20 Jun 2026 07:02:59 -0700 Subject: [PATCH] comfyui-sync --- by-machine/nimo.loc/comfyui-sync.service | 8 +++ by-machine/nimo.loc/comfyui-sync.timer | 9 ++++ comfyui-sync | 64 ++++++++++++++++++++++++ systemd/comfyui-sync.service | 8 +++ systemd/comfyui-sync.timer | 9 ++++ 5 files changed, 98 insertions(+) create mode 100644 by-machine/nimo.loc/comfyui-sync.service create mode 100644 by-machine/nimo.loc/comfyui-sync.timer create mode 100755 comfyui-sync create mode 100644 systemd/comfyui-sync.service create mode 100644 systemd/comfyui-sync.timer diff --git a/by-machine/nimo.loc/comfyui-sync.service b/by-machine/nimo.loc/comfyui-sync.service new file mode 100644 index 0000000..4446175 --- /dev/null +++ b/by-machine/nimo.loc/comfyui-sync.service @@ -0,0 +1,8 @@ +[Unit] +Description=Sync new ComfyUI outputs to Samba share, organize, and rename + +[Service] +Type=oneshot +ExecStart=%h/git/schmeeve-toolz/comfyui-sync +StandardOutput=append:%h/.local/state/comfyui-sync.log +StandardError=append:%h/.local/state/comfyui-sync.log diff --git a/by-machine/nimo.loc/comfyui-sync.timer b/by-machine/nimo.loc/comfyui-sync.timer new file mode 100644 index 0000000..a63c172 --- /dev/null +++ b/by-machine/nimo.loc/comfyui-sync.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run comfyui-sync every 30 minutes + +[Timer] +OnCalendar=*:0/30 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/comfyui-sync b/comfyui-sync new file mode 100755 index 0000000..bfad8d6 --- /dev/null +++ b/comfyui-sync @@ -0,0 +1,64 @@ +#!/bin/bash +set -euo pipefail + +SOURCE="$HOME/ComfyUI/output" +SHARE_DIR="/mini.nas/miniShare1/Pictures" +STATE_FILE="$HOME/.local/state/comfyui-sync.state" +NEATCLI="$(command -v neatcli || true)" +RENAME_SCRIPT="$HOME/git/schmeeve-toolz/rename-ai-snaps" + +mkdir -p "$(dirname "$STATE_FILE")" + +if [ ! -d "$SOURCE" ]; then + echo "[comfyui-sync] ERROR: Source $SOURCE does not exist" + exit 1 +fi + +if [ ! -d "$SHARE_DIR" ]; then + echo "[comfyui-sync] ERROR: Share dir $SHARE_DIR does not exist" + exit 1 +fi + +echo "[comfyui-sync] Starting at $(date)" + +current_files=$(ls "$SOURCE" | sort) + +if [ -f "$STATE_FILE" ]; then + new_files=$(comm -13 <(sort "$STATE_FILE") <(echo "$current_files")) +else + echo "[comfyui-sync] First run — all files considered new." + new_files="$current_files" +fi + +new_count=$(echo "$new_files" | grep -c '[^[:space:]]' || true) + +if [ "$new_count" -eq 0 ]; then + echo "[comfyui-sync] No new files to copy." + exit 0 +fi + +echo "[comfyui-sync] Copying $new_count new file(s)..." +while IFS= read -r f; do + [ -z "$f" ] && continue + cp "$SOURCE/$f" "$SHARE_DIR/" +done <<< "$new_files" + +echo "$current_files" > "$STATE_FILE" +echo "[comfyui-sync] State file updated." + +if [ -n "$NEATCLI" ]; then + echo "[comfyui-sync] Running neatcli organize --by-type -e $SHARE_DIR" + "$NEATCLI" organize --by-type -e "$SHARE_DIR" +else + echo "[comfyui-sync] WARNING: neatcli not found, skipping organize step" +fi + +IMAGES_DIR="$SHARE_DIR/Images" +if [ -d "$IMAGES_DIR" ] && [ -x "$RENAME_SCRIPT" ]; then + echo "[comfyui-sync] Running rename-ai-snaps on $IMAGES_DIR" + cd "$IMAGES_DIR" && "$RENAME_SCRIPT" . --no-interactive +elif [ ! -x "$RENAME_SCRIPT" ]; then + echo "[comfyui-sync] WARNING: rename-ai-snaps not found, skipping rename step" +fi + +echo "[comfyui-sync] Done at $(date)" diff --git a/systemd/comfyui-sync.service b/systemd/comfyui-sync.service new file mode 100644 index 0000000..4446175 --- /dev/null +++ b/systemd/comfyui-sync.service @@ -0,0 +1,8 @@ +[Unit] +Description=Sync new ComfyUI outputs to Samba share, organize, and rename + +[Service] +Type=oneshot +ExecStart=%h/git/schmeeve-toolz/comfyui-sync +StandardOutput=append:%h/.local/state/comfyui-sync.log +StandardError=append:%h/.local/state/comfyui-sync.log diff --git a/systemd/comfyui-sync.timer b/systemd/comfyui-sync.timer new file mode 100644 index 0000000..a63c172 --- /dev/null +++ b/systemd/comfyui-sync.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run comfyui-sync every 30 minutes + +[Timer] +OnCalendar=*:0/30 +Persistent=true + +[Install] +WantedBy=timers.target