aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2022-05-23 13:02:23 +0200
committerPatrick Spek <p.spek@tyil.nl>2022-05-23 13:02:23 +0200
commit50b197935ee39ac9efd472dd7b3de5e497db4ea4 (patch)
treec024fd1208f38d354a5f2ed9012900b428ec0f7e /lib
parentea843ed1bcc863ba8aef8fa972ce0732f386e550 (diff)
Add config_subkeys
Diffstat (limited to 'lib')
-rw-r--r--lib/util/config.bash44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/util/config.bash b/lib/util/config.bash
index 3f939ff..91d5c83 100644
--- a/lib/util/config.bash
+++ b/lib/util/config.bash
@@ -10,6 +10,10 @@ config() {
config_for "${BASHTARD_PLATFORM[fqdn]}" "$@"
}
+config_subkeys() {
+ config_subkeys_for "${BASHTARD_PLATFORM[fqdn]}" "$@"
+}
+
config_for() {
local host=$1 ; shift
local key=$1 ; shift
@@ -68,3 +72,43 @@ config_for() {
# Error
alert "bashtard/config_for" "No configuration value for $key"
}
+
+config_subkeys_for() {
+ local host=$1 ; shift
+ local key=$1 ; shift
+
+ local file
+ local files
+
+ files=(
+ "$BASHTARD_ETCDIR/secrets"
+ "$BASHTARD_ETCDIR/hosts.d/$host"
+ "$BASHTARD_ETCDIR/os.d/${BASHTARD_PLATFORM[key]}"
+ "$BASHTARD_ETCDIR/defaults"
+ )
+
+ if [[ -n "$BASHTARD_PLAYBOOK" ]]
+ then
+ debug "bashtard/config_for" "BASHTARD_PLAYBOOK=$BASHTARD_PLAYBOOK, adding etc entries"
+ files+=(
+ "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/etc/os.d/${BASHTARD_PLATFORM[key]}"
+ "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/etc/defaults"
+ )
+ fi
+
+ files+=(
+ "$BASHTARD_SHAREDIR/os.d/${BASHTARD_PLATFORM[key]}"
+ "$BASHTARD_SHAREDIR/defaults"
+ )
+
+ # Check configuration files
+ for file in "${files[@]}"
+ do
+ debug "bashtard/config_subkeys" "Checking for subkeys of '$key' in '$file'"
+
+ [[ ! -f $file ]] && continue
+
+ grep "^$key\." "$file" \
+ | awk -F= '{ print $1 }'
+ done
+}