diff --git a/usenet-scripts/movetdarr.sh b/usenet-scripts/movetdarr.sh new file mode 100644 index 0000000..94a6824 --- /dev/null +++ b/usenet-scripts/movetdarr.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# movetdarr.sh v2 — SABnzbd PostProcessing: Download -> FileFlows-Eingang (/tdarr/complete) +# Fixes 05.09.2026: +# - Vor dem mv: bestehendes Zielverzeichnis ohne Video-Datei (FileFlows-Leichen) wird entfernt +# - Fehler beim mv werden GEMELDET (exit 1) statt still zu scheitern +# - Ziel mit existierender Video-Datei: Download behalten + WARNUNG (kein Datenverlust) +DIR="$1" +CATEGORY="$5" +STATUS="$7" + +LOGFILE="/usenet/scripts/postprocess.log" +log() { echo "$(date '+%d.%m.%Y %H:%M:%S'): $1" >> "$LOGFILE"; } + +log "Start - Kategorie=$CATEGORY Status=$STATUS Dir=$DIR" + +if [ "$STATUS" != "0" ]; then + log "Download fehlgeschlagen, ueberspringe" + exit 1 +fi + +if [ ! -d "$DIR" ]; then + log "Quellverzeichnis existiert nicht: $DIR" + exit 1 +fi + +DEST="/tdarr/complete/${CATEGORY}" +BASENAME="$(basename "$DIR")" +TARGET="$DEST/$BASENAME" + +mkdir -p "$DEST" + +# Leichen-Handling: existiert das Ziel schon? +if [ -d "$TARGET" ]; then + # Enthaelt es Video-Dateien? + if ls "$TARGET"/*.mkv "$TARGET"/*.mp4 "$TARGET"/*.avi >/dev/null 2>&1; then + log "WARNUNG: Ziel $TARGET enthaelt bereits Video-Dateien - NICHT ueberschrieben, Download bleibt in $DIR" + exit 2 + fi + log "Entferne FileFlows-Restverzeichnis (keine Videos enthalten): $TARGET" + rm -rf "$TARGET" + if [ $? -ne 0 ]; then + log "FEHLER: konnte Restverzeichnis $TARGET nicht entfernen" + exit 1 + fi +fi + +mv "$DIR" "$DEST/" + +if [ $? -eq 0 ]; then + log "Erfolgreich verschoben nach $TARGET" + exit 0 +else + log "FEHLER beim Verschieben nach $TARGET (Quelle bleibt: $DIR)" + exit 1 +fi \ No newline at end of file