]> git.ipfire.org Git - network.git/commitdiff
config: Read all configuration variables into an array.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Sep 2012 09:35:06 +0000 (09:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Sep 2012 09:35:06 +0000 (09:35 +0000)
functions.config

index f10bcf147874de6367bbb3d4b0797e1c59c95106..e229805645a9cf6ee85c4c206d3ac2c22b42845d 100644 (file)
@@ -57,7 +57,47 @@ function config_read() {
                                ;;
                        *)
                                log DEBUG "Invalid line in configuration file: ${line}"
-                               continue
+                               ;;
+               esac
+       done < ${file}
+}
+
+function config_read_array() {
+       local file=${1}
+       assert isset file
+       shift
+
+       local array=${1}
+       assert isset array
+       shift
+
+       local valid_keys=$@
+
+       # Exit if the file cannot be read.
+       [ -r "${file}" ] || return ${EXIT_ERROR}
+
+       local line key val
+       while read -r line; do
+               case "${line}" in
+                       *=*)
+                               key=$(cli_get_key ${line})
+
+                               # If valid_keys is set, key must be in the list.
+                               if [ -n "${valid_keys}" ]; then
+                                       if ! listmatch ${key} ${valid_keys}; then
+                                               log DEBUG "Ignoring configuration setting: ${key}"
+                                               continue
+                                       fi
+                               fi
+
+                               val=$(cli_get_val ${line})
+                               val=$(config_strip ${val})
+
+                               # Assign variable.
+                               printf -v  "${array}["${key}"]" "%s" "${val}"
+                               ;;
+                       *)
+                               log DEBUG "Invalid line in configuration file: ${line}"
                                ;;
                esac
        done < ${file}