2 # SPDX-FileCopyrightText: 2022 Frank Doepper
4 # SPDX-License-Identifier: GPL-3.0-only
7 declare -A h # header array
8 # default (empty) action, to be overridden in config
25 if [ $(date +%s) -gt $toolate ]
33 checkshaandmoveorexit () {
37 if [ "$sha" ] && sha1=$(sha1sum "$src" | awk '{print$1}')
39 if [ "$sha1" = "$sha" ]
41 echo "$n $src sha1 ok"
42 wrap mv -v "$src" "$dst"
46 echo "$n $src sha1 FALSCH"
47 # keine action, aber ACK
52 wrap mv -v "$src" "$dst"
60 -f) f=$2;shift ;; # filename
61 -m) m=$2;shift ;; # mime type
62 -h) setheader "$2";shift ;; # headers
63 -n) n=$2;shift ;; # seq number
64 -r) r=$2;shift ;; # routing key
65 -d) dest=$2;shift ;; # file destination dir
66 -c) . $2 || exit;shift ;; # config snippet
67 -p) prio=$2;shift ;; # priority
68 -t) t=$2;shift ;; # timestamp
69 -R) redeliv=$2;shift ;; # redelivered message
73 trap "rm -f -- \"$f\"" 0 1 2 3 15
74 if [ "${h[chunkSize]}" -a "${h[fileSize]}" ]
82 toolate=$((begin+maxwait))
83 if [ "${h[chunkSize]}" = "${h[fileSize]}" ]
86 wrap cp -v "$f" "$temp/${h[fileName]}"
87 checkshaandmoveorexit "${h[sha1]}" "$temp/${h[fileName]}" "$dest/${h[fileName]}"
88 elif [ "${h[chunkIndex]}" ]
91 wrap cp -v "$f" "$temp/${h[fileName]}.part${h[chunkIndex]}"
92 if [ "${h[chunkCount]}" = "${h[chunkIndex]}" ]
96 until checktimeout; [ -f "$temp/${h[fileName]}.part" ]
98 for i in `seq 1 ${h[chunkCount]}`
100 if ! [ -f "$temp/${h[fileName]}.part$i" ]
102 # einer fehlt. versuch beenden. warten bis der da ist. nochmal probieren.
103 rm -f "$temp/${h[fileName]}.part"
107 # ls -l "$temp/${h[fileName]}.part$i"
108 cat "$temp/${h[fileName]}.part$i" >> "$temp/${h[fileName]}.part"
111 # warten, bis die Prozesse der anderen Teile sich beendet und ihre
112 # Datei entfernt haben und keine *.part* mehr da sind
113 wrap mv -v "$temp/${h[fileName]}.part" "$temp/${h[fileName]}"
114 rm -f -- "$temp/${h[fileName]}.part${h[chunkIndex]}"
115 until checktimeout; [ "$(echo "$temp/${h[fileName]}.part"*)" = "$temp/${h[fileName]}.part*" ]
119 checkshaandmoveorexit "${h[sha1]}" "$temp/${h[fileName]}" "$dest/${h[fileName]}"
122 # erst ACKen, wenn alle Teile da sind und zusammengesetzt sind.
123 until checktimeout; [ -f "$temp/${h[fileName]}" ]
127 rm -f -- "$temp/${h[fileName]}.part${h[chunkIndex]}"
131 # keine headerdaten, normal!