From 5a3a5e2778c33031c42088fcddd4b5b2eb960bd2 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Thu, 9 Mar 2023 13:30:52 +0100
Subject: Implement BASHTARD_PLAYBOOK_VARS
---
lib/subcommands/sync.bash | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'lib/subcommands/sync.bash')
diff --git a/lib/subcommands/sync.bash b/lib/subcommands/sync.bash
index 1ae2aae..8f5e2cd 100644
--- a/lib/subcommands/sync.bash
+++ b/lib/subcommands/sync.bash
@@ -29,6 +29,7 @@ subcommand()
sync_playbook()
{
local playbook_base="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK"
+ local missing_vars=0
notice "bashtard/sync" "Running sync for $BASHTARD_PLAYBOOK"
@@ -47,5 +48,28 @@ sync_playbook()
# shellcheck disable=SC1090,SC1091
. "$playbook_base/playbook.bash"
+ debug "bashtard/sync" "Checking for \$BASHTARD_PLAYBOOK_VARS"
+
+ # Ensure all required vars are non-empty
+ for key in "${!BASHTARD_PLAYBOOK_VARS[@]}"
+ do
+ # shellcheck disable=SC2086
+ in_args "required" ${BASHTARD_PLAYBOOK_VARS[$key]} || continue
+
+ debug "bashtard/sync" "Checking \$BASHTARD_PLAYBOOK_VARS[$key]"
+
+ if [[ "$(config "$key")" == "" ]]
+ then
+ missing_vars=$(( missing_vars + 1))
+ fi
+ done
+
+ if (( 0 < missing_vars ))
+ then
+ emerg "bashtard/sync" "One or more required variables are unset"
+ return 3
+ fi
+
+ # Run the playbook
playbook_sync
}
--
cgit v1.1