From 46664ab3b6bc3312f8f0eac92887e91cec7ecb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Tr=C3=B6ger?= Date: Sun, 19 Apr 2026 19:45:11 +0200 Subject: [PATCH] Code-Vereinfachung: Redundanzen entfernen und Wiederverwendung verbessern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - log() Funktion in darktable_common.sh ausgelagert (war doppelt vorhanden) - ssh_server() Hilfsfunktion für wiederholte SSH-Aufrufe mit konsistenten Optionen - ssh_server() nutzen statt inline SSH-Befehle in darktable_sync.sh und darktable_wrapper.sh - Reduzierung von SSH-Optionswiederbholungen (ConnectTimeout, BatchMode, Port) Co-Authored-By: Claude Sonnet 4.6 --- scripts/darktable_common.sh | 12 ++++++++++-- scripts/darktable_sync.sh | 12 ++---------- scripts/darktable_wrapper.sh | 16 +++------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/scripts/darktable_common.sh b/scripts/darktable_common.sh index aa265ec..5e670da 100644 --- a/scripts/darktable_common.sh +++ b/scripts/darktable_common.sh @@ -44,9 +44,17 @@ check_dependency() { fi } -server_reachable() { +log() { + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" +} + +ssh_server() { ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" true 2>/dev/null + -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" "$@" +} + +server_reachable() { + ssh_server true 2>/dev/null } ask_user() { diff --git a/scripts/darktable_sync.sh b/scripts/darktable_sync.sh index 5e5eaeb..a10b9bd 100755 --- a/scripts/darktable_sync.sh +++ b/scripts/darktable_sync.sh @@ -15,10 +15,6 @@ validate_config export DISPLAY="${DISPLAY:-:0}" -log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" -} - count_synced_files() { local log_file="$1" direction="$2" count=0 case "$direction" in @@ -59,17 +55,13 @@ if [ "$SHOW_NOTIFY_START_STOP" = true ]; then notify-send "Darktable Sync" "Sync gestartet..." -t 3000 fi -ACTIVE=$(ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \ - "cat '$SERVER_DB_DIR/darktable.active' 2>/dev/null || true") +ACTIVE=$(ssh_server "cat '$SERVER_DB_DIR/darktable.active' 2>/dev/null || true") if [ -n "$ACTIVE" ]; then notify-send "Darktable Sync – Warnung" \ "Darktable laueft moeglicherweise auf: $ACTIVE" -u normal -t 10000 fi -SERVER_VERSION=$(ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \ - "cat '$SERVER_DB_DIR/darktable_version' 2>/dev/null || true") +SERVER_VERSION=$(ssh_server "cat '$SERVER_DB_DIR/darktable_version' 2>/dev/null || true") LOCAL_VERSION=$(darktable --version 2>&1 | head -1) diff --git a/scripts/darktable_wrapper.sh b/scripts/darktable_wrapper.sh index e6d026b..608184a 100755 --- a/scripts/darktable_wrapper.sh +++ b/scripts/darktable_wrapper.sh @@ -14,10 +14,6 @@ validate_config export DISPLAY="${DISPLAY:-:0}" -log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" -} - if pgrep -x darktable &>/dev/null; then notify-send "Darktable" \ "Darktable laeuft bereits. Bitte zuerst schliessen." -u critical @@ -28,9 +24,7 @@ ACTIVE_MARKER_SET=false cleanup() { if [ "$ACTIVE_MARKER_SET" = true ]; then - ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \ - "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true + ssh_server "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true fi } trap cleanup EXIT INT TERM @@ -47,9 +41,7 @@ else "$SYNC_BIN" MARKER="$(hostname) seit $(date '+%Y-%m-%d %H:%M:%S')" - ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \ - "echo '$MARKER' > '$SERVER_DB_DIR/darktable.active'" || true + ssh_server "echo '$MARKER' > '$SERVER_DB_DIR/darktable.active'" || true ACTIVE_MARKER_SET=true fi @@ -58,9 +50,7 @@ log "Starte Darktable..." log "Darktable beendet." if [ "$ACTIVE_MARKER_SET" = true ]; then - ssh -o ConnectTimeout=5 -o BatchMode=yes \ - -p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \ - "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true + ssh_server "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true ACTIVE_MARKER_SET=false fi