#!/bin/bash
-
set -e
-errlog()
+find_config()
{
- local lastexit=$?
- local msg="$1"
-
- echo "$msg"
+ [ ! -f "$DLLCONFIG" ] \
+ && echo "WARNING: $DLLCONFIG does not exist" \
+ && return 1
+ echo "found $DLLCONFIG"
+}
- return $lastexit
+delete_entries()
+{
+ local entry="kds_s2000w_net"
+ sed --in-place "/$entry/d" "$DLLCONFIG"
+ echo "remove $entry from $DLLCONFIG"
}
main()
{
- local DLLCONFIG="/etc/sane.d/dll.conf"
- local ENTRY="kds_s2000w_net"
-
- [ -f "$DLLCONFIG" ] \
- || errlog "ERROR: $DLLCONFIG does not exist" \
- || return 0
-
- echo "found $DLLCONFIG"
- cat $DLLCONFIG | grep $ENTRY \
- || errlog "$ENTRY entry does not exists in $DLLCONFIG" \
- || return 0
-
- sed -i "/$ENTRY/d" $DLLCONFIG \
- || errlog "could not remove $ENTRY from $DLLCONFIG" \
- || return 0
+ DLLCONFIG=${DLLCONFIG:="/etc/sane.d/dll.conf"}
- echo "remove $ENTRY from $DLLCONFIG"
+ find_config || return 0
+ delete_entries
}
main
\ No newline at end of file
--- /dev/null
+#!/usr/bin/bats
+
+setup() {
+ bats_load_library bats-support
+ bats_load_library bats-assert
+ mkdir --parents ../build
+ echo kds_s2000w_net > ../build/dllpostrm.conf
+}
+
+teardown() {
+ rm -rf ../build/dllpostrm.conf
+ unset DLLCONFIG
+}
+
+@test "ignore file does not exist" {
+ export DLLCONFIG="../build/dll-not-exists.conf"
+
+ run ../src/debian/postrm
+
+ assert_success
+ assert_output "WARNING: ../build/dll-not-exists.conf does not exist"
+}
+
+@test "delete one entry kds_s2000w_net from dll.conf {
+ export DLLCONFIG="../build/dllpostrm.conf"
+
+ run ../src/debian/postrm
+
+ assert_success
+ assert_line --index 0 "found ../build/dllpostrm.conf"
+ assert_line --index 1 "remove kds_s2000w_net from ../build/dllpostrm.conf"
+ assert_equal "$(cat ../build/dllpostrm.conf)" ""
+ assert_equal "$(cat ../build/dllpostrm.conf | wc --lines)" "0"
+}
+
+@test "delete multiple entry kds_s2000w_net from dll.conf {
+ echo kds_s2000w_net >> ../build/dllpostrm.conf
+ echo kds_s2000w_net >> ../build/dllpostrm.conf
+ echo kds_s2000w_net >> ../build/dllpostrm.conf
+ export DLLCONFIG="../build/dllpostrm.conf"
+
+ run ../src/debian/postrm
+ run ../src/debian/postrm
+ run ../src/debian/postrm
+
+ assert_success
+ assert_line --index 0 "found ../build/dllpostrm.conf"
+ assert_line --index 1 "remove kds_s2000w_net from ../build/dllpostrm.conf"
+ assert_equal "$(cat ../build/dllpostrm.conf)" ""
+ assert_equal "$(cat ../build/dllpostrm.conf | wc --lines)" "0"
+}
\ No newline at end of file