From 87500911e02142fa7877f980818620042707ae5f Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Tue, 5 Mar 2024 08:28:40 +0100 Subject: Implement variable references --- lib/util/config.bash | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') 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 -- cgit v1.1