dracut-lib: new functions: listlist and are_lists_eq
authorAmadeusz Żołnowski <aidecoe@aidecoe.name>
Thu, 26 Jul 2012 13:05:25 +0000 (15:05 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 26 Jul 2012 14:35:13 +0000 (16:35 +0200)
listlist is like strstr for lists with specified separator and
are_lists_eq uses listlist to check equality of specified lists.

modules.d/99base/dracut-lib.sh

index 786661e..2eb1224 100755 (executable)
@@ -906,3 +906,41 @@ export_n()
         [ -n "$val" ] && eval $var=\"$val\"
     done
 }
+
+# returns OK if list1 contains all elements of list2, i.e. checks if list2 is a
+# sublist of list1.  An order and a duplication doesn't matter.
+#
+# $1 = separator
+# $2 = list1
+# $3 = list2
+# $4 = ignore values, separated by $1
+listlist() {
+    local _sep="$1"
+    local _list="${_sep}${2}${_sep}"
+    local _sublist="$3"
+    [ -n "$4" ] && local _iglist="${_sep}${4}${_sep}"
+    local IFS="$_sep"
+    local _v
+
+    [ "$_list" = "$_sublist" ] && return 0
+
+    for _v in $_sublist; do
+        if [ -n "$_v" ] && ! ( [ -n "$_iglist" ] && strstr "$_iglist" "$_v" )
+        then
+            strstr "$_list" "$_v" || return 1
+        fi
+    done
+
+    return 0
+}
+
+# returns OK if both lists contain the same values.  An order and a duplication
+# doesn't matter.
+# 
+# $1 = separator
+# $2 = list1
+# $3 = list2
+# $4 = ignore values, separated by $1
+are_lists_eq() {
+    listlist "$1" "$2" "$3" "$4" && listlist "$1" "$3" "$2" "$4"
+}