Created
May 11, 2022 20:07
-
-
Save bzed/acb827d2bc7ca01be1df4558e6d1f41c to your computer and use it in GitHub Desktop.
HP scanner to Paperless CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
USER="username" | |
PAPERLESS_HOST="paperless.your.domain" | |
PASS="$(pass ${PAPERLESS_HOST}/${USER})" | |
URL="https://${PAPERLESS_HOST}/api/documents/post_document/" | |
API="Accept: application/json; version=2" | |
TMP="$(mktemp scan_XXXXXXXXXX.pdf)" | |
trap "{ rm -f "${TMP}" ; exit 1; }" SIGINT SIGTERM ERR | |
if [ $# -gt 0 ]; then | |
TITLE="${*}" | |
else | |
TITLE="scan $(date --rfc-3339=seconds)" | |
fi | |
hp-scan --adf --size=a4 -mcolor -o "${TMP}" | |
curl --user "${USER}:${PASS}" "${URL}" -H "${API}" -X POST \ | |
-F "document=@${TMP}" \ | |
-F "title=${TITLE}" | |
rm -f "${TMP}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment