From abecfeafecda92ccd1a14f909564c1822b90e3fa Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 22:17:14 +0100 Subject: [PATCH 1/4] Add curl response to stdout if it fails Apparently, it must be called with `-v` otherwise it is silent. --- tools/consumedir.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/consumedir.sh b/tools/consumedir.sh index 77f4c550..47a8882c 100755 --- a/tools/consumedir.sh +++ b/tools/consumedir.sh @@ -248,7 +248,7 @@ checkFile() { url=$url/$(checksum "$file") trace "- Check file via $OPTS: $url" tf1=$($MKTEMP_CMD) tf2=$($MKTEMP_CMD) - $CURL_CMD --fail -o "$tf1" --stderr "$tf2" $OPTS -XGET -s "$url" + $CURL_CMD --fail -v -o "$tf1" --stderr "$tf2" $OPTS -XGET -s "$url" if [ $? -ne 0 ]; then info "Checking file failed!" cat "$tf1" >&2 From 67d2e93c4ddbafd5c79bef22d1317e305aa40371 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 22:46:21 +0100 Subject: [PATCH 2/4] Check setup when using integration endpoint Public upload urls cannot be checked like that currently. --- tools/consumedir.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/consumedir.sh b/tools/consumedir.sh index 47a8882c..e15faae6 100755 --- a/tools/consumedir.sh +++ b/tools/consumedir.sh @@ -324,6 +324,35 @@ findDir() { done } +checkSetup() { + for dir in "${watchdir[@]}"; do + find "$dir" -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -d '' -r collective; do + for url in $urls; do + if [ "$integration" = "y" ]; then + url="$url/$(basename $collective)" + OPTS="$CURL_OPTS -i -s -o /dev/null -w %{http_code}" + if [ $iuser ]; then + OPTS="$OPTS --user $iuser" + fi + if [ $iheader ]; then + OPTS="$OPTS -H $iheader" + fi + trace "Checking integration endpoint: $CURL_CMD $OPTS "$url"" + status=$($CURL_CMD $OPTS "$url") + if [ "$status" != "200" ]; then + echo "[ERROR] $status response integration endpoint: $CURL_CMD $OPTS $url" + exit 1 + fi + fi + done + done + done +} + + +# quit here if something is not correctly configured +checkSetup + if [ "$once" = "y" ]; then info "Uploading all files in '$watchdir'." MD="-maxdepth 1" From 631e6abbfd1f129ca50fcbdc066bbafeaefcb18b Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 23:00:05 +0100 Subject: [PATCH 3/4] Skip hidden files in consumedir --- tools/consumedir.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/consumedir.sh b/tools/consumedir.sh index e15faae6..b0df9abb 100755 --- a/tools/consumedir.sh +++ b/tools/consumedir.sh @@ -354,13 +354,13 @@ checkSetup() { checkSetup if [ "$once" = "y" ]; then - info "Uploading all files in '$watchdir'." + info "Uploading all files (except hidden) in '$watchdir'." MD="-maxdepth 1" if [ "$recursive" = "y" ]; then MD="" fi for dir in "${watchdir[@]}"; do - find "$dir" $MD -type f -print0 | while IFS= read -d '' -r file; do + find "$dir" $MD -type f -not -name ".*" -print0 | while IFS= read -d '' -r file; do process "$file" "$dir" done done @@ -371,9 +371,13 @@ else fi $INOTIFY_CMD $REC -m --format '%w%f' -e close_write -e moved_to "${watchdir[@]}" | while read pathfile; do - dir=$(findDir "$pathfile") - trace "The file '$pathfile' appeared below '$dir'" - sleep 1 - process "$(realpath "$pathfile")" "$dir" + if [[ "$(basename "$pathfile")" != .* ]]; then + dir=$(findDir "$pathfile") + trace "The file '$pathfile' appeared below '$dir'" + sleep 1 + process "$(realpath "$pathfile")" "$dir" + else + trace "Skip hidden file $(realpath "$pathfile")" + fi done fi From 88c16d1bbef5a5343b70161796e03c9c82a7cfd3 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 23:52:12 +0100 Subject: [PATCH 4/4] Add skipDuplicates option to upload in consumedir The `-m` setting checks before upload if a file exists. It is now also checked when the file is being processed. --- tools/consumedir.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/consumedir.sh b/tools/consumedir.sh index b0df9abb..c4d4169e 100755 --- a/tools/consumedir.sh +++ b/tools/consumedir.sh @@ -197,9 +197,15 @@ upload() { if [ "$dryrun" = "y" ]; then info "- Not uploading (dry-run) $file to $url with opts $OPTS" else + META1="" + META2="" + if [ "$distinct" = "y" ]; then + META1="-F" + META2="meta={\"multiple\": false, \"skipDuplicates\": true}" + fi trace "- Uploading $file to $url with options $OPTS" tf1=$($MKTEMP_CMD) tf2=$($MKTEMP_CMD) rc=0 - $CURL_CMD --fail -# -o "$tf1" --stderr "$tf2" $OPTS -XPOST -F file=@"$file" "$url" + $CURL_CMD --fail -# -o "$tf1" --stderr "$tf2" $OPTS -XPOST $META1 "$META2" -F file=@"$file" "$url" if [ $? -ne 0 ]; then info "Upload failed. Exit code: $rc" cat "$tf1"