#!/bin/bash
-main()
+errlog()
+{
+ local lastexit=$?
+ local msg="$1"
+
+ echo "â ERROR: $msg"
+ echo "đ EXIT $lastexit"
+ return $lastexit
+}
+
+build_package()
{
local VERSION="1.0.7"
local BUILDVERSION="1"
local ARCHITECTURE="amd64"
local PACKAGENAME="scantopdf-$VERSION-$BUILDVERSION-$ARCHITECTURE"
+ local EXECUTABLES="scantopdf \
+ scantopdfgray \
+ scantopdfbw \
+ generate-trennblatt"
+
+ echo "âšī¸ INFO: build package $PACKAGENAME"
- echo "â START: build-package"
mkdir -p build
mkdir -p build/$PACKAGENAME/usr/local/bin
- cp scantopdf build/$PACKAGENAME/usr/local/bin/scantopdf
- sed -i '/@scanbasic.sh@/r scanbasic.sh' build/$PACKAGENAME/usr/local/bin/scantopdf
- sed -i '/@scanbasic.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdf
- sed -i '/@errlog.sh@/r errlog.sh' build/$PACKAGENAME/usr/local/bin/scantopdf
- sed -i '/@errlog.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdf
-
- cp scantopdfgray build/$PACKAGENAME/usr/local/bin/scantopdfgray
- sed -i '/@scanbasic.sh@/r scanbasic.sh' build/$PACKAGENAME/usr/local/bin/scantopdfgray
- sed -i '/@scanbasic.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdfgray
- sed -i '/@errlog.sh@/r errlog.sh' build/$PACKAGENAME/usr/local/bin/scantopdfgray
- sed -i '/@errlog.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdfgray
-
- cp scantopdfbw build/$PACKAGENAME/usr/local/bin/scantopdfbw
- sed -i '/@scanbasic.sh@/r scanbasic.sh' build/$PACKAGENAME/usr/local/bin/scantopdfbw
- sed -i '/@scanbasic.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdfbw
- sed -i '/@errlog.sh@/r errlog.sh' build/$PACKAGENAME/usr/local/bin/scantopdfbw
- sed -i '/@errlog.sh@/d' build/$PACKAGENAME/usr/local/bin/scantopdfbw
- cp generate-trennblatt build/$PACKAGENAME/usr/local/bin/generate-trennblatt
+ local executable=
+ for executable in $EXECUTABLES; do
+ cp src/$executable build/$PACKAGENAME/usr/local/bin/$executable
+ sed -i "/@scanbasic.sh@/r src/scanbasic.sh" \
+ build/$PACKAGENAME/usr/local/bin/$executable
+ sed -i "/@scanbasic.sh@/d" \
+ build/$PACKAGENAME/usr/local/bin/$executable
+ done
mkdir -p build/$PACKAGENAME/DEBIAN
- cp control build/$PACKAGENAME/DEBIAN/control
+ cp src/control build/$PACKAGENAME/DEBIAN/control
sed -i "s/\$VERSION/$VERSION/" build/$PACKAGENAME/DEBIAN/control
cd build
-
dpkg --build $PACKAGENAME
+}
+
+run_tests()
+{
+ echo "âšī¸ INFO: run tests"
+ ./tests/scanbasic.bats
+}
+
+main()
+{
+ echo "â START: build-package"
+
+ [ -n "$SKIP_TESTS" ] \
+ || run_tests \
+ || errlog "tests failed" \
+ || return $?
+ build_package
+
echo "â
SUCCESS: build-package"
}
+++ /dev/null
-Package: scantopdf
-Version: $VERSION
-Architecture: amd64
-Maintainer: Bastian Dehn <hhaalo@arcor.de>
-Depends: sane (>= 1.0.14), qpdf (>= 11.3.0), pdftk (>= 2.02), libtiff-tools (>= 4.5.0), ocrmypdf (>= 14.0.1), tesseract-ocr-deu (>= 4.1.0), zbar-tools (>= 0.23.92), qrencode (>= 4.1.), librsvg2-bin (>= 2.54.7)
-Description: scan to pdf with ocr scripts for sane-kds-s2000w-net
+++ /dev/null
-#!/bin/bash
-
-errlog()
-{
- local lastexit=$?
- local msg="$1"
-
- echo "â ERROR $msg"
- echo "đ EXIT $lastexit"
- return $lastexit
-}
-
-main()
-{
- echo "â START: generate-trennblatt"
-
- command -v qrencode > /dev/null \
- || errlog "command qrencode not found" \
- || return $?
- command -v rsvg-convert > /dev/null \
- || errlog "command rsvg-convert not found" \
- || return $?
-
- echo "Trennblatt" \
- | qrencode --level=H \
- --type=SVG \
- --output=- \
- | rsvg-convert --format=pdf \
- --output=trennblatt-qr.pdf
-
- echo "â
SUCCESS: generate-trennblatt"
-}
-
-main
+++ /dev/null
-#!/usr/bin/bats
-
-tiff2pdf() {
- echo "$tiff2pdf_return"
- return "$tiff2pdf_exit"
-}
-
-ocrmypdf() {
- echo "$ocrmypdf_return"
- return "$ocrmypdf_exit"
-}
-
-qpdf() {
- echo "$qpdf_return"
- return "$qpdf_exit"
-}
-
-mv() {
- echo "$mv_return"
- return "$mv_exit"
-}
-
-rm() {
- echo "$rm_return"
- return "$rm_exit"
-}
-
-pdftk() {
- echo "$pdftk_return"
- return "$pdftk_exit"
-}
-
-zbarimg() {
- echo "$zbarimg_return"
- return "$zbarimg_exit"
-}
-
-scanimage() {
- echo "$scanimage_return"
- return "$scanimage_exit"
-}
-
-setup() {
- load "/usr/lib/bats/bats-assert/load"
- load "/usr/lib/bats/bats-support/load"
-
- source ./scanbasic.sh
-
- export -f qpdf
- qpdf_return=
- qpdf_exit=0
-
- export -f mv
- mv_return=
- mv_exit=0
-
- export -f ocrmypdf
- ocrmypdf_return=
- ocrmypdf_exit=0
-
- export -f tiff2pdf
- tiff2pdf_return=
- tiff2pdf_exit=0
-
- export -f rm
- rm_return=
- rm_exit=0
-
- export -f pdftk
- pdftk_return=
- pdftk_exit=0
-
- export -f zbarimg
- zbarimg_return=
- zbarimg_exit=0
-
- export -f scanimage
- scanimage_return=
- scanimage_exit=0
-}
-
-teardown() {
- export -n qpdf
- export -n mv
- export -n ocrmypdf
- export -n tiff2pdf
- export -n rm
- export -n pdftk
- export -n zbarimg
- export -n scanimage
-}
-
-@test "should failure optimize input parameter is missing" {
- run optimize
-
- assert_failure
- assert_line --index 0 "â ERROR: missing input"
-}
-
-@test "should failure optimize when qpdf failes" {
- qpdf_exit=1
-
- run optimize "testfile"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not linearize testfile"
-}
-
-@test "should failure optimize when mv fails" {
- mv_exit=1
-
- run optimize "testfile"
-
- assert_failure
- assert_line --index 0 \
- "â ERROR: could not rename testfile-out to testfile"
-}
-
-@test "should success optimize" {
- run optimize "testfile"
-
- assert_success
-}
-
-@test "should failure addocr missing input parameter" {
- run addocr
-
- assert_failure
- assert_line --index 0 "â ERROR: missing input"
-}
-
-@test "should failure addocr ocrmypdf fails" {
- ocrmypdf_exit=1
-
- run addocr "testfile"
-
- assert_failure
- assert_line --index 0 "âšī¸ INFO: adding ocr on file testfile..."
- assert_line --index 1 "â ERROR: could not add ocr on testfile"
-}
-
-@test "should success addocr" {
- run addocr "testfile"
-
- assert_success
- assert_line --index 0 "âšī¸ INFO: adding ocr on file testfile..."
-}
-
-@test "should failure createonepdf missing output parameter" {
- run createonepdf
-
- assert_failure
- assert_line --index 0 "â ERROR: missing output"
-}
-
-@test "should failure createonepdf tiff2pdf fails" {
- tiff2pdf_exit=1
-
- run createonepdf "testfile"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not convert tiff to pdf"
-}
-
-@test "should failure createonepdf delete testfile fails" {
- rm_exit=1
-
- run createonepdf "testfile"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not delete scanned*.tiff"
-}
-
-@test "should failure createonepdf pdftk fails" {
- pdftk_exit=1
-
- run createonepdf "testfile"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not convert into single testfile"
-}
-
-@test "should success createonepdf" {
- run createonepdf "testfile"
-
- assert_success
-}
-
-@test "should failure createpdf missing start parameter" {
- run createpdf
-
- assert_failure
- assert_line --index 0 "â ERROR: missing start"
-}
-
-@test "should failure createpdf missing end parameter" {
- run createpdf "1"
-
- assert_failure
- assert_line --index 0 "â ERROR: missing end"
-}
-
-@test "should failure createpdf pdftk fails" {
- pdftk_exit=1
-
- run createpdf "1" "2"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not create pdf"
-}
-
-@test "should failure pdf delete fails" {
- rm_exit=1
-
- run createpdf "1" "2"
-
- assert_failure
- assert_line --index 0 "â ERROR: could not delete scanned001.pdf"
-}
-
-@test "should success createpdf" {
- run createpdf "1" "2"
-
- assert_success
-}
-
-@test "should failure detectsplit missing parameter" {
- run detectsplit
-
- assert_failure
- assert_line --index 0 "â ERROR: missing pdf"
-}
-
-@test "should failure detectsplit zbarimg fails" {
- zbarimg_exit=1
-
- run detectsplit "testfile.pdf"
-
- assert_success
- assert_line --index 0 "false"
-}
-
-@test "should success and false detectsplit zbarimg nothing find" {
- run detectsplit "testfile.pdf"
-
- assert_success
- assert_line --index 0 "false"
-}
-
-@test "should success and true detectsplit zbarimg find trennblatt" {
- zbarimg_return="Trennblatt"
-
- run detectsplit "testfile.pdf"
-
- assert_success
- assert_line --index 0 "true"
-}
-
-@test "should failure createmultipdfs tiff2pdf fails" {
- tiff2pdf_exit=1
-
- run createmultipdfs
-
- assert_failure
- assert_line --index 0 "â ERROR: could not convert scanned*.tiff to scanned*.pdf"
-}
-
-@test "should failure createmultipdfs rm tiff fails" {
- rm_exit=1
-
- run createmultipdfs
-
- assert_failure
- assert_line --index 0 "â ERROR: could not delete scanned*.tiff"
-}
-
-@test "should success createmutlipdfs" {
- run createmultipdfs
-
- assert_success
-}
-
-@test "should failure scantopdf missing mode parameter" {
- run scantopdf
-
- assert_failure
- assert_line --index 0 "â ERROR: missing mode"
-}
-
-@test "should failure scantopdf missing pagecount parameter" {
- run scantopdf "Color"
-
- assert_failure
- assert_line --index 0 "â ERROR: missing pagecount"
-}
-
-@test "should failure scantopdf missing output parameter" {
- run scantopdf "Color" "5"
-
- assert_failure
- assert_line --index 0 "â ERROR: missing output"
-}
-
-@test "should failure scantopdf scanimage fails" {
- scanimage_exit=1
-
- run scantopdf "Color" "1" "test.pdf"
-
- assert_failure
- assert_line --index 0 "â ERROR: scan error"
-}
-
-@test "should success scantopdf" {
- run scantopdf "Color" "1" "test.pdf"
-
- assert_success
-}
+++ /dev/null
-errlog()
-{
- local lastexit=$?
- local msg="$1"
-
- echo "â ERROR: $msg"
- echo "đ EXIT $lastexit"
- return $lastexit
-}
-
-optimize()
-{
- local input="$1"
- local output="$input-out"
-
- command -v qpdf > /dev/null \
- || errlog "command qpdf not found" \
- || return $?
- [ -n "$input" ] \
- || errlog "missing input" \
- || return $?
- qpdf --linearize $input $output \
- || errlog "could not linearize $input" \
- || return $?
- mv $output $input \
- || errlog "could not rename $output to $input" \
- || return $?
-}
-
-addocr()
-{
- local input="$1"
- local output="$input-out"
-
- command -v ocrmypdf > /dev/null \
- || errlog "command ocrmypdf not found" \
- || return $?
- [ -n "$input" ] \
- || errlog "missing input" \
- || return $?
-
- echo "âšī¸ INFO: adding ocr on file $input..."
- ocrmypdf --quiet --language deu $input $output \
- || errlog "could not add ocr on $input" \
- || return $?
-
- [ ! -f $output ] && return 0
-
- mv $output $input \
- || errlog "could not rename $output to $input" \
- || return $?
- optimize $input \
- || return $?
-}
-
-createonepdf()
-{
- local output=$1
-
- command -v tiff2pdf > /dev/null \
- || errlog "command tiff2pdf not found" \
- || return $?
- command -v pdftk > /dev/null \
- || errlog "command pdftk not found" \
- || return $?
- [ -n "$output" ] \
- || errlog "missing output" \
- || return $?
-
- local output_pdf=
- local tiff=
- for tiff in scanned*.tiff; do
- output_pdf=${tiff/.tiff/.pdf}
- tiff2pdf $tiff -o $output_pdf \
- || errlog "could not convert tiff to pdf" \
- || return $?
- rm $tiff \
- || errlog "could not delete $tiff" \
- || return $?
- done
-
- pdftk scanned*.pdf output $output \
- || errlog "could not convert into single $output" \
- || return $?
-
- rm scanned*.pdf \
- || errlog "could not remove scanned pdfs" \
- || return $?
-
- addocr $output \
- || return $?
-}
-
-createpdf()
-{
- local start="$1"
- local end="$2"
- local basename="$3"
- local countno=
- local pdfs=()
- basename=${basename:="out"}
-
- command -v pdftk > /dev/null \
- || errlog "command pdftk not found" \
- || return $?
- [ -n "$start" ] \
- || errlog "missing start" \
- || return $?
- [ -n "$end" ] \
- || errlog "missing end" \
- || return $?
-
- local i=
- for i in $(seq $start $end); do
- countno=$(printf "%03d" $i)
- pdfs=$(echo $pdfs "scanned$countno.pdf")
- done
-
- pdftk $pdfs output "$basename$(printf "%03d" $start).pdf" \
- || errlog "could not create pdf" \
- || return 1
-
- for pdf in $pdfs; do
- rm "$pdf" \
- || errlog "could not delete $pdf" \
- || return 1
- done
-
- addocr "$basename$(printf "%03d" $start).pdf" \
- || return $?
-}
-
-detectsplit()
-{
- local pdf=$1
- local trenn=
-
- command -v zbarimg > /dev/null \
- || errlog "command zbarimg not found" \
- || return $?
- [ -n "$pdf" ] \
- || errlog "missing pdf" \
- || return $?
-
- trenn=$(zbarimg --raw --quiet $pdf)
-
- [ "$trenn" == "Trennblatt" ] \
- && echo "true" \
- && return 0
-
- echo "false"
-}
-
-createmultipdfs()
-{
- local basename="multi"
- local startcount=1
- local endcount=1
-
- command -v tiff2pdf > /dev/null \
- || errlog "command tiff2pdf not found" \
- || return $?
- [ -n "$basename" ] \
- || errlog "missing basename" \
- || return $?
-
- local pdf=
- local tiff=
- for tiff in scanned*.tiff; do
- pdf=${tiff/.tiff/.pdf}
- tiff2pdf $tiff -o $pdf \
- || errlog "could not convert $tiff to $pdf" \
- || return $?
- trenn=$(detectsplit $pdf) \
- || return $?
- rm $tiff \
- || errlog "could not delete $tiff" \
- || return $?
-
- if [ "$trenn" == "true" ]; then
- rm $pdf \
- || errlog "could not delete $pdf" \
- || return $?
- createpdf "$startcount" \
- "$((endcount - 1))" \
- "$basename" \
- || return $?
- startcount=$((endcount + 1))
- fi
-
- ((endcount++))
- done
-}
-
-scantopdf() {
- local mode="$1"
- local pagecount="$2"
- local output="$3"
-
- command -v scanimage > /dev/null \
- || errlog "command scanimage not found" \
- || return $?
- [ -n "$mode" ] \
- || errlog "missing mode" \
- || return $?
- [ -n "$pagecount" ] \
- || errlog "missing pagecount" \
- || return $?
- [ -n "$output" ] \
- || errlog "missing output" \
- || return $?
-
- scanimage --source=DocumentFeeder \
- --mode=$mode \
- --resolution=300 \
- --scanside=Duplex \
- --skip-blank-pages=yes \
- --format=tiff \
- --batch-count=$pagecount \
- --batch-increment=1 \
- --batch=scanned%03d.tiff \
- || errlog "scan error" \
- || return $?
-
- if [ "$output" == "multi" ]; then
- createmultipdfs || return $?
- return
- fi
-
- createonepdf "$output" \
- || return $?
-}
+++ /dev/null
-#!/bin/bash
-
-# @scanbasic.sh@
-
-main()
-{
- local pagecount=$1
- local output=$2
-
- echo "â START: scantopdf"
-
- scantopdf "Color" "$pagecount" "$output" \
- || return $?
-
- echo "â
SUCCESS: scantopdf"
-}
-
-main $*
+++ /dev/null
-#!/bin/bash
-
-@scanbasic.sh@
-
-main()
-{
- local pagecount=$1
- local output=$2
-
- echo "â START: scantopdfbw"
-
- scantopdf "BW" "$pagecount" "$output" \
- || return $?
-
- echo "â
SUCCESS: scantopdfbw"
-}
-
-main $*
+++ /dev/null
-#!/bin/bash
-
-@scanbasic.sh@
-
-main()
-{
- local pagecount=$1
- local output=$2
-
- echo "â START: scantopdfgray"
-
- scantopdf "Gray" "$pagecount" "$output" \
- || return $?
-
- echo "â
SUCCESS: scantopdfgray"
-}
-
-main $*
--- /dev/null
+Package: scantopdf
+Version: $VERSION
+Architecture: amd64
+Maintainer: Bastian Dehn <hhaalo@arcor.de>
+Depends: sane (>= 1.0.14), qpdf (>= 11.3.0), pdftk (>= 2.02), libtiff-tools (>= 4.5.0), ocrmypdf (>= 14.0.1), tesseract-ocr-deu (>= 4.1.0), zbar-tools (>= 0.23.92), qrencode (>= 4.1.), librsvg2-bin (>= 2.54.7)
+Description: scan to pdf with ocr scripts for sane-kds-s2000w-net
--- /dev/null
+#!/bin/bash
+
+errlog()
+{
+ local lastexit=$?
+ local msg="$1"
+
+ echo "â ERROR $msg"
+ echo "đ EXIT $lastexit"
+ return $lastexit
+}
+
+main()
+{
+ echo "â START: generate-trennblatt"
+
+ command -v qrencode > /dev/null \
+ || errlog "command qrencode not found" \
+ || return $?
+ command -v rsvg-convert > /dev/null \
+ || errlog "command rsvg-convert not found" \
+ || return $?
+
+ echo "Trennblatt" \
+ | qrencode --level=H \
+ --type=SVG \
+ --output=- \
+ | rsvg-convert --format=pdf \
+ --output=trennblatt-qr.pdf
+
+ echo "â
SUCCESS: generate-trennblatt"
+}
+
+main
--- /dev/null
+errlog()
+{
+ local lastexit=$?
+ local msg="$1"
+
+ echo "â ERROR: $msg"
+ echo "đ EXIT $lastexit"
+ return $lastexit
+}
+
+optimize()
+{
+ local input="$1"
+ local output="$input-out"
+
+ command -v qpdf > /dev/null \
+ || errlog "command qpdf not found" \
+ || return $?
+ [ -n "$input" ] \
+ || errlog "missing input" \
+ || return $?
+ qpdf --linearize $input $output \
+ || errlog "could not linearize $input" \
+ || return $?
+ mv $output $input \
+ || errlog "could not rename $output to $input" \
+ || return $?
+}
+
+addocr()
+{
+ local input="$1"
+ local output="$input-out"
+
+ command -v ocrmypdf > /dev/null \
+ || errlog "command ocrmypdf not found" \
+ || return $?
+ [ -n "$input" ] \
+ || errlog "missing input" \
+ || return $?
+
+ echo "âšī¸ INFO: adding ocr on file $input"
+ ocrmypdf --quiet --language deu $input $output \
+ || errlog "could not add ocr on $input" \
+ || return $?
+
+ [ ! -f $output ] && return 0
+
+ mv $output $input \
+ || errlog "could not rename $output to $input" \
+ || return $?
+ optimize $input \
+ || return $?
+}
+
+createonepdf()
+{
+ local output=$1
+
+ command -v tiff2pdf > /dev/null \
+ || errlog "command tiff2pdf not found" \
+ || return $?
+ command -v pdftk > /dev/null \
+ || errlog "command pdftk not found" \
+ || return $?
+ [ -n "$output" ] \
+ || errlog "missing output" \
+ || return $?
+
+ local output_pdf=
+ local tiff=
+ for tiff in scanned*.tiff; do
+ output_pdf=${tiff/.tiff/.pdf}
+ tiff2pdf $tiff -o $output_pdf \
+ || errlog "could not convert tiff to pdf" \
+ || return $?
+ rm $tiff \
+ || errlog "could not delete $tiff" \
+ || return $?
+ done
+
+ pdftk scanned*.pdf output $output \
+ || errlog "could not convert into single $output" \
+ || return $?
+
+ rm scanned*.pdf \
+ || errlog "could not remove scanned pdfs" \
+ || return $?
+
+ addocr $output \
+ || return $?
+}
+
+createpdf()
+{
+ local start="$1"
+ local end="$2"
+ local basename="$3"
+ local countno=
+ local pdfs=()
+ basename=${basename:="out"}
+
+ command -v pdftk > /dev/null \
+ || errlog "command pdftk not found" \
+ || return $?
+ [ -n "$start" ] \
+ || errlog "missing start" \
+ || return $?
+ [ -n "$end" ] \
+ || errlog "missing end" \
+ || return $?
+
+ local i=
+ for i in $(seq $start $end); do
+ countno=$(printf "%03d" $i)
+ pdfs=$(echo $pdfs "scanned$countno.pdf")
+ done
+
+ pdftk $pdfs output "$basename$(printf "%03d" $start).pdf" \
+ || errlog "could not create pdf" \
+ || return 1
+
+ for pdf in $pdfs; do
+ rm "$pdf" \
+ || errlog "could not delete $pdf" \
+ || return 1
+ done
+
+ addocr "$basename$(printf "%03d" $start).pdf" \
+ || return $?
+}
+
+detectsplit()
+{
+ local pdf=$1
+ local trenn=
+
+ command -v zbarimg > /dev/null \
+ || errlog "command zbarimg not found" \
+ || return $?
+ [ -n "$pdf" ] \
+ || errlog "missing pdf" \
+ || return $?
+
+ trenn=$(zbarimg --raw --quiet $pdf)
+
+ [ "$trenn" == "Trennblatt" ] \
+ && echo "true" \
+ && return 0
+
+ echo "false"
+}
+
+createmultipdfs()
+{
+ local basename="multi"
+ local startcount=1
+ local endcount=1
+
+ command -v tiff2pdf > /dev/null \
+ || errlog "command tiff2pdf not found" \
+ || return $?
+ [ -n "$basename" ] \
+ || errlog "missing basename" \
+ || return $?
+
+ local pdf=
+ local tiff=
+ for tiff in scanned*.tiff; do
+ pdf=${tiff/.tiff/.pdf}
+ tiff2pdf $tiff -o $pdf \
+ || errlog "could not convert $tiff to $pdf" \
+ || return $?
+ trenn=$(detectsplit $pdf) \
+ || return $?
+ rm $tiff \
+ || errlog "could not delete $tiff" \
+ || return $?
+
+ if [ "$trenn" == "true" ]; then
+ rm $pdf \
+ || errlog "could not delete $pdf" \
+ || return $?
+ createpdf "$startcount" \
+ "$((endcount - 1))" \
+ "$basename" \
+ || return $?
+ startcount=$((endcount + 1))
+ fi
+
+ ((endcount++))
+ done
+}
+
+scantopdf() {
+ local mode="$1"
+ local pagecount="$2"
+ local output="$3"
+
+ command -v scanimage > /dev/null \
+ || errlog "command scanimage not found" \
+ || return $?
+ [ -n "$mode" ] \
+ || errlog "missing mode" \
+ || return $?
+ [ -n "$pagecount" ] \
+ || errlog "missing pagecount" \
+ || return $?
+ [ -n "$output" ] \
+ || errlog "missing output" \
+ || return $?
+
+ scanimage --source=DocumentFeeder \
+ --mode=$mode \
+ --resolution=300 \
+ --scanside=Duplex \
+ --skip-blank-pages=yes \
+ --format=tiff \
+ --batch-count=$pagecount \
+ --batch-increment=1 \
+ --batch=scanned%03d.tiff \
+ || errlog "scan error" \
+ || return $?
+
+ if [ "$output" == "multi" ]; then
+ createmultipdfs || return $?
+ return
+ fi
+
+ createonepdf "$output" \
+ || return $?
+}
--- /dev/null
+#!/bin/bash
+
+# @scanbasic.sh@
+
+main()
+{
+ local pagecount=$1
+ local output=$2
+
+ echo "â START: scantopdf"
+
+ scantopdf "Color" "$pagecount" "$output" \
+ || return $?
+
+ echo "â
SUCCESS: scantopdf"
+}
+
+main $*
--- /dev/null
+#!/bin/bash
+
+@scanbasic.sh@
+
+main()
+{
+ local pagecount=$1
+ local output=$2
+
+ echo "â START: scantopdfbw"
+
+ scantopdf "BW" "$pagecount" "$output" \
+ || return $?
+
+ echo "â
SUCCESS: scantopdfbw"
+}
+
+main $*
--- /dev/null
+#!/bin/bash
+
+@scanbasic.sh@
+
+main()
+{
+ local pagecount=$1
+ local output=$2
+
+ echo "â START: scantopdfgray"
+
+ scantopdf "Gray" "$pagecount" "$output" \
+ || return $?
+
+ echo "â
SUCCESS: scantopdfgray"
+}
+
+main $*
--- /dev/null
+#!/usr/bin/bats
+
+tiff2pdf() {
+ printf "$tiff2pdf_return"
+ return "$tiff2pdf_exit"
+}
+
+ocrmypdf() {
+ printf "$ocrmypdf_return"
+ return "$ocrmypdf_exit"
+}
+
+qpdf() {
+ printf "$qpdf_return"
+ return "$qpdf_exit"
+}
+
+mv() {
+ printf "$mv_return"
+ return "$mv_exit"
+}
+
+rm() {
+ printf "$rm_return"
+ return "$rm_exit"
+}
+
+pdftk() {
+ printf "$pdftk_return"
+ return "$pdftk_exit"
+}
+
+zbarimg() {
+ printf "$zbarimg_return"
+ return "$zbarimg_exit"
+}
+
+scanimage() {
+ printf "$scanimage_return"
+ return "$scanimage_exit"
+}
+
+setup() {
+ load "/usr/lib/bats/bats-assert/load"
+ load "/usr/lib/bats/bats-support/load"
+
+ source ./src/scanbasic.sh
+
+ export -f qpdf
+ qpdf_return=
+ qpdf_exit=0
+
+ export -f mv
+ mv_return=
+ mv_exit=0
+
+ export -f ocrmypdf
+ ocrmypdf_return=
+ ocrmypdf_exit=0
+
+ export -f tiff2pdf
+ tiff2pdf_return=
+ tiff2pdf_exit=0
+
+ export -f rm
+ rm_return=
+ rm_exit=0
+
+ export -f pdftk
+ pdftk_return=
+ pdftk_exit=0
+
+ export -f zbarimg
+ zbarimg_return=
+ zbarimg_exit=0
+
+ export -f scanimage
+ scanimage_return=
+ scanimage_exit=0
+}
+
+teardown() {
+ export -n qpdf
+ export -n mv
+ export -n ocrmypdf
+ export -n tiff2pdf
+ export -n rm
+ export -n pdftk
+ export -n zbarimg
+ export -n scanimage
+}
+
+@test "should failure optimize input parameter is missing" {
+ run optimize
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing input"
+}
+
+@test "should failure optimize when qpdf failes" {
+ qpdf_exit=1
+
+ run optimize "testfile"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: could not linearize testfile"
+}
+
+@test "should failure optimize when mv fails" {
+ mv_exit=1
+
+ run optimize "testfile"
+
+ assert_failure
+ assert_line --index 0 \
+ "â ERROR: could not rename testfile-out to testfile"
+}
+
+@test "should success optimize" {
+ run optimize "testfile"
+
+ assert_success
+}
+
+@test "should failure addocr missing input parameter" {
+ run addocr
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing input"
+}
+
+@test "should failure addocr ocrmypdf fails" {
+ ocrmypdf_exit=1
+
+ run addocr "testfile"
+
+ assert_failure
+ assert_line --index 0 "âšī¸ INFO: adding ocr on file testfile"
+ assert_line --index 1 "â ERROR: could not add ocr on testfile"
+}
+
+@test "should success addocr" {
+ run addocr "testfile"
+
+ assert_success
+ assert_line --index 0 "âšī¸ INFO: adding ocr on file testfile"
+}
+
+@test "should failure createonepdf missing output parameter" {
+ run createonepdf
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing output"
+}
+
+@test "should failure createonepdf tiff2pdf fails" {
+ tiff2pdf_exit=1
+
+ run createonepdf "testfile"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: could not convert tiff to pdf"
+}
+
+@test "should failure createonepdf pdftk fails" {
+ pdftk_exit=1
+
+ run createonepdf "testfile"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: could not convert into single testfile"
+}
+
+@test "should success createonepdf" {
+ run createonepdf "testfile"
+
+ assert_success
+}
+
+@test "should failure createpdf missing start parameter" {
+ run createpdf
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing start"
+}
+
+@test "should failure createpdf missing end parameter" {
+ run createpdf "1"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing end"
+}
+
+@test "should failure createpdf pdftk fails" {
+ pdftk_exit=1
+
+ run createpdf "1" "2"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: could not create pdf"
+}
+
+@test "should success createpdf" {
+ run createpdf "1" "2"
+
+ assert_success
+}
+
+@test "should failure detectsplit missing parameter" {
+ run detectsplit
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing pdf"
+}
+
+@test "should failure detectsplit zbarimg fails" {
+ zbarimg_exit=1
+
+ run detectsplit "testfile.pdf"
+
+ assert_success
+ assert_line --index 0 "false"
+}
+
+@test "should success and false detectsplit zbarimg nothing find" {
+ run detectsplit "testfile.pdf"
+
+ assert_success
+ assert_line --index 0 "false"
+}
+
+@test "should success and true detectsplit zbarimg find trennblatt" {
+ zbarimg_return="Trennblatt"
+
+ run detectsplit "testfile.pdf"
+
+ assert_success
+ assert_line --index 0 "true"
+}
+
+@test "should failure createmultipdfs tiff2pdf fails" {
+ tiff2pdf_exit=1
+
+ run createmultipdfs
+
+ assert_failure
+ assert_line --index 0 "â ERROR: could not convert scanned*.tiff to scanned*.pdf"
+}
+
+@test "should success createmutlipdfs" {
+ run createmultipdfs
+
+ assert_success
+}
+
+@test "should failure scantopdf missing mode parameter" {
+ run scantopdf
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing mode"
+}
+
+@test "should failure scantopdf missing pagecount parameter" {
+ run scantopdf "Color"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing pagecount"
+}
+
+@test "should failure scantopdf missing output parameter" {
+ run scantopdf "Color" "5"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: missing output"
+}
+
+@test "should failure scantopdf scanimage fails" {
+ scanimage_exit=1
+
+ run scantopdf "Color" "1" "test.pdf"
+
+ assert_failure
+ assert_line --index 0 "â ERROR: scan error"
+}
+
+@test "should success scantopdf" {
+ run scantopdf "Color" "1" "test.pdf"
+
+ assert_success
+}