From 3bdd26ed81496f036b4a7c71faae19bba1e45a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Tr=C3=B6ger?= Date: Sat, 3 Jan 2026 10:47:27 +0100 Subject: [PATCH] First step into separated scripts --- desktop/darktable-sync-only.desktop | 7 + desktop/darktable-with-sync.desktop | 7 + install.sh | 301 +++++++--------------------- scripts/darktable_sync.sh | 109 ++++++++++ scripts/darktable_wrapper.sh | 12 ++ systemd/darktable_sync.service | 6 + systemd/darktable_sync.timer | 10 + 7 files changed, 228 insertions(+), 224 deletions(-) create mode 100644 desktop/darktable-sync-only.desktop create mode 100644 desktop/darktable-with-sync.desktop create mode 100755 scripts/darktable_sync.sh create mode 100755 scripts/darktable_wrapper.sh create mode 100644 systemd/darktable_sync.service create mode 100644 systemd/darktable_sync.timer diff --git a/desktop/darktable-sync-only.desktop b/desktop/darktable-sync-only.desktop new file mode 100644 index 0000000..876f387 --- /dev/null +++ b/desktop/darktable-sync-only.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=Darktable sync only +Comment=Run Darktable sync without starting Darktable +Exec=/home/%u/.local/bin/darktable_sync.sh --with-notify-start-stop +Terminal=false +Categories=Graphics;Photography; diff --git a/desktop/darktable-with-sync.desktop b/desktop/darktable-with-sync.desktop new file mode 100644 index 0000000..704a2ee --- /dev/null +++ b/desktop/darktable-with-sync.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=Darktable (with sync) +Comment=Start Darktable and run sync in background +Exec=/home/%u/.local/bin/darktable_wrapper.sh +Terminal=false +Categories=Graphics;Photography; diff --git a/install.sh b/install.sh index ab9652b..e634e31 100755 --- a/install.sh +++ b/install.sh @@ -2,274 +2,127 @@ set -e -### πŸ”§ Default Configuration (can be overridden by .env file) -SERVER_USER="${SERVER_USER:-$USER}" # Default: current user -SERVER_SSH_PORT="${SERVER_SSH_PORT:-22}" # Default: standard SSH port -SERVER_IP="${SERVER_IP:-192.168.1.100}" # Default: common local network +### Default Configuration (can be overridden by .env file) + +SERVER_USER="${SERVER_USER:-$USER}" # Default: current user +SERVER_SSH_PORT="${SERVER_SSH_PORT:-22}" # Default: standard SSH port +SERVER_IP="${SERVER_IP:-192.168.1.100}" # Default: common local network + SERVER_DB_DIR="${SERVER_DB_DIR:-/volume1/Darktable/darktable_db}" SERVER_PHOTO_DIR="${SERVER_PHOTO_DIR:-/volume1/Darktable/photo_library}" + LOCAL_PHOTO_DIR="${PHOTO_DIR:-$HOME/Pictures/raw}" LOCAL_DARKTABLE_DB_DIR="${DARKTABLE_DB_DIR:-$HOME/.config/darktable}" + BIN_DIR="${BIN_DIR:-$HOME/.local/bin}" APPLICATIONS_DIR="$HOME/.local/share/applications" + SYNC_SCRIPT="$BIN_DIR/darktable_sync.sh" WRAPPER_SCRIPT="$BIN_DIR/darktable_wrapper.sh" DESKTOP_SHORTCUT="$APPLICATIONS_DIR/darktable-with-sync.desktop" SYNC_ONLY_SHORTCUT="$APPLICATIONS_DIR/darktable-sync-only.desktop" +### Prepare folders -### πŸ“ Prepare folders mkdir -p "$BIN_DIR" mkdir -p "$HOME/.config/systemd/user" +mkdir -p "$APPLICATIONS_DIR" + +### Load .env if present (overrides defaults) -### πŸ”„ Load .env if present (overrides defaults) ENV_FILE=".env" + if [[ -f "$ENV_FILE" ]]; then - echo "πŸ“₯ Loading configuration from .env file..." - set -a # automatically export all variables - source "$ENV_FILE" - set +a + echo "Loading configuration from .env file..." + set -a + # shellcheck source=/dev/null + . "$ENV_FILE" + set +a fi -### πŸ“ Show effective configuration -echo "Using configuration:" -echo "SERVER_USER: $SERVER_USER" -echo "SERVER_IP: $SERVER_IP" -echo "SERVER_SSH_PORT: $SERVER_SSH_PORT" -echo "SERVER_DB_DIR: $SERVER_DB_DIR" -echo "SERVER_PHOTO_DIR: $SERVER_PHOTO_DIR" -echo "PHOTO_DIR: $LOCAL_PHOTO_DIR" -echo "DARKTABLE_DB_DIR:$LOCAL_DARKTABLE_DB_DIR" -echo "BIN_DIR: $BIN_DIR" +### Show effective configuration -### πŸ” Check dependencies -echo "πŸ” Checking requirements..." +echo "Using configuration:" +echo "SERVER_USER: $SERVER_USER" +echo "SERVER_IP: $SERVER_IP" +echo "SERVER_SSH_PORT: $SERVER_SSH_PORT" +echo "SERVER_DB_DIR: $SERVER_DB_DIR" +echo "SERVER_PHOTO_DIR: $SERVER_PHOTO_DIR" +echo "PHOTO_DIR: $LOCAL_PHOTO_DIR" +echo "DARKTABLE_DB_DIR: $LOCAL_DARKTABLE_DB_DIR" +echo "BIN_DIR: $BIN_DIR" + +### Check dependencies + +echo "Checking requirements..." REQUIRED_CMDS=("rsync" "notify-send" "ping" "darktable" "systemctl" "xdg-user-dir") + for cmd in "${REQUIRED_CMDS[@]}"; do - if ! command -v "$cmd" >/dev/null 2>&1; then - echo "❌ Error: '$cmd' is not installed." - echo "πŸ‘‰ You can install it with: sudo apt install $cmd" - exit 1 - fi + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "Error: '$cmd' is not installed." + echo "Install it with: sudo apt install $cmd" + exit 1 + fi done # Check folder presence + if [ ! -d "$LOCAL_PHOTO_DIR" ]; then - echo "❌ Local photo folder does not exist: $LOCAL_PHOTO_DIR" - echo "πŸ‘‰ Please create it using: mkdir -p \"$LOCAL_PHOTO_DIR\"" - exit 1 -fi - -if [ ! -d "$LOCAL_DARKTABLE_DB_DIR" ]; then - echo "❌ Darktable database path does not exist: $LOCAL_DARKTABLE_DB_DIR" - echo "πŸ‘‰ Start Darktable once or create the directory manually." - exit 1 -fi - -# Check if Server is reachable -if ping -c 1 "$SERVER_IP" &>/dev/null; then - echo "βœ… Server is reachable: $SERVER_IP" - - if ! ssh -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" "[ -d '$SERVER_DB_DIR' ]"; then - echo "❌ Remote directory missing on Server: $SERVER_DB_DIR" - echo "πŸ‘‰ Please create it or adjust the path." - exit 1 - fi - - if ! ssh -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" "[ -d '$SERVER_PHOTO_DIR' ]"; then - echo "❌ Remote directory missing on Server: $SERVER_PHOTO_DIR" - echo "πŸ‘‰ Please create it or adjust the path." - exit 1 - fi -else - echo "⚠️ Server not reachable: $SERVER_IP" - echo "➑️ Sync will fail until Server is online." -fi - -### βœ… Create sync script -cat > "$SYNC_SCRIPT" <f|cd)' "\$LOG" | wc -l) - ;; - *) - COUNT=0 - ;; - esac - - echo "\$COUNT" -} - -SCRIPT_NAME=\$(basename \$0) -LOCKFILE="/tmp/\${SCRIPT_NAME}.lock" -if [ -e "\$LOCKFILE" ]; then - echo "Scrip is already running or delete \$LOCKFILE" + echo "Local photo folder does not exist: $LOCAL_PHOTO_DIR" + echo "Create it using: mkdir -p \"$LOCAL_PHOTO_DIR\"" exit 1 fi -touch "\$LOCKFILE" -trap "rm -f '\$LOCKFILE'" EXIT - -SHOW_NOTIFY_START_STOP=false -if [[ "\$1" == "--with-notify-start-stop" ]]; then - SHOW_NOTIFY_START_STOP=true +if [ ! -d "$LOCAL_DARKTABLE_DB_DIR" ]; then + echo "Darktable database path does not exist: $LOCAL_DARKTABLE_DB_DIR" + echo "Start Darktable once or create the directory manually." + exit 1 fi -if ping -c 1 $SERVER_IP &>/dev/null; then - export DISPLAY=:0 - SYNC_LOG=\$(mktemp) - log "πŸ”ƒ Server is reachable – starting sync..." - log "Log file: \$SYNC_LOG" +# Check if server is reachable and remote dirs exist - if [ "\$SHOW_NOTIFY_START_STOP" = true ]; then - notify-send "Darktable Sync" "πŸ”„ Sync started..." -t 3000 - fi +if ping -c 1 "$SERVER_IP" &>/dev/null; then + echo "Server is reachable: $SERVER_IP" - log "⬆️ Uploading Darktable DB to Server..." - UPLOAD_LOG1=\$(mktemp) - rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" "$LOCAL_DARKTABLE_DB_DIR/" "$SERVER_USER@$SERVER_IP:$SERVER_DB_DIR/" 2>&1 | tee -a "\$SYNC_LOG" "\$UPLOAD_LOG1" - SENT1=\$(count_synced_files "\$UPLOAD_LOG1" "up") - rm "\$UPLOAD_LOG1" + if ! ssh -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" "[ -d '$SERVER_DB_DIR' ]"; then + echo "Remote directory missing on server: $SERVER_DB_DIR" + echo "Create it or adjust the path." + exit 1 + fi - log "⬆️ Uploading photos to Server..." - UPLOAD_LOG2=\$(mktemp) - rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" "$LOCAL_PHOTO_DIR/" "$SERVER_USER@$SERVER_IP:$SERVER_PHOTO_DIR/" 2>&1 | tee -a "\$SYNC_LOG" "\$UPLOAD_LOG2" - SENT2=\$(count_synced_files "\$UPLOAD_LOG2" "up") - rm "\$UPLOAD_LOG2" - - log "⬇️ Downloading DB back from Server..." - DOWNLOAD_LOG1=\$(mktemp) - rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP:$SERVER_DB_DIR/" "$LOCAL_DARKTABLE_DB_DIR/" 2>&1 | tee -a "\$SYNC_LOG" "\$DOWNLOAD_LOG1" - RECEIVED1=\$(count_synced_files "\$DOWNLOAD_LOG1" "down") - rm "\$DOWNLOAD_LOG1" - - log "⬇️ Downloading photos from Server..." - DOWNLOAD_LOG2=\$(mktemp) - rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP:$SERVER_PHOTO_DIR/" "$LOCAL_PHOTO_DIR/" 2>&1 | tee -a "\$SYNC_LOG" "\$DOWNLOAD_LOG2" - RECEIVED2=\$(count_synced_files "\$DOWNLOAD_LOG2" "down") - rm "\$DOWNLOAD_LOG2" - - if [ "\$SHOW_NOTIFY_START_STOP" = true ]; then - notify-send "Darktable Sync" "βœ… Sync finished." -t 3000 - fi - - TOTAL_SENT=\$((SENT1 + SENT2)) - TOTAL_RECEIVED=\$((RECEIVED1 + RECEIVED2)) - - if [ "\$TOTAL_SENT" -gt 0 ] || [ "\$TOTAL_RECEIVED" -gt 0 ]; then - log "βœ… Uploaded: \$TOTAL_SENT files" - log "βœ… Downloaded: \$TOTAL_RECEIVED files" - notify-send "Darktable Sync" "⬆️ \$TOTAL_SENT uploaded | ⬇️ \$TOTAL_RECEIVED downloaded" -t 10000 - else - log "ℹ️ No changes detected." - fi - - rm -f "\$SYNC_LOG" + if ! ssh -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" "[ -d '$SERVER_PHOTO_DIR' ]"; then + echo "Remote directory missing on server: $SERVER_PHOTO_DIR" + echo "Create it or adjust the path." + exit 1 + fi else - log "❌ Server not reachable – skipping sync." + echo "Server not reachable: $SERVER_IP" + echo "Sync will fail until server is online." fi -EOF -chmod +x "$SYNC_SCRIPT" +### Install sync and wrapper scripts -### βœ… Create wrapper script with sync + notify -cat > "$WRAPPER_SCRIPT" < "$HOME/.config/systemd/user/darktable-sync.service" </dev/null || true -# [Service] -# Type=oneshot -# ExecStart=$SYNC_SCRIPT -# EOF - -# cat > "$HOME/.config/systemd/user/darktable-sync.timer" < "$DESKTOP_SHORTCUT" < "$SYNC_ONLY_SHORTCUT" <f|cd' "$LOG" | wc -l) + ;; + down) + COUNT=$(grep -E '^/dev/null; then + export DISPLAY=:0 + SYNC_LOG=$(mktemp) + log "Server is reachable – starting sync..." + log "Log file: $SYNC_LOG" + + if [ "$SHOW_NOTIFY_START_STOP" = true ]; then + notify-send "Darktable Sync" "Sync started..." -t 3000 + fi + + log "Uploading Darktable DB to Server..." + UPLOAD_LOG1=$(mktemp) + rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" \ + "$LOCAL_DARKTABLE_DB_DIR/" "$SERVER_USER@$SERVER_IP:$SERVER_DB_DIR/" \ + 2>&1 | tee -a "$SYNC_LOG" "$UPLOAD_LOG1" + SENT1=$(count_synced_files "$UPLOAD_LOG1" "up") + rm "$UPLOAD_LOG1" + + log "Uploading photos to Server..." + UPLOAD_LOG2=$(mktemp) + rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" \ + "$LOCAL_PHOTO_DIR/" "$SERVER_USER@$SERVER_IP:$SERVER_PHOTO_DIR/" \ + 2>&1 | tee -a "$SYNC_LOG" "$UPLOAD_LOG2" + SENT2=$(count_synced_files "$UPLOAD_LOG2" "up") + rm "$UPLOAD_LOG2" + + log "Downloading DB back from Server..." + DOWNLOAD_LOG1=$(mktemp) + rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" \ + "$SERVER_USER@$SERVER_IP:$SERVER_DB_DIR/" "$LOCAL_DARKTABLE_DB_DIR/" \ + 2>&1 | tee -a "$SYNC_LOG" "$DOWNLOAD_LOG1" + RECEIVED1=$(count_synced_files "$DOWNLOAD_LOG1" "down") + rm "$DOWNLOAD_LOG1" + + log "Downloading photos from Server..." + DOWNLOAD_LOG2=$(mktemp) + rsync -uavh --itemize-changes -e "ssh -p $SERVER_SSH_PORT" \ + "$SERVER_USER@$SERVER_IP:$SERVER_PHOTO_DIR/" "$LOCAL_PHOTO_DIR/" \ + 2>&1 | tee -a "$SYNC_LOG" "$DOWNLOAD_LOG2" + RECEIVED2=$(count_synced_files "$DOWNLOAD_LOG2" "down") + rm "$DOWNLOAD_LOG2" + + if [ "$SHOW_NOTIFY_START_STOP" = true ]; then + notify-send "Darktable Sync" "Sync finished." -t 3000 + fi + + TOTAL_SENT=$((SENT1 + SENT2)) + TOTAL_RECEIVED=$((RECEIVED1 + RECEIVED2)) + + if [ "$TOTAL_SENT" -gt 0 ] || [ "$TOTAL_RECEIVED" -gt 0 ]; then + log "Uploaded: $TOTAL_SENT files" + log "Downloaded: $TOTAL_RECEIVED files" + notify-send "Darktable Sync" "↑ $TOTAL_SENT uploaded | ↓ $TOTAL_RECEIVED downloaded" -t 10000 + else + log "No changes detected." + fi + + rm -f "$SYNC_LOG" +else + log "Server not reachable – skipping sync." +fi diff --git a/scripts/darktable_wrapper.sh b/scripts/darktable_wrapper.sh new file mode 100755 index 0000000..2f23b94 --- /dev/null +++ b/scripts/darktable_wrapper.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# Konfiguration (per ENV ΓΌberschreibbar) +DARKTABLE_BIN="${DARKTABLE_BIN:-darktable}" +SYNC_BIN="${SYNC_BIN:-darktable_sync.sh}" + +# Sync im Hintergrund starten +"$SYNC_BIN" --with-notify-start-stop & + +# Darktable starten +exec "$DARKTABLE_BIN" "$@" diff --git a/systemd/darktable_sync.service b/systemd/darktable_sync.service new file mode 100644 index 0000000..6b25ead --- /dev/null +++ b/systemd/darktable_sync.service @@ -0,0 +1,6 @@ +[Unit] +Description=Darktable sync service + +[Service] +Type=oneshot +ExecStart=%h/.local/bin/darktable_sync.sh diff --git a/systemd/darktable_sync.timer b/systemd/darktable_sync.timer new file mode 100644 index 0000000..e24468e --- /dev/null +++ b/systemd/darktable_sync.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run Darktable sync periodically + +[Timer] +OnCalendar=*-*-* *:00:00 +Persistent=true +Unit=darktable-sync.service + +[Install] +WantedBy=timers.target