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
- cp scantopdfbw build/$PACKAGENAME/usr/local/bin/scantopdfbw
+ 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
mkdir -p build/$PACKAGENAME/DEBIAN
--- /dev/null
+errlog()
+{
+ local msg="$1"
+
+ echo "ERROR: $msg"
+ return 1
+}
local input=$1
local output=$input-out
- qpdf --linearize $input $output
- mv $output $input
+ qpdf --linearize $input $output \
+ || errlog "could not linearize $input" \
+ || return 1
+ mv $output $input \
+ || errlog "cloud not rename $ouptut to $input" \
+ || return 1
}
addocr()
local error=""
echo $input
- error=$(ocrmypdf -l deu $input $output 2>&1)
+ error=$(ocrmypdf -l deu $input $output 2>&1) \
+ || errlog "could not add ocr on $input" \
+ || return 1
if [ -n "$(echo $error | grep offset)" ]; then
printf "%s: %s\n" $input $error >> $HOME/addocr-error.log
fi
if [ -f $output ]; then
- mv $output $input
- optimize $input
+ mv $output $input \
+ || errlog "could not rename $output to $input" \
+ || return 1
+ optimize $input || return 1
fi
}
local output=$1
for i in scanned*.tiff; do
- tiff2pdf $i -o ${i/.tiff/.pdf}
- rm $i
+ tiff2pdf $i -o ${i/.tiff/.pdf} \
+ || errlog "could not convert tiff to pdf" \
+ || return 1
+ rm $i || errlog "could not delete $i" || return 1
done
- pdftk scanned*.pdf output $output
- rm scanned*.pdf
- addocr $output
+ pdftk scanned*.pdf output $output \
+ || errlog "could not convert into single $output" \
+ || return 1
+ rm scanned*.pdf \
+ || errlog "could not remove scanned pdfs" \
+ || return 1
+ addocr $output || return 1
}
createpdf()
pdfs=$(echo $pdfs "scanned$countno.pdf")
done
- pdftk $pdfs output $basename$(printf "%03d" $start).pdf
+ pdftk $pdfs output $basename$(printf "%03d" $start).pdf \
+ || errlog "could not create pdf" \
+ || return 1
for i in $pdfs; do
- rm $i
+ rm $i || errlog "could not delete $i" || return 1
done
- addocr $basename$(printf "%03d" $start).pdf
+ addocr $basename$(printf "%03d" $start).pdf || return 1
}
detectsplit()
local pdf=$1
local trenn=
- trenn=$(zbarimg --raw --quiet $pdf)
+ trenn=$(zbarimg --raw --quiet $pdf) \
+ || errlog "could not read cut page" \
+ || return 1
if [ "$trenn" == "Trennblatt" ]; then
echo "true"
return
for i in scanned*.tiff; do
pdf=${i/.tiff/.pdf}
- tiff2pdf $i -o $pdf
+ tiff2pdf $i -o $pdf \
+ || errlog "could not convert $i to $pdf" \
+ || return 1
trenn=$(detectsplit $pdf)
rm $i
if [ "$trenn" == "true" ]; then
rm $pdf
- createpdf $startcount $((endcount - 1)) $basename
+ createpdf $startcount $((endcount - 1)) $basename \
+ || return 1
startcount=$((endcount + 1))
fi
((endcount++))
#!/bin/bash
+@errlog.sh@
+
@scanbasic.sh@
main()
{
- if [ -z "$1" ]; then
- echo "ERROR: no page count"
- exit 1
- fi
-
- if [ -z "$2" ]; then
- echo "ERROR: no pdf file name"
- exit 1
- fi
-
local pagecount=$1
local output=$2
local basename=$3
+ if [ -z "$pagecount" ]; then
+ errlog "no page count"
+ return 1
+ fi
+
+ if [ -z "$output" ]; then
+ errlog "no pdf file name"
+ return 1
+ fi
+
scanimage --source=DocumentFeeder \
--mode=Color \
--resolution=300 \
--format=tiff \
--batch-count=$pagecount \
--batch-increment=1 \
- --batch=scanned%03d.tiff
-
- if [ $? -gt 0 ]; then
- echo "ERROR: scan error"
- exit 1
- fi
+ --batch=scanned%03d.tiff \
+ || errlog "scan error" \
+ || return 1
if [ "$output" == "multi" ]; then
- createmultipdfs $pagecount $basename
+ createmultipdfs $pagecount $basename || return 1
exit 0
fi
- createonepdf $output
+ createonepdf $output || return 1
}
main $*
#!/bin/bash
+@errlog.sh@
+
@scanbasic.sh@
main()
{
- if [ -z "$1" ]; then
- echo "ERROR: no page count"
- exit 1
- fi
-
- if [ -z "$2" ]; then
- echo "ERROR: no pdf file name"
- exit 1
- fi
-
local pagecount=$1
local output=$2
local basename=$3
+ if [ -z "$pagecount" ]; then
+ errlog "no page count"
+ return 1
+ fi
+
+ if [ -z "$output" ]; then
+ errlog "no pdf file name"
+ return 1
+ fi
+
scanimage --source=DocumentFeeder \
--mode=BW \
--resolution=300 \
--format=tiff \
--batch-count=$pagecount \
--batch-increment=1 \
- --batch=scanned%03d.tiff
-
- if [ $? -gt 0 ]; then
- echo "ERROR: scan error"
- exit 1
- fi
+ --batch=scanned%03d.tiff \
+ || errlog "scan error" \
+ || return 1
if [ "$output" == "multi" ]; then
- createmultipdfs $pagecount $basename
- exit 0
+ createmultipdfs $pagecount $basename || return 1
+ return
fi
- createonepdf $output
+ createonepdf $output || return 1
}
main $*
#!/bin/bash
+@errlog.sh@
+
@scanbasic.sh@
main()
{
- if [ -z "$1" ]; then
- echo "ERROR: no page count"
- exit 1
- fi
-
- if [ -z "$2" ]; then
- echo "ERROR: no pdf file name"
- exit 1
- fi
-
local pagecount=$1
local output=$2
local basename=$3
+ if [ -z "$pagecount" ]; then
+ errlog "no page count"
+ return 1
+ fi
+
+ if [ -z "$output" ]; then
+ errlog "no pdf file name"
+ return 1
+ fi
+
scanimage --source=DocumentFeeder \
--mode=Gray \
--resolution=300 \
--format=tiff \
--batch-count=$pagecount \
--batch-increment=1 \
- --batch=scanned%03d.tiff
-
- if [ $? -gt 0 ]; then
- echo "ERROR: scan error"
- exit 1
- fi
+ --batch=scanned%03d.tiff \
+ || errlog "scan error" \
+ || return 1
if [ "$output" == "multi" ]; then
- createmultipdfs $pagecount $basename
- exit 0
+ createmultipdfs $pagecount $basename || return 1
+ return
fi
- createonepdf $output
+ createonepdf $output || return 1
}
main $*