From 17370b2d50c5a94aa486077a818b3e249a301065 Mon Sep 17 00:00:00 2001 From: holzi1005 Date: Tue, 7 Jan 2025 18:10:09 +0100 Subject: [PATCH] update inotify --- inotify.sh | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/inotify.sh b/inotify.sh index c7dc6ae..9beed09 100644 --- a/inotify.sh +++ b/inotify.sh @@ -1,5 +1,7 @@ #!/bin/sh +export PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin/bin + inotifywait -m /out -e close_write | while read PATH ACTION FILE; do @@ -12,23 +14,45 @@ inotifywait -m /out -e close_write | chunk_size="$CHUNK_SIZE" id="${FILE%.mp4}" - file_size=$(/bin/stat -c%s "$file_path") + # Überprüfen, ob die Datei existiert + if [ ! -f "$file_path" ]; then + echo "Fehler: Datei $file_path existiert nicht." + exit 1 + fi + + # Dateigröße ermitteln + file_size=$(stat -c%s "$file_path") num_chunks=$(( (file_size + chunk_size - 1) / chunk_size )) + # Datei in Chunks hochladen i=0 while [ $i -lt $num_chunks ]; do - echo "${i}" - echo "${id}" - echo "${num_chunks}" - /bin/dd if="$file_path" bs=$chunk_size skip=$i count=1 2>/dev/null | \ - /usr/bin/curl --location "$UPLOAD_URL" \ - --header "Authorization: Bearer $AUTH_TOKEN" \ - --form "recording_id=${id}" \ - --form "chunk_index=${i}" \ - --form "total_chunks=${num_chunks}" \ - --form "FILE=@-" + # Temporäre Datei für den Chunk + temp_chunk_file="/tmp/chunk_$i" - i=$(( i + 1 )) + # Chunk erstellen + dd if="$file_path" bs=$chunk_size skip=$i count=1 of="$temp_chunk_file" 2>/dev/null + + # Überprüfen, ob der Chunk erfolgreich erstellt wurde + if [ -f "$temp_chunk_file" ]; then + # Chunk hochladen + curl --location "$UPLOAD_URL" \ + --header "Authorization: Bearer $AUTH_TOKEN" \ + --form "recording_id=${file%.mp4}" \ + --form "chunk_index=${i} \ + --form "total_chunks=${num_chunks}" \ + --form "file=@$temp_chunk_file" + + # Temporäre Datei löschen + rm "$temp_chunk_file" + else + echo "Fehler beim Erstellen des Chunks $i" + fi + + # Inkrementieren des Chunk-Zählers + i=$(( i + 1 )) done - fi + + + done