From: Bastian Dehn Date: Thu, 16 Jul 2026 15:05:10 +0000 (+0200) Subject: change postinst add one entry X-Git-Tag: v1.1.35^2~3^2~12 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=433bf4cc04f8a5a8e8845ef01ef8d17a48ec3892;p=sane-kds-s2000w-net.git change postinst add one entry --- 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