70 lines
1.8 KiB
Bash
Executable file
70 lines
1.8 KiB
Bash
Executable file
#!/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-salt
|
|
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-salt
|
|
|
|
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-salt" </dev/null >/tmp/saltstuff.bundle
|
|
|
|
echo "{dom0} cloning into \$1; checking out branch '${branch}'" >&2
|
|
|
|
git clone /tmp/saltstuff.bundle -b "${branch}" "\$1"
|
|
|
|
pushd "\$1"
|
|
|
|
echo "{dom0} setting up remote '${guest_name}' to push/pull changes via bundle" >&2
|
|
|
|
mkdir ./.bundles
|
|
mv /tmp/saltstuff.bundle ./.bundles/qubes-mgmt-salt
|
|
git remote remove origin
|
|
git remote add "${guest_name}" \$(pwd)/.bundles/qubes-mgmt-salt
|
|
|
|
# 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-salt main~1..main main
|
|
|
|
qvm-run -p "${guest_name}" "cat > ${guest_repo_dir}/.bundles/qubes-mgmt-salt" <.bundles/qubes-mgmt-salt
|
|
|
|
qvm-run -p "${guest_name}" "cd ${guest_repo_dir} && git fetch dom0" </dev/null
|
|
|
|
# configure pointer to guest VM and path
|
|
|
|
echo "GUEST=${guest_name}" > .bundle-env
|
|
echo "GUEST_REPO=${guest_repo_dir}" >> .bundle-env
|
|
|
|
echo "${dom0} has pulled!" >&2
|
|
|
|
popd
|
|
DOM0
|
|
|