From ceae57fc8dd350cc0de1510cdc42341139c7cc96 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 5 Jul 2025 19:36:55 +0200 Subject: [PATCH] change project structur --- build-package | 66 ++++++++++++------- control => src/control | 0 .../generate-trennblatt | 0 scanbasic.sh => src/scanbasic.sh | 2 +- scantopdf => src/scantopdf | 0 scantopdfbw => src/scantopdfbw | 0 scantopdfgray => src/scantopdfgray | 0 scanbasic.bats => tests/scanbasic.bats | 49 ++++---------- 8 files changed, 56 insertions(+), 61 deletions(-) rename control => src/control (100%) rename generate-trennblatt => src/generate-trennblatt (100%) rename scanbasic.sh => src/scanbasic.sh (98%) rename scantopdf => src/scantopdf (100%) rename scantopdfbw => src/scantopdfbw (100%) rename scantopdfgray => src/scantopdfgray (100%) rename scanbasic.bats => tests/scanbasic.bats (86%) diff --git a/build-package b/build-package index 964ea40..86c602a 100755 --- a/build-package +++ b/build-package @@ -1,42 +1,64 @@ #!/bin/bash -main() +errlog() +{ + local lastexit=$? + local msg="$1" + + echo "❌ ERROR: $msg" + echo "🛑 EXIT $lastexit" + return $lastexit +} + +build_package() { local VERSION="1.0.7" local BUILDVERSION="1" local ARCHITECTURE="amd64" local PACKAGENAME="scantopdf-$VERSION-$BUILDVERSION-$ARCHITECTURE" + local EXECUTABLES="scantopdf \ + scantopdfgray \ + scantopdfbw \ + generate-trennblatt" + + echo "ℹ️ INFO: build package $PACKAGENAME" - echo "⭐ START: build-package" mkdir -p build mkdir -p build/$PACKAGENAME/usr/local/bin - 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 - 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 + local executable= + for executable in $EXECUTABLES; do + cp src/$executable build/$PACKAGENAME/usr/local/bin/$executable + sed -i "/@scanbasic.sh@/r src/scanbasic.sh" \ + build/$PACKAGENAME/usr/local/bin/$executable + sed -i "/@scanbasic.sh@/d" \ + build/$PACKAGENAME/usr/local/bin/$executable + done mkdir -p build/$PACKAGENAME/DEBIAN - cp control build/$PACKAGENAME/DEBIAN/control + cp src/control build/$PACKAGENAME/DEBIAN/control sed -i "s/\$VERSION/$VERSION/" build/$PACKAGENAME/DEBIAN/control cd build - dpkg --build $PACKAGENAME +} + +run_tests() +{ + echo "ℹ️ INFO: run tests" + ./tests/scanbasic.bats +} + +main() +{ + echo "⭐ START: build-package" + + [ -n "$SKIP_TESTS" ] \ + || run_tests \ + || errlog "tests failed" \ + || return $? + build_package + echo "✅ SUCCESS: build-package" } diff --git a/control b/src/control similarity index 100% rename from control rename to src/control diff --git a/generate-trennblatt b/src/generate-trennblatt similarity index 100% rename from generate-trennblatt rename to src/generate-trennblatt diff --git a/scanbasic.sh b/src/scanbasic.sh similarity index 98% rename from scanbasic.sh rename to src/scanbasic.sh index 06f5eb5..b7d7692 100644 --- a/scanbasic.sh +++ b/src/scanbasic.sh @@ -39,7 +39,7 @@ addocr() || errlog "missing input" \ || return $? - echo "ℹ️ INFO: adding ocr on file $input..." + echo "ℹ️ INFO: adding ocr on file $input" ocrmypdf --quiet --language deu $input $output \ || errlog "could not add ocr on $input" \ || return $? diff --git a/scantopdf b/src/scantopdf similarity index 100% rename from scantopdf rename to src/scantopdf diff --git a/scantopdfbw b/src/scantopdfbw similarity index 100% rename from scantopdfbw rename to src/scantopdfbw diff --git a/scantopdfgray b/src/scantopdfgray similarity index 100% rename from scantopdfgray rename to src/scantopdfgray diff --git a/scanbasic.bats b/tests/scanbasic.bats similarity index 86% rename from scanbasic.bats rename to tests/scanbasic.bats index 6ffb3f0..c1c8a4b 100755 --- a/scanbasic.bats +++ b/tests/scanbasic.bats @@ -1,42 +1,42 @@ #!/usr/bin/bats tiff2pdf() { - echo "$tiff2pdf_return" + printf "$tiff2pdf_return" return "$tiff2pdf_exit" } ocrmypdf() { - echo "$ocrmypdf_return" + printf "$ocrmypdf_return" return "$ocrmypdf_exit" } qpdf() { - echo "$qpdf_return" + printf "$qpdf_return" return "$qpdf_exit" } mv() { - echo "$mv_return" + printf "$mv_return" return "$mv_exit" } rm() { - echo "$rm_return" + printf "$rm_return" return "$rm_exit" } pdftk() { - echo "$pdftk_return" + printf "$pdftk_return" return "$pdftk_exit" } zbarimg() { - echo "$zbarimg_return" + printf "$zbarimg_return" return "$zbarimg_exit" } scanimage() { - echo "$scanimage_return" + printf "$scanimage_return" return "$scanimage_exit" } @@ -44,7 +44,7 @@ setup() { load "/usr/lib/bats/bats-assert/load" load "/usr/lib/bats/bats-support/load" - source ./scanbasic.sh + source ./src/scanbasic.sh export -f qpdf qpdf_return= @@ -135,7 +135,7 @@ teardown() { run addocr "testfile" assert_failure - assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile..." + assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile" assert_line --index 1 "❌ ERROR: could not add ocr on testfile" } @@ -143,7 +143,7 @@ teardown() { run addocr "testfile" assert_success - assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile..." + assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile" } @test "should failure createonepdf missing output parameter" { @@ -162,15 +162,6 @@ teardown() { assert_line --index 0 "❌ ERROR: could not convert tiff to pdf" } -@test "should failure createonepdf delete testfile fails" { - rm_exit=1 - - run createonepdf "testfile" - - assert_failure - assert_line --index 0 "❌ ERROR: could not delete scanned*.tiff" -} - @test "should failure createonepdf pdftk fails" { pdftk_exit=1 @@ -209,15 +200,6 @@ teardown() { assert_line --index 0 "❌ ERROR: could not create pdf" } -@test "should failure pdf delete fails" { - rm_exit=1 - - run createpdf "1" "2" - - assert_failure - assert_line --index 0 "❌ ERROR: could not delete scanned001.pdf" -} - @test "should success createpdf" { run createpdf "1" "2" @@ -265,15 +247,6 @@ teardown() { assert_line --index 0 "❌ ERROR: could not convert scanned*.tiff to scanned*.pdf" } -@test "should failure createmultipdfs rm tiff fails" { - rm_exit=1 - - run createmultipdfs - - assert_failure - assert_line --index 0 "❌ ERROR: could not delete scanned*.tiff" -} - @test "should success createmutlipdfs" { run createmultipdfs -- 2.47.3