3 declare -A h # header array
4 # default (empty) action, to be overridden in config
21 if [ $(date +%s) -gt $toolate ]
29 checkshaandmoveorexit () {
33 if [ "$sha" ] && sha1=$(sha1sum "$src" | awk '{print$1}')
35 if [ "$sha1" = "$sha" ]
37 echo "$n $src sha1 ok"
38 wrap mv -v "$src" "$dst"
42 echo "$n $src sha1 FALSCH"
43 # keine action, aber ACK
48 wrap mv -v "$src" "$dst"
56 -f) f=$2;shift ;; # filename
57 -m) m=$2;shift ;; # mime type
58 -h) setheader "$2";shift ;; # headers
59 -n) n=$2;shift ;; # seq number
60 -r) r=$2;shift ;; # routing key
61 -d) dest=$2;shift ;; # file destination dir
62 -c) . $2 || exit;shift ;; # config snippet
63 -p) prio=$2;shift ;; # priority
64 -t) t=$2;shift ;; # timestamp
65 -R) redeliv=$2;shift ;; # redelivered message
69 trap "rm -f -- \"$f\"" 0 1 2 3 15
70 if [ "${h[chunkSize]}" -a "${h[fileSize]}" ]
78 toolate=$((begin+maxwait))
79 if [ "${h[chunkSize]}" = "${h[fileSize]}" ]
82 wrap cp -v "$f" "$temp/${h[fileName]}"
83 checkshaandmoveorexit "${h[sha1]}" "$temp/${h[fileName]}" "$dest/${h[fileName]}"
84 elif [ "${h[chunkIndex]}" ]
87 wrap cp -v "$f" "$temp/${h[fileName]}.part${h[chunkIndex]}"
88 if [ "${h[chunkCount]}" = "${h[chunkIndex]}" ]
92 until checktimeout; [ -f "$temp/${h[fileName]}.part" ]
94 for i in `seq 1 ${h[chunkCount]}`
96 if ! [ -f "$temp/${h[fileName]}.part$i" ]
98 # einer fehlt. versuch beenden. warten bis der da ist. nochmal probieren.
99 rm -f "$temp/${h[fileName]}.part"
103 # ls -l "$temp/${h[fileName]}.part$i"
104 cat "$temp/${h[fileName]}.part$i" >> "$temp/${h[fileName]}.part"
107 # warten, bis die Prozesse der anderen Teile sich beendet und ihre
108 # Datei entfernt haben und keine *.part* mehr da sind
109 wrap mv -v "$temp/${h[fileName]}.part" "$temp/${h[fileName]}"
110 rm -f -- "$temp/${h[fileName]}.part${h[chunkIndex]}"
111 until checktimeout; [ "$(echo "$temp/${h[fileName]}.part"*)" = "$temp/${h[fileName]}.part*" ]
115 checkshaandmoveorexit "${h[sha1]}" "$temp/${h[fileName]}" "$dest/${h[fileName]}"
118 # erst ACKen, wenn alle Teile da sind und zusammengesetzt sind.
119 until checktimeout; [ -f "$temp/${h[fileName]}" ]
123 rm -f -- "$temp/${h[fileName]}.part${h[chunkIndex]}"
127 # keine headerdaten, normal!