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
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