commit 98c6295dbe64f89c7317ae862042436427deb525 Author: mustard Date: Wed Dec 3 14:23:27 2025 +0100 Initial commit diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..7900193 --- /dev/null +++ b/setup.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -eo pipefail + +# running in guest +guest_name="$(qubesdb-read /name)" +echo $(realpath ""$0"") +guest_repo_dir="$(dirname $(realpath ""$0""))" +echo $guest_repo_dir + +pushd ${guest_repo_dir} >/dev/null + +if git remote | grep -Fq 'dom0'; then + echo "(${guest_name}) remote 'dom0' already exists" >&2 +else + echo "(${guest_name}) setting up remote 'dom0' to pull changes via bundle" >&2 + echo "ehhh" + echo ${guest_repo_dir} + git remote add dom0 ${guest_repo_dir}/.bundles/qubes-mgmt-ansible +fi + +branch=$(git branch --show-current) +echo "(${guest_name}) creating bundle for branch '${branch}'" >&2 +mkdir -p .bundles + +git bundle create - --all > .bundles/qubes-mgmt-ansible + +popd >/dev/null + +# piped to bash in dom0 + +cat <<-DOM0 +set -eo pipefail + +echo "(dom0) bringing bundle from qubes '${guest_name}'" >&2 + +qvm-run -p ${guest_name} "cat ${guest_repo_dir}/.bundles/qubes-mgmt-ansible" /tmp/ansiblestuff.bundle + +echo "{dom0} cloning into \$1; checking out branch '${branch}'" >&2 + +git clone /tmp/ansiblestuff.bundle -b "${branch}" "\$1" + +pushd "\$1" + +echo "{dom0} setting up remote '${guest_name}' to push/pull changes via bundle" >&2 + +mkdir ./.bundles +mv /tmp/ansiblestuff.bundle ./.bundles/qubes-mgmt-ansible +git remote remove origin +git remote add "${guest_name}" \$(pwd)/.bundles/qubes-mgmt-ansible + +# ensure remote refs are present in each repo +git fetch "${guest_name}" # ensure remote refs are present in the dom0 repo + +git bundle create .bundles/qubes-mgmt-ansible main~1..main main + +qvm-run -p "${guest_name}" "cat > ${guest_repo_dir}/.bundles/qubes-mgmt-ansible" <.bundles/qubes-mgmt-ansible + +qvm-run -p "${guest_name}" "cd ${guest_repo_dir} && git fetch dom0" .bundle-env +echo "GUEST_REPO=${guest_repo_dir}" >> .bundle-env + +echo "${dom0} has pulled!" >&2 + +popd +DOM0 + +