From: Bastian Dehn Date: Sat, 29 Mar 2025 10:07:22 +0000 (+0100) Subject: add errlog to scripts X-Git-Tag: v1.0.5^2~1 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=73bc555c39dcc3f1e855d9c589a7bd58badc736c;p=scantopdf.git add errlog to scripts --- diff --git a/build-package b/build-package index 86deccd..ee2eca6 100755 --- a/build-package +++ b/build-package @@ -13,14 +13,20 @@ main() 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 diff --git a/errlog.sh b/errlog.sh new file mode 100644 index 0000000..47986f2 --- /dev/null +++ b/errlog.sh @@ -0,0 +1,7 @@ +errlog() +{ + local msg="$1" + + echo "ERROR: $msg" + return 1 +} diff --git a/scanbasic.sh b/scanbasic.sh index 08d5c22..6cfbe1c 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -3,8 +3,12 @@ optimize() 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() @@ -14,15 +18,19 @@ 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 } @@ -31,13 +39,19 @@ createonepdf() 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() @@ -57,13 +71,15 @@ 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() @@ -71,7 +87,9 @@ 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 @@ -90,12 +108,15 @@ createmultipdfs() 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++)) diff --git a/scantopdf b/scantopdf index 768800f..1e9e0ee 100755 --- a/scantopdf +++ b/scantopdf @@ -1,23 +1,25 @@ #!/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 \ @@ -26,19 +28,16 @@ main() --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 $* diff --git a/scantopdfbw b/scantopdfbw index c25dfed..570508e 100755 --- a/scantopdfbw +++ b/scantopdfbw @@ -1,23 +1,25 @@ #!/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 \ @@ -26,19 +28,16 @@ main() --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 $* diff --git a/scantopdfgray b/scantopdfgray index 224fb5e..5b6a6ad 100755 --- a/scantopdfgray +++ b/scantopdfgray @@ -1,23 +1,25 @@ #!/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 \ @@ -26,19 +28,16 @@ main() --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 $*