aboutsummaryrefslogtreecommitdiff
path: root/lib/subcommands
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-03-09 13:30:52 +0100
committerPatrick Spek <p.spek@tyil.nl>2023-03-09 13:30:52 +0100
commit5a3a5e2778c33031c42088fcddd4b5b2eb960bd2 (patch)
tree572a640f2d892206e3b5fb2c0d7cfc66e7562219 /lib/subcommands
parent9575bf831765033243743f026fcaabc9a02e9f78 (diff)
Implement BASHTARD_PLAYBOOK_VARS
Diffstat (limited to 'lib/subcommands')
-rw-r--r--lib/subcommands/add.bash24
-rw-r--r--lib/subcommands/sync.bash24
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/subcommands/add.bash b/lib/subcommands/add.bash
index 2ae6a43..ff1e5e9 100644
--- a/lib/subcommands/add.bash
+++ b/lib/subcommands/add.bash
@@ -7,6 +7,7 @@
subcommand()
{
local buffer
+ local missing_vars=0
export BASHTARD_PLAYBOOK="$1" ; shift
@@ -43,6 +44,29 @@ subcommand()
# shellcheck disable=SC1090,SC1091
. "$playbook_base/playbook.bash"
+ # Ensure all required vars are non-empty
+ debug "bashtard/add" "Checking for \$BASHTARD_PLAYBOOK_VARS"
+
+ for key in "${!BASHTARD_PLAYBOOK_VARS[@]}"
+ do
+ # shellcheck disable=SC2086
+ in_args "required" ${BASHTARD_PLAYBOOK_VARS[$key]} || continue
+
+ debug "bashtard/add" "Checking \$BASHTARD_PLAYBOOK_VARS[$key]"
+
+ if [[ "$(config "$key")" == "" ]]
+ then
+ missing_vars=$(( missing_vars + 1))
+ fi
+ done
+
+ if (( 0 < missing_vars ))
+ then
+ emerg "bashtard/add" "One or more required variables are unset"
+ return 3
+ fi
+
+ # Run the playbook
if ! playbook_add
then
crit "bashtard/add" "$BASHTARD_PLAYBOOK reported an error"
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
}