]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
fix shell check issues
authorBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 11:14:52 +0000 (13:14 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 27 Jun 2026 11:14:52 +0000 (13:14 +0200)
Makefile
src/addkeywords
src/addocr
src/addocr.sh
src/keywords.sh
src/scanbasic.sh

index 0ca7833b86ed30ea607e47033df99e83ed4f0a0d..26dac0f03f13c16abb6ea998be0f2c34f0c6c3aa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,7 @@ $(PACKAGEDIR)/$(BINDIR)/scantopdf: \
        ./tools/includer $(SRCDIR)/scantopdf \
                | sed "s/@VERSION@/$(VERSION)/" > $(@)
        chmod 755 $(@)
+       shellcheck $(@)
 
 $(PACKAGEDIR)/$(BINDIR)/scantopdfgray: \
        $(BUILDDIR)/parts/scanbasic.sh
@@ -62,6 +63,7 @@ $(PACKAGEDIR)/$(BINDIR)/scantopdfgray: \
        ./tools/includer $(SRCDIR)/scantopdfgray \
                | sed "s/@VERSION@/$(VERSION)/" > $(@)
        chmod 755 $(@)
+       shellcheck $(@)
 
 $(PACKAGEDIR)/$(BINDIR)/scantopdfbw: \
        $(BUILDDIR)/parts/scanbasic.sh
@@ -70,6 +72,7 @@ $(PACKAGEDIR)/$(BINDIR)/scantopdfbw: \
        ./tools/includer $(SRCDIR)/scantopdfgray \
                | sed "s/@VERSION@/$(VERSION)/" > $(@)
        chmod 755 $(@)
+       shellcheck $(@)
 
 $(PACKAGEDIR)/$(BINDIR)/addocr:
 
@@ -77,6 +80,7 @@ $(PACKAGEDIR)/$(BINDIR)/addocr:
        ./tools/includer $(SRCDIR)/addocr \
                | sed "s/@VERSION@/$(VERSION)/" > $(@)
        chmod 755 $(@)
+       shellcheck $(@)
 
 $(PACKAGEDIR)/$(BINDIR)/addkeywords:
 
@@ -84,6 +88,7 @@ $(PACKAGEDIR)/$(BINDIR)/addkeywords:
        ./tools/includer $(SRCDIR)/addkeywords \
                | sed "s/@VERSION@/$(VERSION)/" > $(@)
        chmod 755 $(@)
+       shellcheck $(@)
 
 ################################################################################
 
index 7186d40ce531f7f3641b34217b4975201bc0efb1..d31b0c0c8d82b4cdc36918f15fbcecef3dcedb8a 100644 (file)
@@ -24,4 +24,4 @@ main()
        echo "✅ SUCCESS: addkeywords  @VERSION@"
 }
 
-main $*
\ No newline at end of file
+main "$*"
\ No newline at end of file
index 9fa585ac2e1824fdaf1a6d3281b36e8d85ca23ee..344a52c33bcd526aae46bd8a03eccbf0d4471584 100644 (file)
@@ -20,4 +20,4 @@ main()
        echo "✅ SUCCESS: addocr @VERSION@"
 }
 
-main $*
\ No newline at end of file
+main "$*"
\ No newline at end of file
index 18f3d0a948820ee346cc9528d054dbda8709a8f1..9998ea8510ef2778d5fa81de7e9e7df1fb638e9f 100644 (file)
@@ -7,10 +7,10 @@ optimize()
                || errlog "missing input" \
                || return $?
 
-       qpdf --linearize $input $output \
+       qpdf --linearize "$input" "$output" \
                || errlog "could not linearize $input" \
                || return $?
-       mv $output $input \
+       mv "$output" "$input" \
                || errlog "could not rename $output to $input" \
                || return $?
 }
@@ -27,15 +27,15 @@ addocr()
                || return $?
 
        echo "ℹ️  INFO: adding ocr on file $input"
-       ocrmypdf --quiet --jobs $jobs --language deu $input $output \
+       ocrmypdf --quiet --jobs "$jobs" --language deu "$input" "$output" \
                || errlog "could not add ocr on $input" \
                        || return $?
 
-       [ ! -f $output ] && return 0
+       [ ! -f "$output" ] && return 0
 
-       mv $output $input \
+       mv "$output" "$input" \
                || errlog "could not rename $output to $input" \
                || return $?
-       optimize $input \
+       optimize "$input" \
                || return $?
 }
index 112e3cba74c1dc47083bc31f630b83d18a69bbd4..a8d5c4fe65b89cc23eea852dcf24f44f46bbaf62 100644 (file)
@@ -1,7 +1,8 @@
 get_title_from_file_name()
 {
        local file_name="$1"
-       local title="${file_name%.*}"
+       local title=
+       title="${file_name%.*}"
        title="${title#*_}"
        title="${title//_/ }"
 
@@ -21,11 +22,13 @@ add_keywords()
 {
        local file_name="$1"
        local keywords="$2"
+       local title=
+       local date=
 
        [ -z "$keywords" ] && return 0
 
-       local title=$(get_title_from_file_name "$file_name")
-       local date=$(get_date_from_file_name "$file_name")
+       title=$(get_title_from_file_name "$file_name")
+       date=$(get_date_from_file_name "$file_name")
 
        echo "ℹ️  INFO: adding keywords $keywords to $file_name"
        exiftool -Title="$title" \
index 6587c1c769dcc2d7a9c118333cf6421fada7fc50..c36ccbf50c4d25ba4640420aa11a7095a106a2a2 100644 (file)
@@ -38,8 +38,8 @@ convert_tiff_to_pdf()
        local tiff="$1"
        local pdf=${tiff/.tiff/.pdf}
 
-       tiff2pdf $tiff -o $pdf
-       rm $tiff
+       tiff2pdf "$tiff" -o "$pdf"
+       rm "$tiff"
 }
 
 createonepdf()
@@ -55,7 +55,7 @@ createonepdf()
                | sort \
                | parallel convert_tiff_to_pdf {}
 
-       pdftk scanned-$$-*.pdf output $output \
+       pdftk scanned-$$-*.pdf output "$output" \
                || errlog "could not convert into single $output" \
                || return $?
 
@@ -63,7 +63,7 @@ createonepdf()
                || errlog "could not remove scanned pdfs" \
                || return $?
 
-       addocr $output \
+       addocr "$output" \
                || return $?
 }
 
@@ -84,16 +84,16 @@ createpdf()
                || return $?
 
        local i=
-       for i in $(seq $start $end); do
-               countno=$(printf "%03d" $i)
-               pdfs=$(echo $pdfs "scanned-$$-$countno.pdf")
+       for i in $(seq "$start" "$end"); do
+               countno=$(printf "%03d" "$i")
+               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 pdf in $pdfs; do
+       for pdf in "${pdfs[@]}"; do
                rm "$pdf" \
                        || errlog "could not delete $pdf" \
                        || return 1
@@ -109,7 +109,7 @@ detectsplit()
                || errlog "missing pdf" \
                || return $?
 
-       trenn=$(pdfgrep "CUTPAGE-CUTPAGE-CUTPAGE-CUTPAGE" $pdf | xargs)
+       trenn=$(pdfgrep "CUTPAGE-CUTPAGE-CUTPAGE-CUTPAGE" "$pdf" | xargs)
 
        [ "$trenn" == "CUTPAGE-CUTPAGE-CUTPAGE-CUTPAGE" ] \
                && echo "true" \
@@ -134,17 +134,17 @@ createmultipdfs()
        export -f optimize
        find . -name "scanned-$$-*.pdf" \
                | sort \
-               | parallel --keep-order addocr {} $(nproc)
+               | parallel --keep-order addocr {} "$(nproc)"
 
        local startcount=1
        local endcount=1
        local trenn=
        local pdffile=
-       for pdffile in scanned-$$-*.pdf; do
-               trenn=$(detectsplit $pdffile) \
+       for pdffile in scanned-"$$"-*.pdf; do
+               trenn=$(detectsplit "$pdffile") \
                        || return $?
                [ "$trenn" != "true" ] \
-                       || rm $pdffile \
+                       || rm "$pdffile" \
                        || errlog "could not delete $pdffile" \
                        || return $?
                [ "$trenn" != "true" ] \
@@ -182,12 +182,12 @@ scantopdf() {
                || return $?
 
        scanimage --source=DocumentFeeder \
-               --mode=$mode \
+               --mode="$mode" \
                --resolution=300 \
                --scanside=Duplex \
                --skip-blank-pages=yes \
                --format=tiff \
-               --batch-count=$pagecount \
+               --batch-count="$pagecount" \
                --batch-increment=1 \
                --batch=scanned-$$-%03d.tiff \
                || errlog "scan error" \