]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
add command checks
authorBastian Dehn <hhaalo@arcor.de>
Thu, 3 Apr 2025 17:59:08 +0000 (19:59 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 3 Apr 2025 17:59:08 +0000 (19:59 +0200)
errlog.sh [deleted file]
scanbasic.sh

diff --git a/errlog.sh b/errlog.sh
deleted file mode 100644 (file)
index 47986f2..0000000
--- a/errlog.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-errlog()
-{
-       local msg="$1"
-
-       echo "ERROR: $msg"
-       return 1
-}
index 6cfbe1ceff76dfefc8b142f4888bdabb24d0af1d..454af45eb56f042481bc6ef21946067744d5830e 100644 (file)
@@ -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 \