Code-Vereinfachung: Redundanzen entfernen und Wiederverwendung verbessern
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -44,9 +44,17 @@ check_dependency() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
server_reachable() {
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_server() {
|
||||||
ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
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() {
|
ask_user() {
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ validate_config
|
|||||||
|
|
||||||
export DISPLAY="${DISPLAY:-:0}"
|
export DISPLAY="${DISPLAY:-:0}"
|
||||||
|
|
||||||
log() {
|
|
||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
count_synced_files() {
|
count_synced_files() {
|
||||||
local log_file="$1" direction="$2" count=0
|
local log_file="$1" direction="$2" count=0
|
||||||
case "$direction" in
|
case "$direction" in
|
||||||
@@ -59,17 +55,13 @@ if [ "$SHOW_NOTIFY_START_STOP" = true ]; then
|
|||||||
notify-send "Darktable Sync" "Sync gestartet..." -t 3000
|
notify-send "Darktable Sync" "Sync gestartet..." -t 3000
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ACTIVE=$(ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
ACTIVE=$(ssh_server "cat '$SERVER_DB_DIR/darktable.active' 2>/dev/null || true")
|
||||||
-p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \
|
|
||||||
"cat '$SERVER_DB_DIR/darktable.active' 2>/dev/null || true")
|
|
||||||
if [ -n "$ACTIVE" ]; then
|
if [ -n "$ACTIVE" ]; then
|
||||||
notify-send "Darktable Sync – Warnung" \
|
notify-send "Darktable Sync – Warnung" \
|
||||||
"Darktable laueft moeglicherweise auf: $ACTIVE" -u normal -t 10000
|
"Darktable laueft moeglicherweise auf: $ACTIVE" -u normal -t 10000
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SERVER_VERSION=$(ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
SERVER_VERSION=$(ssh_server "cat '$SERVER_DB_DIR/darktable_version' 2>/dev/null || true")
|
||||||
-p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \
|
|
||||||
"cat '$SERVER_DB_DIR/darktable_version' 2>/dev/null || true")
|
|
||||||
|
|
||||||
LOCAL_VERSION=$(darktable --version 2>&1 | head -1)
|
LOCAL_VERSION=$(darktable --version 2>&1 | head -1)
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ validate_config
|
|||||||
|
|
||||||
export DISPLAY="${DISPLAY:-:0}"
|
export DISPLAY="${DISPLAY:-:0}"
|
||||||
|
|
||||||
log() {
|
|
||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
if pgrep -x darktable &>/dev/null; then
|
if pgrep -x darktable &>/dev/null; then
|
||||||
notify-send "Darktable" \
|
notify-send "Darktable" \
|
||||||
"Darktable laeuft bereits. Bitte zuerst schliessen." -u critical
|
"Darktable laeuft bereits. Bitte zuerst schliessen." -u critical
|
||||||
@@ -28,9 +24,7 @@ ACTIVE_MARKER_SET=false
|
|||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [ "$ACTIVE_MARKER_SET" = true ]; then
|
if [ "$ACTIVE_MARKER_SET" = true ]; then
|
||||||
ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
ssh_server "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true
|
||||||
-p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \
|
|
||||||
"rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
trap cleanup EXIT INT TERM
|
trap cleanup EXIT INT TERM
|
||||||
@@ -47,9 +41,7 @@ else
|
|||||||
"$SYNC_BIN"
|
"$SYNC_BIN"
|
||||||
|
|
||||||
MARKER="$(hostname) seit $(date '+%Y-%m-%d %H:%M:%S')"
|
MARKER="$(hostname) seit $(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
ssh_server "echo '$MARKER' > '$SERVER_DB_DIR/darktable.active'" || true
|
||||||
-p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \
|
|
||||||
"echo '$MARKER' > '$SERVER_DB_DIR/darktable.active'" || true
|
|
||||||
ACTIVE_MARKER_SET=true
|
ACTIVE_MARKER_SET=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -58,9 +50,7 @@ log "Starte Darktable..."
|
|||||||
log "Darktable beendet."
|
log "Darktable beendet."
|
||||||
|
|
||||||
if [ "$ACTIVE_MARKER_SET" = true ]; then
|
if [ "$ACTIVE_MARKER_SET" = true ]; then
|
||||||
ssh -o ConnectTimeout=5 -o BatchMode=yes \
|
ssh_server "rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true
|
||||||
-p "$SERVER_SSH_PORT" "$SERVER_USER@$SERVER_IP" \
|
|
||||||
"rm -f '$SERVER_DB_DIR/darktable.active'" 2>/dev/null || true
|
|
||||||
ACTIVE_MARKER_SET=false
|
ACTIVE_MARKER_SET=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user