extracted load_env into a function
This commit is contained in:
parent
ef1a12e02f
commit
7c8acd5a27
1 changed files with 15 additions and 11 deletions
4
paperless.sh
Executable file → Normal file
4
paperless.sh
Executable file → Normal file
|
@ -3,18 +3,22 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
load_env () {
|
||||||
[ ! -r "./.env" ] && { echo "env file not readable, please make sure a .env is present." >&2; exit 1; }
|
[ ! -r "./.env" ] && { echo "env file not readable, please make sure a .env is present." >&2; exit 1; }
|
||||||
. "./.env"
|
. "./.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 "$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; }
|
[ -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"
|
AUTH_PARM="Authorization: Token $TOKEN"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
get_tasks)
|
get_tasks)
|
||||||
|
load_env
|
||||||
curl -H "$AUTH_PARM" "${BASE_URL}/api/tasks/"
|
curl -H "$AUTH_PARM" "${BASE_URL}/api/tasks/"
|
||||||
;;
|
;;
|
||||||
put_document)
|
put_document)
|
||||||
|
load_env
|
||||||
[ ! -r "$2" ] && { echo "file not readable." >&2; exit 1; }
|
[ ! -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}"
|
curl -H "$AUTH_PARM" -X "POST" "${BASE_URL}/api/documents/post_document/" -H 'Accept: application/json' --form "document=@${2}"
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue