From 92663498248f5f55252d510b292cefb84d1a3b84 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 16 Jul 2026 17:28:42 +0200 Subject: [PATCH] change postinst with sub functions --- src/debian/postinst | 26 ++++++++++++++++++++------ tests/postinst.bats | 3 ++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/debian/postinst b/src/debian/postinst index 38d92a0..523b7ee 100755 --- a/src/debian/postinst +++ b/src/debian/postinst @@ -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 diff --git a/tests/postinst.bats b/tests/postinst.bats index 589d8dc..7d78fbf 100755 --- a/tests/postinst.bats +++ b/tests/postinst.bats @@ -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 -- 2.47.3