diff --git a/bundles/scansnap/files/ocr.sh b/bundles/scansnap/files/ocr.sh new file mode 100644 index 0000000..04e98f9 --- /dev/null +++ b/bundles/scansnap/files/ocr.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail + +DATE=$(date +%F_%H-%M-%S) + +cd "$1" + +convert *.tiff no_ocr.pdf +ocrmypdf -l deu no_ocr.pdf has_ocr.pdf + +rm -f *.tiff +rm -f no_ocr.pdf + +chown nobody:nogroup has_ocr.pdf + +mv has_ocr.pdf "/srv/scansnap/${DATE}.pdf" + +cd / + +rm -r "$1" diff --git a/bundles/scansnap/files/scan.sh b/bundles/scansnap/files/scan.sh index 7b86a41..5e7a145 100644 --- a/bundles/scansnap/files/scan.sh +++ b/bundles/scansnap/files/scan.sh @@ -2,17 +2,8 @@ set -euo pipefail -DATE=$(date +%F_%H-%M-%S) -OUTFILE="/tmp/${DATE}" +OUTFILE=$(mktemp -d) -scanimage --source 'ADF Duplex' --format tiff --mode Gray --resolution 300 --page-width 210 --page-height 297.3 -x 210 -y 297.3 --batch=${OUTFILE}_p%04d.tiff +scanimage --source 'ADF Duplex' --format tiff --mode Gray --resolution 300 --page-width 210 --page-height 297.3 -x 210 -y 297.3 --batch=${OUTFILE}/p%04d.tiff -convert ${OUTFILE}_*.tiff ${OUTFILE}.pdf -ocrmypdf -l deu ${OUTFILE}.pdf ${OUTFILE}.OCR.pdf - -rm -f ${OUTFILE}_*.tiff -rm -f ${OUTFILE}.pdf - -chown nobody:nogroup "${OUTFILE}.OCR.pdf" - -mv "${OUTFILE}.OCR.pdf" "/srv/scansnap/${DATE}.pdf" +/etc/scanbd/scripts/ocr.sh "$OUTFILE" & diff --git a/bundles/scansnap/files/scanbd.conf b/bundles/scansnap/files/scanbd.conf index 3e21237..f425338 100644 --- a/bundles/scansnap/files/scanbd.conf +++ b/bundles/scansnap/files/scanbd.conf @@ -35,8 +35,8 @@ global { action scan { filter = "^scan.*" numerical-trigger { - from-value = 1 - to-value = 0 + from-value = 0 + to-value = 1 } desc = "Scan to file" script = "scan.sh" diff --git a/bundles/scansnap/items.py b/bundles/scansnap/items.py index d4b55ea..97bdf55 100644 --- a/bundles/scansnap/items.py +++ b/bundles/scansnap/items.py @@ -19,10 +19,17 @@ files = { 'svc_systemd:scanbd:restart', }, }, + '/etc/scanbd/scripts/ocr.sh': { + 'mode': '0755', + 'needs': { + 'directory:/srv/scansnap', + }, + }, '/etc/scanbd/scripts/scan.sh': { 'mode': '0755', 'needs': { 'directory:/srv/scansnap', + 'file:/etc/scanbd/scripts/ocr.sh', }, }, }