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
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user