mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-02 21:42:52 +00:00
Extend tools/ds.sh
to check for file existence
This commit is contained in:
parent
902fd63125
commit
1bb464b9ed
@ -9,7 +9,8 @@ title: Features and Limitations
|
|||||||
- Multiple users per account
|
- Multiple users per account
|
||||||
- Handle multiple documents as one unit
|
- Handle multiple documents as one unit
|
||||||
- OCR using [tesseract](https://github.com/tesseract-ocr/tesseract)
|
- 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
|
- Text is analysed to find and attach meta data automatically
|
||||||
- Manage document processing (cancel jobs, set priorities)
|
- Manage document processing (cancel jobs, set priorities)
|
||||||
- Everything available via a documented [REST Api](api)
|
- Everything available via a documented [REST Api](api)
|
||||||
|
38
tools/ds.sh
38
tools/ds.sh
@ -15,6 +15,9 @@
|
|||||||
# url.2=...
|
# url.2=...
|
||||||
#
|
#
|
||||||
# Lines starting with a `#' are ignored.
|
# 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
|
# saner programming env: these switches turn some bugs into errors
|
||||||
set -o errexit -o pipefail -o noclobber -o nounset
|
set -o errexit -o pipefail -o noclobber -o nounset
|
||||||
@ -30,8 +33,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OPTIONS=c:hsd
|
OPTIONS=c:hsde
|
||||||
LONGOPTS=config:,help,skip,delete
|
LONGOPTS=config:,help,skip,delete,exists
|
||||||
|
|
||||||
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
||||||
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
||||||
@ -43,7 +46,7 @@ fi
|
|||||||
# read getopt’s output this way to handle the quoting right:
|
# read getopt’s output this way to handle the quoting right:
|
||||||
eval set -- "$PARSED"
|
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
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
@ -58,6 +61,10 @@ while true; do
|
|||||||
delete="y"
|
delete="y"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-e|--exists)
|
||||||
|
exists=y
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
@ -121,9 +128,10 @@ showUsage() {
|
|||||||
info " -c | --config Provide a config file. (value: $config)"
|
info " -c | --config Provide a config file. (value: $config)"
|
||||||
info " -d | --delete Delete the files when successfully uploaded (value: $delete)"
|
info " -d | --delete Delete the files when successfully uploaded (value: $delete)"
|
||||||
info " -h | --help Prints this help text. (value: $help)"
|
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 ""
|
||||||
info "Arguments:"
|
info "Arguments:"
|
||||||
info " One or more PDF files to upload."
|
info " One or more files to check for existence or upload."
|
||||||
info ""
|
info ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,13 +161,21 @@ done <<< $($GREP_CMD -v '^#.*' "$config")
|
|||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for file in $*; do
|
for file in $*; do
|
||||||
for url in "${urls[@]}"; do
|
for url in "${urls[@]}"; do
|
||||||
info "Uploading '$file' to '$url'"
|
if [ "$exists" = "y" ]; then
|
||||||
set +e
|
if checkFile "$url" "$file"; then
|
||||||
upload "$file" "$url"
|
info "$url $file: true"
|
||||||
set -e
|
else
|
||||||
if [ "$delete" = "y" ] && [ $? -eq 0 ]; then
|
info "$url $file: false"
|
||||||
info "Deleting file: $file"
|
fi
|
||||||
rm -f "$file"
|
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
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user