From: Bastian Dehn Date: Thu, 3 Apr 2025 17:59:08 +0000 (+0200) Subject: add command checks X-Git-Tag: v1.0.6^2~4 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0610db48ba022633f301e796712c52e159f541e7;p=scantopdf.git add command checks --- diff --git a/errlog.sh b/errlog.sh deleted file mode 100644 index 47986f2..0000000 --- a/errlog.sh +++ /dev/null @@ -1,7 +0,0 @@ -errlog() -{ - local msg="$1" - - echo "ERROR: $msg" - return 1 -} diff --git a/scanbasic.sh b/scanbasic.sh index 6cfbe1c..454af45 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -1,14 +1,27 @@ +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 $? qpdf --linearize $input $output \ || errlog "could not linearize $input" \ - || return 1 + || return $? mv $output $input \ || errlog "cloud not rename $ouptut to $input" \ - || return 1 + || return $? } addocr() @@ -17,10 +30,13 @@ addocr() local output=$input-out local error="" + command -v ocrmypdf > /dev/null \ + || errlog "command ocrmypdf not found" \ + || return $? echo $input error=$(ocrmypdf -l deu $input $output 2>&1) \ || errlog "could not add ocr on $input" \ - || return 1 + || return $? if [ -n "$(echo $error | grep offset)" ]; then printf "%s: %s\n" $input $error >> $HOME/addocr-error.log @@ -29,8 +45,8 @@ addocr() if [ -f $output ]; then mv $output $input \ || errlog "could not rename $output to $input" \ - || return 1 - optimize $input || return 1 + || return $? + optimize $input || return $? fi } @@ -38,20 +54,26 @@ 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 $? for i in scanned*.tiff; do tiff2pdf $i -o ${i/.tiff/.pdf} \ || errlog "could not convert tiff to pdf" \ - || return 1 - rm $i || errlog "could not delete $i" || return 1 + || return $? + rm $i || errlog "could not delete $i" || return $? done pdftk scanned*.pdf output $output \ || errlog "could not convert into single $output" \ - || return 1 + || return $? rm scanned*.pdf \ || errlog "could not remove scanned pdfs" \ - || return 1 - addocr $output || return 1 + || return $? + addocr $output || return $? } createpdf() @@ -62,6 +84,10 @@ createpdf() local countno= local pdfs=() + command -v pdftk > /dev/null \ + || errlog "command pdftk not found" \ + || return $? + if [ -z "$basename" ]; then basename="out" fi @@ -106,6 +132,9 @@ createmultipdfs() local endcount=1 local pdf= + command -v tiff2pdf > /dev/null \ + || errlog "command tiff2pdf not found" \ + || return $? for i in scanned*.tiff; do pdf=${i/.tiff/.pdf} tiff2pdf $i -o $pdf \