docspell/tools/convert-pdf/convert-all-pdfs.sh

33 lines
866 B
Bash
Raw Normal View History

2020-08-13 20:08:15 +00:00
#!/usr/bin/env bash
#
# Simple script to authenticate with docspell and trigger the "convert
# all pdf" route that submits a task to convert all pdf files using
# ocrmypdf.
set -e
2021-01-22 21:32:02 +00:00
CURL_CMD="curl"
JQ_CMD="jq"
2020-08-13 20:08:15 +00:00
BASE_URL="${1:-http://localhost:7880}"
LOGIN_URL="$BASE_URL/api/v1/open/auth/login"
TRIGGER_URL="$BASE_URL/api/v1/sec/item/convertallpdfs"
echo "Login to trigger converting all pdfs."
echo "Using url: $BASE_URL"
echo -n "Account: "
read USER
echo -n "Password: "
read -s PASS
echo
2021-01-22 21:32:02 +00:00
auth=$("$CURL_CMD" --fail -XPOST --silent --data-binary "{\"account\":\"$USER\", \"password\":\"$PASS\"}" "$LOGIN_URL")
2020-08-13 20:08:15 +00:00
2021-01-22 21:32:02 +00:00
if [ "$(echo $auth | "$JQ_CMD" .success)" == "true" ]; then
2020-08-13 20:08:15 +00:00
echo "Login successful"
2021-01-22 21:32:02 +00:00
auth_token=$(echo $auth | "$JQ_CMD" -r .token)
"$CURL_CMD" --fail -XPOST -H "X-Docspell-Auth: $auth_token" "$TRIGGER_URL"
2020-08-13 20:08:15 +00:00
else
echo "Login failed."
fi