update inotify
This commit is contained in:
parent
a7fc324201
commit
17370b2d50
1 changed files with 37 additions and 13 deletions
50
inotify.sh
50
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
|
||||
|
|
Loading…
Add table
Reference in a new issue