functions.sh: add list_contains function for checking whether a list contains a speci...
[openwrt.git] / package / base-files / files / etc / functions.sh
index 5ad45ec..01db77c 100755 (executable)
@@ -24,6 +24,29 @@ append() {
        eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
 }
 
+list_contains() {
+       local var="$1"
+       local str="$2"
+       local val
+
+       eval "val=\" \${$var} \""
+       [ "${val%% $str *}" != "$val" ]
+}
+
+list_remove() {
+       local var="$1"
+       local remove="$2"
+       local val
+
+       eval "val=\" \${$var} \""
+       val1="${val%% $remove *}"
+       [ "$val1" = "$val" ] && return
+       val2="${val##* $remove }"
+       [ "$val2" = "$val" ] && return
+       val="${val1## } ${val2%% }"
+       eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\""
+}
+
 config_load() {
        [ -n "$IPKG_INSTROOT" ] && return 0
        uci_load "$@"
@@ -208,4 +231,4 @@ uci_apply_defaults() {(
        uci commit
 )}
 
-[ -z "$IPKG_INSTROOT" ] && . /lib/config/uci.sh
+[ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh
This page took 0.023239 seconds and 4 git commands to generate.