From ef1a12e02fbef9f8c6b3ad1f21081fb44a1fca13 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Thu, 14 Nov 2024 09:40:12 +0100 Subject: [PATCH] added initial paperless.sh --- paperless.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 paperless.sh diff --git a/paperless.sh b/paperless.sh new file mode 100755 index 0000000..4de9247 --- /dev/null +++ b/paperless.sh @@ -0,0 +1,21 @@ +#! /bin/sh +# SPDX-FileCopyrightText: 2024 Tobias Schmidl +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +[ ! -r "./.env" ] && { echo "env file not readable, please make sure a .env is present." >&2; exit 1; } +. "./.env" +[ -z "$TOKEN" ] && { echo "Parameter TOKEN is not present in env file, please fill it with a valid paperless API token." >&2; exit 1; } +[ -z "$BASE_URL" ] && { echo "Parameter BASE_URL is not present in env file, please fill it with the URL of your paperless server." >&2; exit 1; } + +AUTH_PARM="Authorization: Token $TOKEN" + +case "$1" in + get_tasks) + curl -H "$AUTH_PARM" "${BASE_URL}/api/tasks/" + ;; + put_document) + [ ! -r "$2" ] && { echo "file not readable." >&2; exit 1; } + curl -H "$AUTH_PARM" -X "POST" "${BASE_URL}/api/documents/post_document/" -H 'Accept: application/json' --form "document=@${2}" + ;; +esac