mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-02 21:42:52 +00:00
Add a poll option to the consumedir script
This was available for docker only via a special entrypoint and is now integrated into the script.
This commit is contained in:
parent
b122d9eab0
commit
d7363b9c8e
@ -22,7 +22,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
|
||||
fi
|
||||
|
||||
OPTIONS=omhdp:vrmi
|
||||
LONGOPTS=once,distinct,help,delete,path:,verbose,recursive,dry,integration,iuser:,iheader:
|
||||
LONGOPTS=once,distinct,help,delete,path:,verbose,recursive,dry,integration,iuser:,iheader:,poll:
|
||||
|
||||
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
||||
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
||||
@ -36,7 +36,7 @@ eval set -- "$PARSED"
|
||||
|
||||
declare -a watchdir
|
||||
help=n verbose=n delete=n once=n distinct=n recursive=n dryrun=n
|
||||
integration=n iuser="" iheader=""
|
||||
integration=n iuser="" iheader="" poll=""
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
@ -84,6 +84,10 @@ while true; do
|
||||
iheader="$2"
|
||||
shift 2
|
||||
;;
|
||||
--poll)
|
||||
poll="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
@ -108,6 +112,8 @@ showUsage() {
|
||||
echo " -h | --help Prints this help text. (value: $help)"
|
||||
echo " -m | --distinct Optional. Upload only if the file doesn't already exist. (value: $distinct)"
|
||||
echo " -o | --once Instead of watching, upload all files in that dir. (value: $once)"
|
||||
echo " --poll <sec> Run the script periodically instead of watching a directory. This can be"
|
||||
echo " used if watching via inotify is not possible."
|
||||
echo " -r | --recursive Traverse the directory(ies) recursively (value: $recursive)"
|
||||
echo " -i | --integration Upload to the integration endpoint. It implies -r. This puts the script in"
|
||||
echo " a different mode, where the first subdirectory of any given starting point"
|
||||
@ -355,11 +361,7 @@ checkSetup() {
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# warn if something seems not correctly configured
|
||||
checkSetup
|
||||
|
||||
if [ "$once" = "y" ]; then
|
||||
runOnce() {
|
||||
info "Uploading all files (except hidden) in '$watchdir'."
|
||||
MD="-maxdepth 1"
|
||||
if [ "$recursive" = "y" ]; then
|
||||
@ -370,20 +372,37 @@ if [ "$once" = "y" ]; then
|
||||
process "$file" "$dir"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# warn if something seems not correctly configured
|
||||
checkSetup
|
||||
|
||||
if [ "$once" = "y" ]; then
|
||||
runOnce
|
||||
else
|
||||
REC=""
|
||||
if [ "$recursive" = "y" ]; then
|
||||
REC="-r"
|
||||
fi
|
||||
$INOTIFY_CMD $REC -m --format '%w%f' -e close_write -e moved_to "${watchdir[@]}" |
|
||||
while read pathfile; do
|
||||
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
|
||||
if [ -z "$poll" ]; then
|
||||
$INOTIFY_CMD $REC -m --format '%w%f' -e close_write -e moved_to "${watchdir[@]}" |
|
||||
while read pathfile; do
|
||||
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
|
||||
else
|
||||
echo "Running in polling mode: ${poll}s"
|
||||
while [ : ]
|
||||
do
|
||||
runOnce
|
||||
sleep $poll
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user