Skip to content

Commit 050cb21

Browse files
committed
Added scanbd2smb
1 parent 3132e02 commit 050cb21

File tree

12 files changed

+206
-0
lines changed

12 files changed

+206
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

scanbd2smb/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog:
2+
## Version 0.1.0
3+
- First release of scandb2smb addon

scanbd2smb/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM debian:trixie-20250908-slim
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
sane \
6+
scanbd \
7+
imagemagick \
8+
exactimage \
9+
pdftk \
10+
tesseract-ocr \
11+
tesseract-ocr-eng \
12+
libusb-dev \
13+
smbclient \
14+
jq \
15+
&& rm -rf /tmp/* /var/{cache,log}/* /var/lib/apt/lists/*
16+
17+
COPY ./scan.sh /scan.sh
18+
RUN chmod +x /scan.sh
19+
20+
RUN sed -i '/action scan {/,/}/s|script = ".*"|script = "/scan.sh"|' /etc/scanbd/scanbd.conf
21+
22+
COPY ./entrypoint.sh /entrypoint.sh
23+
RUN chmod +x /entrypoint.sh
24+
25+
ENTRYPOINT [ "/entrypoint.sh" ]
26+
27+
ARG VERSION
28+
LABEL \
29+
io.hass.name="scanbd2smb" \
30+
io.hass.description="Scan from your USB Scanner to a SMB Folder." \
31+
io.hass.version="${VERSION}" \
32+
io.hass.type="addon" \
33+
io.hass.arch="armhf|aarch64|i386|amd64|armv7" \
34+
maintainer="Nils Stein <[email protected]>" \
35+
org.opencontainers.image.title="scanbd2smb" \
36+
org.opencontainers.image.description="Scan from your USB Scanner to a SMB Folder." \
37+
org.opencontainers.image.vendor="Nils Home Assistant Add-ons" \
38+
org.opencontainers.image.authors="Nils Stein <[email protected]>" \
39+
org.opencontainers.image.licenses="MIT" \
40+
org.opencontainers.image.source="https://github.com/mietzen/hassio-addons" \
41+
org.opencontainers.image.documentation="https://github.com/mietzen/hassio-addons/blob/main/p910nd/README.md"

scanbd2smb/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **Status: Untested Beta ×**
2+
3+
# Home Assistant Add-on: scanbd2smb
4+
5+
Enables you to scan from your USB scanner directly to a SMB share.
6+
7+
## About
8+
9+
This add-on uses **scanbd** to listen for scanner button presses and automatically scans documents.
10+
Scans are processed with **OCR (Tesseract)** and stored as compressed searchable PDFs on your SMB share.
11+
12+
## Installation
13+
14+
1. Navigate in your Home Assistant frontend to **Settings** -> **Add-ons** -> **Add-on Store** and add this URL as an additional repository: `https://github.com/mietzen/hassio-addons`
15+
2. Refresh your browser.
16+
3. Find the "scanbd2smb" add-on and click the "INSTALL" button.
17+
4. Configure the add-on and click on "START".

scanbd2smb/config.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: scanbd2smb
2+
version: 0.1.0
3+
slug: scanbd2smb
4+
description: Enables you to scan from your USB Scanner to a SMB Folder.
5+
url: https://github.com/mietzen/hassio-addons/tree/master/scanbd
6+
arch:
7+
- armhf
8+
- armv7
9+
- aarch64
10+
- amd64
11+
- i386
12+
startup: application
13+
boot: auto
14+
homeassistant_api: false
15+
hassio_api: false
16+
hassio_role: manager
17+
stdin: true
18+
image: mietzen/hass-addon-scanbd2smb
19+
init: false
20+
usb: true
21+
22+
options:
23+
smb_share: ""
24+
smb_user: ""
25+
smb_password: ""
26+
ocr_language: "eng"
27+
scan_resolution: 300
28+
scan_mode: "Color"
29+
30+
schema:
31+
smb_share: str
32+
smb_user: str
33+
smb_password: str
34+
ocr_language: str
35+
scan_resolution: int
36+
scan_mode: str
37+
log_level: list(debug|info|warning|error)?

scanbd2smb/entrypoint.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Read options.json into env vars
5+
export SMB_SHARE=$(jq -r '.smb_share' /data/options.json)
6+
export SMB_USER=$(jq -r '.smb_user' /data/options.json)
7+
export SMB_PASSWORD=$(jq -r '.smb_password' /data/options.json)
8+
export OCR_LANGUAGE=$(jq -r '.ocr_language' /data/options.json)
9+
export SCAN_RESOLUTION=$(jq -r '.scan_resolution' /data/options.json)
10+
export SCAN_MODE=$(jq -r '.scan_mode' /data/options.json)
11+
12+
if ! dpkg -l | grep -q "tesseract-ocr-${OCR_LANGUAGE}"; then
13+
echo "OCR Language: $OCR_LANGUAGE not installed! Installing:"
14+
apt-get update
15+
apt-get install --yes "tesseract-ocr-${OCR_LANGUAGE}"
16+
fi
17+
18+
echo "ScanBD starting with:"
19+
echo " SMB_SHARE=$SMB_SHARE"
20+
echo " SMB_USER=$SMB_USER"
21+
echo " OCR_LANGUAGE=$OCR_LANGUAGE"
22+
echo " SCAN_RESOLUTION=$SCAN_RESOLUTION"
23+
echo " SCAN_MODE=$SCAN_MODE"
24+
25+
exec /usr/sbin/scanbd -f

scanbd2smb/icon.png

25.7 KB
Loading

scanbd2smb/scan.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
TMP_DIR=$(mktemp -d)
5+
FILE_NAME="scan_$(date +%Y-%m-%d-%H%M%S)"
6+
7+
echo 'Scanning...'
8+
scanimage --resolution "$SCAN_RESOLUTION" \
9+
--batch="$TMP_DIR/scan_%03d.pnm" \
10+
--format=pnm \
11+
--mode "$SCAN_MODE" \
12+
--source "ADF Front"
13+
14+
echo "Output saved in $TMP_DIR/scan*.pnm"
15+
cd "$TMP_DIR"
16+
17+
# Convert to TIFF
18+
for i in scan_*.pnm; do
19+
echo "Converting $i"
20+
convert "$i" "$i.tif"
21+
done
22+
23+
# OCR
24+
echo 'Performing OCR...'
25+
for i in scan_*.tif; do
26+
echo "Processing $i"
27+
tesseract "$i" "$i" -l "$OCR_LANGUAGE" hocr
28+
hocr2pdf -i "$i" -s -o "$i.pdf" < "$i.hocr"
29+
done
30+
31+
# Merge PDFs
32+
echo 'Merging PDFs...'
33+
pdftk *.tif.pdf cat output compiled.pdf
34+
35+
# Compress final PDF
36+
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
37+
-dNOPAUSE -dQUIET -dBATCH \
38+
-sOutputFile="$FILE_NAME.pdf" compiled.pdf
39+
40+
# Upload via Samba
41+
smbclient "$SMB_SHARE" -U "$SMB_USER"%"$SMB_PASSWORD" -c "put $FILE_NAME.pdf"
42+
43+
# Cleanup
44+
rm -rf "$TMP_DIR"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title "scandb2smb Integration Test"
2+
3+
describe processes(Regexp.new("scandb")) do
4+
it { should exist }
5+
its('users') { should include 'root' }
6+
its('pids') { should cmp "1"}
7+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
lockfile_version: 1
3+
depends: []

0 commit comments

Comments
 (0)