From 325166de216b6acfaa167341588304eb8e296c12 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 27 Jun 2026 13:14:52 +0200 Subject: [PATCH] fix shell check issues --- Makefile | 5 +++++ src/addkeywords | 2 +- src/addocr | 2 +- src/addocr.sh | 12 ++++++------ src/keywords.sh | 9 ++++++--- src/scanbasic.sh | 32 ++++++++++++++++---------------- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 0ca7833..26dac0f 100644 --- 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 $(@) ################################################################################ diff --git a/src/addkeywords b/src/addkeywords index 7186d40..d31b0c0 100644 --- a/src/addkeywords +++ b/src/addkeywords @@ -24,4 +24,4 @@ main() echo "✅ SUCCESS: addkeywords @VERSION@" } -main $* \ No newline at end of file +main "$*" \ No newline at end of file diff --git a/src/addocr b/src/addocr index 9fa585a..344a52c 100644 --- a/src/addocr +++ b/src/addocr @@ -20,4 +20,4 @@ main() echo "✅ SUCCESS: addocr @VERSION@" } -main $* \ No newline at end of file +main "$*" \ No newline at end of file diff --git a/src/addocr.sh b/src/addocr.sh index 18f3d0a..9998ea8 100644 --- a/src/addocr.sh +++ b/src/addocr.sh @@ -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 $? } diff --git a/src/keywords.sh b/src/keywords.sh index 112e3cb..a8d5c4f 100644 --- a/src/keywords.sh +++ b/src/keywords.sh @@ -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" \ diff --git a/src/scanbasic.sh b/src/scanbasic.sh index 6587c1c..c36ccbf 100644 --- a/src/scanbasic.sh +++ b/src/scanbasic.sh @@ -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" \ -- 2.47.3