]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change postinst add one entry
authorBastian Dehn <hhaalo@arcor.de>
Thu, 16 Jul 2026 15:05:10 +0000 (17:05 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 16 Jul 2026 15:05:10 +0000 (17:05 +0200)
src/debian/postinst
tests/postinst.bats

index fa90e2a4433222b6a6dda9430d571fcbeadab996..546a97eee63cbd71f7eb90d910f03b72f6242144 100755 (executable)
@@ -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
index 14cc79471354ba71dc43f71f1fa804d707873e0d..fb3e353fe23969ee5ec14840cc587d32a71f5eb4 100755 (executable)
@@ -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