Skip to content

Instantly share code, notes, and snippets.

@bzed
Created May 11, 2022 20:07
Show Gist options
  • Save bzed/acb827d2bc7ca01be1df4558e6d1f41c to your computer and use it in GitHub Desktop.
Save bzed/acb827d2bc7ca01be1df4558e6d1f41c to your computer and use it in GitHub Desktop.
HP scanner to Paperless CLI
#!/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