From bebe0dabde4e9240e59664cace3e9f4d3255f780 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 27 Jan 2021 21:13:16 +0100 Subject: [PATCH] Add consumedir-entrypoint.sh to allow polling consumedir --- docker/consumedir.dockerfile | 2 +- tools/consumedir/consumedir-entrypoint.sh | 60 +++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tools/consumedir/consumedir-entrypoint.sh diff --git a/docker/consumedir.dockerfile b/docker/consumedir.dockerfile index 39079ced..12230683 100644 --- a/docker/consumedir.dockerfile +++ b/docker/consumedir.dockerfile @@ -13,7 +13,7 @@ RUN apk add --no-cache curl bash inotify-tools COPY --from=docspell-base-binaries /opt/docspell-tools /opt/docspell-tools -ENTRYPOINT /opt/docspell-tools/consumedir/consumedir.sh --path /opt/docs -i --iheader Docspell-Integration:$DOCSPELL_HEADER_VALUE -m http://docspell-restserver:7880/api/v1/open/integration/item -v +ENTRYPOINT ["/opt/docspell-tools/consumedir/consumedir-entrypoint.sh"] HEALTHCHECK --interval=1m --timeout=10s --retries=2 --start-period=10s \ CMD pgrep inotifywait diff --git a/tools/consumedir/consumedir-entrypoint.sh b/tools/consumedir/consumedir-entrypoint.sh new file mode 100644 index 00000000..575e7d11 --- /dev/null +++ b/tools/consumedir/consumedir-entrypoint.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +# This script watches a directory for new files and uploads them to +# docspell. Or it uploads all files currently in the directory. +# +# It requires inotifywait, curl and sha256sum if the `-m' option is +# used. + +# saner programming env: these switches turn some bugs into errors +set -o errexit -o pipefail -o noclobber -o nounset + +CONSUMEDIR_SCRIPT=${CONSUMEDIR_SCRIPT-${0/-entrypoint/}} +CONSUMEDIR_PATH="${CONSUMEDIR_PATH-/opt/docs}" +CONSUMEDIR_POLLING_INTERVAL=${CONSUMEDIR_POLLING_INTERVAL-60} +DOCSPELL_HEADER_VALUE=${DOCSPELL_HEADER_VALUE-none} +CONSUMEDIR_ARGS=${CONSUMEDIR_ARGS-} + +if [ -z "${CONSUMEDIR_ARGS}" ]; then + CONSUMEDIR_ARGS="--path $CONSUMEDIR_PATH --iheader Docspell-Integration:$DOCSPELL_HEADER_VALUE" + + if [ "${CONSUMEDIR_INTEGRATION-n}" = "y" ]; then + CONSUMEDIR_ARGS="$CONSUMEDIR_ARGS -i" + fi + + if [ -z "${CONSUMEDIR_ENDPOINT-}" ]; then + if [ "${CONSUMEDIR_INTEGRATION-n}" = "y" ]; then + CONSUMEDIR_ENDPOINT="http://docspell-restserver:7880/api/v1/open/integration/item" + echo "Using default CONSUMEDIR_ENDPOINT=$CONSUMEDIR_ENDPOINT" + else + echo "Please specify CONSUMEDIR_ENDPOINT" + exit 1 + fi + fi + + if [ "${CONSUMEDIR_VERBOSE-n}" = "y" ]; then + CONSUMEDIR_ARGS="$CONSUMEDIR_ARGS -v" + fi + + if [ "${CONSUMEDIR_UNIQUE-n}" = "y" ]; then + CONSUMEDIR_ARGS="$CONSUMEDIR_ARGS -m" + fi + + if [ "${CONSUMEDIR_POLLING-n}" = "y" ] || [ "${CONSUMEDIR_ONCE-n}" = "y" ]; then + CONSUMEDIR_ARGS="$CONSUMEDIR_ARGS --once" + fi + + CONSUMEDIR_ARGS="$CONSUMEDIR_ARGS $CONSUMEDIR_ENDPOINT" +fi + +if [ "${CONSUMEDIR_POLLING-n}" = "y" ]; then + echo "Running in polling mode" + while [ : ] + do + $CONSUMEDIR_SCRIPT $CONSUMEDIR_ARGS + sleep $CONSUMEDIR_POLLING_INTERVAL + done +else + echo "Running in inotifywait mode" + $CONSUMEDIR_SCRIPT $CONSUMEDIR_ARGS +fi