diff options
Diffstat (limited to 'lib/subcommands/sync.bash')
-rw-r--r-- | lib/subcommands/sync.bash | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/subcommands/sync.bash b/lib/subcommands/sync.bash index 9537922..8d437f6 100644 --- a/lib/subcommands/sync.bash +++ b/lib/subcommands/sync.bash @@ -1,6 +1,6 @@ #!/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 @@ -15,22 +15,8 @@ subcommand() return fi - notice "bashtard/sync" "Syncing $BASHTARD_ETCDIR" - pushd -- "$BASHTARD_ETCDIR" > /dev/null - git pull origin master || return 4 - popd > /dev/null - - # Otherwise, do a full sync - notice "bashtard/sync" "Syncing remote playbooks" - - # Update all playbook sources - while read -r playbook _ branch - do - pushd -- "$BASHTARD_ETCDIR/playbooks.d/$playbook" > /dev/null \ - || return 2 - git pull origin "$branch" - popd > /dev/null - done < "$BASHTARD_ETCDIR/playbooks.d/remotes" + # Pull latest changes + "$BASHTARD_BIN" pull # Run a sync for each registered playbook for this host while read -r playbook @@ -42,7 +28,10 @@ subcommand() sync_playbook() { - local playbook_base="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK" + local playbook_base + local missing_vars=0 + + playbook_base="$(playbook_path "base")" notice "bashtard/sync" "Running sync for $BASHTARD_PLAYBOOK" @@ -58,8 +47,31 @@ sync_playbook() return 1 fi - # shellcheck disable=SC1090 + # 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 } |