diff options
Diffstat (limited to 'lib/subcommands/sync.bash')
-rw-r--r-- | lib/subcommands/sync.bash | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/subcommands/sync.bash b/lib/subcommands/sync.bash new file mode 100644 index 0000000..af5f282 --- /dev/null +++ b/lib/subcommands/sync.bash @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +subcommand() +{ + export BASHTARD_PLAYBOOK="$1" ; shift + + # If a specific playbook is given, sync that + if [[ ! -z "$BASHTARD_PLAYBOOK" ]] + then + sync_playbook "$BASHTARD_PLAYBOOK" + return + fi + + # Otherwise, do a full sync + notice "bashtard/sync" "Syncing remote playbooks" + + # Update all playbook sources + while read -r playbook url branch + do + pushd -- "$BASHTARD_ETCDIR/playbooks.d/$playbook" + git pull origin "$branch" + done < "$BASHTARD_ETCDIR/playbooks.d/remotes" + + # Run a sync for each registered playbook for this host + while read -r playbook + do + info "bashtard/sync" "Syncing $playbook" + "$BASHTARD_BASEDIR/bin/$BASHTARD_NAME" sync "$playbook" + done < "$BASHTARD_ETCDIR/registry.d/${BASHTARD_PLATFORM[fqdn]}" +} + +sync_playbook() +{ + local playbook_base="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK" + + notice "bashtard/sync" "Running sync for $BASHTARD_PLAYBOOK" + + if [[ ! -d "$playbook_base" ]] + then + emerg "bashtard/sync" "No such directory: $playbook_base" + return 1 + fi + + if [[ ! -f "$playbook_base/playbook.bash" ]] + then + emerg "bashtard/sync" "No such file: $playbook_base/playbook.bash" + return 1 + fi + + . "$playbook_base/playbook.bash" + + playbook_sync +} |