From f2f03d6ea4d6d181880a9f9c4f019d24065db4ec Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sat, 16 Apr 2022 14:27:42 +0200 Subject: Initial draft for sync subcommand --- lib/subcommands/sync.bash | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/subcommands/sync.bash (limited to 'lib/subcommands/sync.bash') 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 +} -- cgit v1.1