From 1bb464b9eda9d9e908e23648564c5e20de8bafb9 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Thu, 27 Feb 2020 20:03:46 +0100 Subject: [PATCH] Extend `tools/ds.sh` to check for file existence --- modules/microsite/docs/features.md | 3 ++- tools/ds.sh | 38 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/modules/microsite/docs/features.md b/modules/microsite/docs/features.md index c5d60643..8390db7f 100644 --- a/modules/microsite/docs/features.md +++ b/modules/microsite/docs/features.md @@ -9,7 +9,8 @@ title: Features and Limitations - Multiple users per account - Handle multiple documents as one unit - OCR using [tesseract](https://github.com/tesseract-ocr/tesseract) -- Conversion to PDF: all files are converted into a PDF file +- Conversion to PDF: all files are converted into a PDF file, while + the original file is preserved - Text is analysed to find and attach meta data automatically - Manage document processing (cancel jobs, set priorities) - Everything available via a documented [REST Api](api) diff --git a/tools/ds.sh b/tools/ds.sh index 321c9f38..9d16f94d 100755 --- a/tools/ds.sh +++ b/tools/ds.sh @@ -15,6 +15,9 @@ # url.2=... # # Lines starting with a `#' are ignored. +# +# The `-e|--exists' option allows to skip uploading and only check +# whether a given file exists in docspell. # saner programming env: these switches turn some bugs into errors set -o errexit -o pipefail -o noclobber -o nounset @@ -30,8 +33,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then exit 1 fi -OPTIONS=c:hsd -LONGOPTS=config:,help,skip,delete +OPTIONS=c:hsde +LONGOPTS=config:,help,skip,delete,exists ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]]; then @@ -43,7 +46,7 @@ fi # read getopt’s output this way to handle the quoting right: eval set -- "$PARSED" -delete=n help=n config="${XDG_CONFIG_HOME:-$HOME/.config}/docspell/ds.conf" +exists=n delete=n help=n config="${XDG_CONFIG_HOME:-$HOME/.config}/docspell/ds.conf" while true; do case "$1" in -h|--help) @@ -58,6 +61,10 @@ while true; do delete="y" shift ;; + -e|--exists) + exists=y + shift + ;; --) shift break @@ -121,9 +128,10 @@ showUsage() { info " -c | --config Provide a config file. (value: $config)" info " -d | --delete Delete the files when successfully uploaded (value: $delete)" info " -h | --help Prints this help text. (value: $help)" + info " -e | --exists Checks for the existence of a file instead of uploading (value: $exists)" info "" info "Arguments:" - info " One or more PDF files to upload." + info " One or more files to check for existence or upload." info "" } @@ -153,13 +161,21 @@ done <<< $($GREP_CMD -v '^#.*' "$config") IFS=$'\n' for file in $*; do for url in "${urls[@]}"; do - info "Uploading '$file' to '$url'" - set +e - upload "$file" "$url" - set -e - if [ "$delete" = "y" ] && [ $? -eq 0 ]; then - info "Deleting file: $file" - rm -f "$file" + if [ "$exists" = "y" ]; then + if checkFile "$url" "$file"; then + info "$url $file: true" + else + info "$url $file: false" + fi + else + info "Uploading '$file' to '$url'" + set +e + upload "$file" "$url" + set -e + if [ "$delete" = "y" ] && [ $? -eq 0 ]; then + info "Deleting file: $file" + rm -f "$file" + fi fi done done