From 433bf4cc04f8a5a8e8845ef01ef8d17a48ec3892 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 16 Jul 2026 17:05:10 +0200 Subject: [PATCH] change postinst add one entry --- src/debian/postinst | 14 +++++--------- tests/postinst.bats | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/debian/postinst b/src/debian/postinst index fa90e2a..546a97e 100755 --- a/src/debian/postinst +++ b/src/debian/postinst @@ -7,27 +7,23 @@ errlog() local lastexit=$? local msg="$1" - echo "$msg" + echo "ERROR: $msg" return $lastexit } main() { - local DLLCONFIG="/etc/sane.d/dll.conf" + DLLCONFIG=${DLLCONFIG:="/etc/sane.d/dll.conf"} + local entry_count= local ENTRY="kds_s2000w_net" [ -f "$DLLCONFIG" ] \ - || errlog "ERROR: $DLLCONFIG does not exist" \ + || errlog "$DLLCONFIG does not exist" \ || return 0 - echo "found $DLLCONFIG" - cat $DLLCONFIG | grep $ENTRY \ - || sed -i "\$a$ENTRY" $DLLCONFIG \ - || errlog "could not add entry $ENTRY to $DLLCONFIG" \ - || return 0 - echo "add $ENTRY to $DLLCONFIG" + grep --silent "$ENTRY" "$DLLCONFIG" || echo "$ENTRY" >> "$DLLCONFIG" } main \ No newline at end of file diff --git a/tests/postinst.bats b/tests/postinst.bats index 14cc794..fb3e353 100755 --- a/tests/postinst.bats +++ b/tests/postinst.bats @@ -3,8 +3,42 @@ setup() { bats_load_library bats-support bats_load_library bats-assert + mkdir --parents ../build + rm -rf ../build/dll.conf + touch ../build/dll.conf } -@test "sanity" { - assert_equal 1 1 +@test "ignore file does not exists" { + export DLLCONFIG="../build/dll-not-exists.conf" + + run ../src/debian/postinst + + assert_success + assert_output "ERROR: ../build/dll-not-exists.conf does not exist" + unset DLLCONFIG } + +@test "add entry kds_s2000w_net dll.conf" { + export DLLCONFIG="../build/dll.conf" + + run ../src/debian/postinst + + assert_success + assert_output "found ../build/dll.conf" + assert_equal "$(cat ../build/dll.conf)" "kds_s2000w_net" + assert_equal "$(cat ../build/dll.conf | wc --lines)" "1" + unset DLLCONFIG +} + +@test "entry exists in dll.conf do nothing" { + export DLLCONFIG="../build/dll.conf" + + run ../src/debian/postinst + run ../src/debian/postinst + + assert_success + assert_output "found ../build/dll.conf" + assert_equal "$(cat ../build/dll.conf)" "kds_s2000w_net" + assert_equal "$(cat ../build/dll.conf | wc --lines)" "1" + unset DLLCONFIG +} \ No newline at end of file -- 2.47.3