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

index 38d92a02785cefa18139446450ca3878be14aba3..523b7ee0b0de658eeb07bebc14464848bcca616f 100755 (executable)
@@ -1,17 +1,31 @@
 #!/bin/bash
 set -e
 
-main()
+find_config()
 {
-       DLLCONFIG=${DLLCONFIG:="/etc/sane.d/dll.conf"}
-       local ENTRY="kds_s2000w_net"
-
        [ ! -f "$DLLCONFIG" ] \
                && echo "ERROR: $DLLCONFIG does not exist" \
-               && return 0
+               && return 1
        echo "found $DLLCONFIG"
+}
+
+add_entry()
+{
+       local entry="$1"
+       local dllconfig="$2"
 
-       grep --silent "$ENTRY" "$DLLCONFIG" || echo "$ENTRY" >> "$DLLCONFIG"
+       grep --silent "$entry" "$dllconfig" && return 0
+       echo "$entry" >> "$dllconfig"
+       echo "add kds_s2000w_net to ../build/dll.conf"
+}
+
+main()
+{
+       DLLCONFIG=${DLLCONFIG:="/etc/sane.d/dll.conf"}
+       local ENTRY="kds_s2000w_net"
+       
+       find_config "$DLLCONFIG" || return 0
+       add_entry "$ENTRY" "$DLLCONFIG"
 }
 
 main
\ No newline at end of file
index 589d8dcef5e666f019a32eacf5ee219930e3dcbd..7d78fbfb59a852fbb54c90bed328a2dc70729df2 100755 (executable)
@@ -27,7 +27,8 @@ teardown() {
        run ../src/debian/postinst
 
        assert_success
-       assert_output "found ../build/dll.conf"
+       assert_line --index 0 "found ../build/dll.conf"
+       assert_line --index 1 "add kds_s2000w_net to ../build/dll.conf"
        assert_equal "$(cat ../build/dll.conf)" "kds_s2000w_net"
        assert_equal "$(cat ../build/dll.conf | wc --lines)" "1"
        unset DLLCONFIG