diff options
author | Patrick Spek <p.spek@tyil.nl> | 2024-03-05 08:28:40 +0100 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2024-04-02 09:25:04 +0200 |
commit | 87500911e02142fa7877f980818620042707ae5f (patch) | |
tree | d5e0b7f2bc29872da53e0407e676439b119e5e50 /lib/util/config.bash | |
parent | ca33873ad616bdb4d38cd9e15aa184d1ab2aba05 (diff) |
Implement variable references
Diffstat (limited to 'lib/util/config.bash')
-rw-r--r-- | lib/util/config.bash | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/util/config.bash b/lib/util/config.bash index 9817cf3..703dc4d 100644 --- a/lib/util/config.bash +++ b/lib/util/config.bash @@ -55,6 +55,20 @@ config_for() { [[ ! -f $file ]] && continue + # Check if the lookup is a reference variable, defined by using + # &= instead of just a single = as seperator. If this exists, + # do a new config_for lookup, this time using the value as the + # key for the new lookup. + value="$(awk -F= '$1 == "'"$key"'&" { print $0 }' "$file" | cut -d'=' -f 2-)" + + if [[ -n $value ]] + then + debug "bashtard/config_for" "Found reference for $key to $value in $file" + + printf "%s" "$(config_for "$host" "$value")" + return + fi + # Use awk to find the right line, then use cut to get the # actual value. Cutting it out with awk _is_ possible, but # comes with whitespace issues or having to deal with values |