diff options
Diffstat (limited to 'lib/subcommands/add.bash')
-rw-r--r-- | lib/subcommands/add.bash | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/subcommands/add.bash b/lib/subcommands/add.bash index c72582b..db3ec40 100644 --- a/lib/subcommands/add.bash +++ b/lib/subcommands/add.bash @@ -1,12 +1,15 @@ #!/usr/bin/env bash -# SPDX-FileCopyrightText: 2022 Patrick Spek <p.spek@tyil.nl> +# SPDX-FileCopyrightText: 2023 Patrick Spek <p.spek@tyil.nl> # # SPDX-License-Identifier: AGPL-3.0-or-later subcommand() { local buffer + local missing_vars=0 + local playbook_base + local playbook_registry export BASHTARD_PLAYBOOK="$1" ; shift @@ -16,8 +19,8 @@ subcommand() return 2 fi - local playbook_base="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK" - local playbook_registry="$BASHTARD_ETCDIR/registry.d/${BASHTARD_PLATFORM[fqdn]}" + playbook_base="$(playbook_path "base")" + playbook_registry="$BASHTARD_ETCDIR/registry.d/${BASHTARD_PLATFORM[fqdn]}" # Make sure we only run add if the playbook is not in the registry yet if grep -Fqx "$BASHTARD_PLAYBOOK" "$playbook_registry" @@ -40,9 +43,32 @@ subcommand() return 1 fi - # shellcheck disable=SC1090 + # 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" |