Compare commits
2 Commits
ff30f63404
...
cdde5e3d6a
| Author | SHA1 | Date | |
|---|---|---|---|
| cdde5e3d6a | |||
| bceb2bb95b |
@@ -3,6 +3,8 @@ Description=Sync new ComfyUI outputs to Samba share, organize, and rename
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
User=schmeeve
|
||||||
|
Environment=HOME=/home/schmeeve
|
||||||
ExecStart=/home/schmeeve/git/schmeeve-toolz/comfyui-sync
|
ExecStart=/home/schmeeve/git/schmeeve-toolz/comfyui-sync
|
||||||
StandardOutput=append:/home/schmeeve/.local/state/comfyui-sync.log
|
StandardOutput=append:/home/schmeeve/.local/state/comfyui-sync.log
|
||||||
StandardError=append:/home/schmeeve/.local/state/comfyui-sync.log
|
StandardError=append:/home/schmeeve/.local/state/comfyui-sync.log
|
||||||
|
|||||||
96
deploy-comfyui-sync
Executable file
96
deploy-comfyui-sync
Executable file
@@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# deploy-comfyui-sync — Push sync-comfyui-snaps and dependencies to nimo.loc
|
||||||
|
# and configure cron, credentials, and sudoers.
|
||||||
|
#
|
||||||
|
# Run this from your Mac (from the schmeeve-toolz repo root):
|
||||||
|
# ./deploy-comfyui-sync
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
NIMO="schmeeve@nimo.loc"
|
||||||
|
REMOTE_BIN="/home/schmeeve/.local/bin"
|
||||||
|
REMOTE_LOG="/home/schmeeve/.local/log"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
|
|
||||||
|
SCRIPTS=(
|
||||||
|
sync-comfyui-snaps
|
||||||
|
rename-ai-snaps
|
||||||
|
organize-images
|
||||||
|
extract-ai-meta
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "[deploy] Deploying to ${NIMO}"
|
||||||
|
|
||||||
|
# 1. Ensure remote dirs exist
|
||||||
|
ssh "${NIMO}" "mkdir -p ${REMOTE_BIN} ${REMOTE_LOG} ~/.smb"
|
||||||
|
|
||||||
|
# 2. Copy scripts
|
||||||
|
echo "[deploy] Copying scripts → ${REMOTE_BIN}/"
|
||||||
|
for s in "${SCRIPTS[@]}"; do
|
||||||
|
src="${SCRIPT_DIR}/${s}"
|
||||||
|
if [ ! -f "${src}" ]; then
|
||||||
|
echo "[deploy] WARNING: ${src} not found, skipping"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
scp -q "${src}" "${NIMO}:${REMOTE_BIN}/${s}"
|
||||||
|
echo " ✓ ${s}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3. Make scripts executable
|
||||||
|
ssh "${NIMO}" "chmod +x $(printf "${REMOTE_BIN}/%s " "${SCRIPTS[@]}")"
|
||||||
|
|
||||||
|
# 4. Install Python dependency (Pillow) for rename-ai-snaps and extract-ai-meta
|
||||||
|
echo "[deploy] Installing Pillow (Python)"
|
||||||
|
ssh "${NIMO}" "pip3 install --user --quiet Pillow && echo ' ✓ Pillow installed'"
|
||||||
|
|
||||||
|
# 5. Create NAS credentials file template if not already present
|
||||||
|
echo "[deploy] Checking NAS credentials file"
|
||||||
|
ssh "${NIMO}" '
|
||||||
|
if [ -f ~/.smb/mini.nas ]; then
|
||||||
|
echo " credentials file already exists, skipping"
|
||||||
|
else
|
||||||
|
printf "username=schmeeve\npassword=CHANGEME\n" > ~/.smb/mini.nas
|
||||||
|
chmod 600 ~/.smb/mini.nas
|
||||||
|
echo " created ~/.smb/mini.nas — EDIT IT to set your NAS password"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
|
||||||
|
# 6. Add sudoers entry for passwordless cifs mount
|
||||||
|
echo "[deploy] Configuring sudoers for cifs mount"
|
||||||
|
ssh -t "${NIMO}" '
|
||||||
|
SUDOERS_FILE="/etc/sudoers.d/schmeeve-cifs"
|
||||||
|
RULE="schmeeve ALL=(root) NOPASSWD: /usr/bin/mount -t cifs *"
|
||||||
|
if sudo test -f "${SUDOERS_FILE}" 2>/dev/null; then
|
||||||
|
echo " sudoers entry already exists"
|
||||||
|
else
|
||||||
|
echo "${RULE}" | sudo tee "${SUDOERS_FILE}" > /dev/null
|
||||||
|
sudo chmod 440 "${SUDOERS_FILE}"
|
||||||
|
echo " sudoers entry added: ${SUDOERS_FILE}"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
|
||||||
|
# 7. Create mount point
|
||||||
|
ssh "${NIMO}" "mkdir -p /home/schmeeve/mnt/miniShare1"
|
||||||
|
|
||||||
|
# 8. Add cron job (every 2 hours) if not already present
|
||||||
|
echo "[deploy] Checking crontab"
|
||||||
|
ssh "${NIMO}" '
|
||||||
|
CRON_LINE="0 */2 * * * /home/schmeeve/.local/bin/sync-comfyui-snaps >> /home/schmeeve/.local/log/sync-comfyui-snaps.log 2>&1"
|
||||||
|
if crontab -l 2>/dev/null | grep -qF "sync-comfyui-snaps"; then
|
||||||
|
echo " cron entry already exists"
|
||||||
|
else
|
||||||
|
( crontab -l 2>/dev/null; echo "${CRON_LINE}" ) | crontab -
|
||||||
|
echo " cron entry added (every 2 hours)"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "[deploy] Done."
|
||||||
|
echo
|
||||||
|
echo " Next step: if ~/.smb/mini.nas still has CHANGEME, SSH in and set your NAS password:"
|
||||||
|
echo " ssh ${NIMO}"
|
||||||
|
echo " nano ~/.smb/mini.nas"
|
||||||
|
echo
|
||||||
|
echo " Test the sync manually:"
|
||||||
|
echo " ssh ${NIMO} ${REMOTE_BIN}/sync-comfyui-snaps"
|
||||||
86
sync-comfyui-snaps
Executable file
86
sync-comfyui-snaps
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# sync-comfyui-snaps — Pull new images from nimo.loc ComfyUI output, sync to NAS,
|
||||||
|
# then rename AI snaps and organize.
|
||||||
|
#
|
||||||
|
# Crontab (every 2 hours):
|
||||||
|
# 0 */2 * * * /home/schmeeve/.local/bin/sync-comfyui-snaps >> /home/schmeeve/.local/log/sync-comfyui-snaps.log 2>&1
|
||||||
|
#
|
||||||
|
# Requires: rsync, SSH key auth to nimo.loc (or runs directly on nimo.loc),
|
||||||
|
# rename-ai-snaps and organize-images in ~/.local/bin/
|
||||||
|
#
|
||||||
|
# NAS credentials file at ~/.smb/mini.nas (chmod 600):
|
||||||
|
# username=schmeeve
|
||||||
|
# password=yourpass
|
||||||
|
|
||||||
|
# Source is local (this script runs on nimo.loc).
|
||||||
|
# Set NIMO_HOST to a remote hostname only if running this from another machine.
|
||||||
|
NIMO_HOST=""
|
||||||
|
NIMO_USER="schmeeve"
|
||||||
|
NIMO_SRC="/home/schmeeve/ComfyUI/output"
|
||||||
|
|
||||||
|
SHARE="//mini.nas/miniShare1"
|
||||||
|
NAS_SUBPATH="Pictures"
|
||||||
|
MOUNTPOINT="${HOME}/mnt/miniShare1"
|
||||||
|
CREDENTIALS="${HOME}/.smb/mini.nas"
|
||||||
|
|
||||||
|
RENAME_SCRIPT="${HOME}/.local/bin/rename-ai-snaps"
|
||||||
|
ORGANIZE_SCRIPT="${HOME}/.local/bin/organize-images"
|
||||||
|
|
||||||
|
START="$(date +%s)"
|
||||||
|
echo "[sync-comfyui-snaps] Starting at $(date)"
|
||||||
|
|
||||||
|
# 1. Mount NAS if not already mounted
|
||||||
|
if mount | grep -q "${MOUNTPOINT}"; then
|
||||||
|
echo "[sync-comfyui-snaps] Already mounted at ${MOUNTPOINT}"
|
||||||
|
else
|
||||||
|
echo "[sync-comfyui-snaps] Mounting ${SHARE} → ${MOUNTPOINT}"
|
||||||
|
mkdir -p "${MOUNTPOINT}"
|
||||||
|
OPTS="username=schmeeve,uid=$(id -u),gid=$(id -g),forceuid,forcegid,nounix,serverino"
|
||||||
|
if [ -f "${CREDENTIALS}" ]; then
|
||||||
|
OPTS="${OPTS},credentials=${CREDENTIALS}"
|
||||||
|
fi
|
||||||
|
sudo mount -t cifs "${SHARE}" "${MOUNTPOINT}" -o "${OPTS}"
|
||||||
|
if ! mount | grep -q "${MOUNTPOINT}"; then
|
||||||
|
echo "[sync-comfyui-snaps] ERROR: Failed to mount ${SHARE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[sync-comfyui-snaps] Mounted at ${MOUNTPOINT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEST="${MOUNTPOINT}/${NAS_SUBPATH}"
|
||||||
|
mkdir -p "${DEST}"
|
||||||
|
|
||||||
|
# 2. Rsync from nimo.loc ComfyUI output → NAS Pictures
|
||||||
|
# If running directly on nimo.loc, set NIMO_HOST="" and it will use a local path instead.
|
||||||
|
if [ -z "${NIMO_HOST}" ] || [ "${NIMO_HOST}" = "localhost" ]; then
|
||||||
|
SRC="${NIMO_SRC}/"
|
||||||
|
else
|
||||||
|
SRC="${NIMO_USER}@${NIMO_HOST}:${NIMO_SRC}/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[sync-comfyui-snaps] Syncing ${SRC} → ${DEST}/"
|
||||||
|
rsync -vu --checksum \
|
||||||
|
--include="*.png" --include="*.jpg" --include="*.jpeg" --include="*.webp" \
|
||||||
|
--exclude="*" \
|
||||||
|
--progress --stats \
|
||||||
|
"${SRC}" "${DEST}/"
|
||||||
|
|
||||||
|
# 3. Rename AI snaps (non-interactive for automation)
|
||||||
|
if [ -x "${RENAME_SCRIPT}" ]; then
|
||||||
|
echo "[sync-comfyui-snaps] Running rename-ai-snaps on ${DEST}"
|
||||||
|
"${RENAME_SCRIPT}" "${DEST}" --no-interactive
|
||||||
|
else
|
||||||
|
echo "[sync-comfyui-snaps] WARNING: rename-ai-snaps not found at ${RENAME_SCRIPT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. Organize images
|
||||||
|
if [ -x "${ORGANIZE_SCRIPT}" ]; then
|
||||||
|
echo "[sync-comfyui-snaps] Running organize-images on ${DEST}"
|
||||||
|
"${ORGANIZE_SCRIPT}" "${DEST}" -e
|
||||||
|
else
|
||||||
|
echo "[sync-comfyui-snaps] WARNING: organize-images not found at ${ORGANIZE_SCRIPT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
DURATION=$(( $(date +%s) - START ))
|
||||||
|
echo "[sync-comfyui-snaps] Done in ${DURATION}s at $(date)"
|
||||||
Reference in New Issue
Block a user