feat: add safe remote repository sync
Homelab Main / validate (push) Has been cancelled Details
Homelab Main / running-update (push) Has been cancelled Details
Homelab Main / debian-ops (push) Has been cancelled Details

This commit is contained in:
juvenal.diaz 2026-10-27 08:23:44 -06:00
parent 31949a55e9
commit 94cd91795e
4 changed files with 57 additions and 1 deletions

View File

@ -54,7 +54,7 @@ var allowedCommands = map[string]bool{
"deploy-dex": true, "deploy-matrix": true, "deploy-ai-stack": true,
"deploy-office": true,
"deploy-ai-tools": true, "deploy-omniroute": true, "deploy-hermes": true,
"rpi-services": true, "host-bootstrap": true, "bootstrap-gitea-repo": true, "backup-gitea": true,
"rpi-services": true, "host-bootstrap": true, "bootstrap-gitea-repo": true, "repo-sync": true, "backup-gitea": true,
"backup": true, "drill-restore": true, "drill-gitea-restore": true,
"drill-pihole-restore": true, "install-gitea-runner": true,
"move-prometheus-stack-workers": true, "doctor-versions": true,

View File

@ -66,6 +66,8 @@ Build And Bootstrap
deploy-omniroute Deploy the OmniRoute LLM routing gateway.
deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service).
bootstrap-gitea-repo Ensure the Gitea repo and SSH key wiring exist.
repo-sync [--remote REMOTE] [--branch BRANCH]
Safely fast-forward the Debian pipeline checkout.
rpi-services Deploy Pi-hole, Unbound, and Uptime Kuma on RPi4.
host-bootstrap rpi4 [status|plan|nfs-stage|install-image|apply --yes]
Provision/check the physical RPi4, then bootstrap host services.
@ -494,6 +496,9 @@ case "${1:-}" in
bootstrap-gitea-repo)
bootstrap_gitea_repo
;;
repo-sync)
repo_sync "${@:2}"
;;
backup-gitea)
backup_gitea
;;

View File

@ -4075,6 +4075,12 @@ oci_cleanup() {
"${REPO_ROOT}/scripts/oci-cleanup" "$@"
}
repo_sync() {
require_debian_server "repo-sync"
record_change_journal "repo-sync" "$@"
"${REPO_ROOT}/scripts/repo-sync" "$@"
}
storage_status() {
require_debian_server "storage"
local kubeconfig="${KUBECONFIG_PATH}"

45
scripts/repo-sync Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="${JEANNIE_SERVER_REPO_ROOT:-${REPO_ROOT:-$(pwd)}}"
remote="${JEANNIE_REPO_SYNC_REMOTE:-origin}"
branch="${JEANNIE_REPO_SYNC_BRANCH:-}"
while (($# > 0)); do
case "$1" in
--remote) remote="${2:-}"; shift 2 ;;
--branch) branch="${2:-}"; shift 2 ;;
*) echo "Usage: ./jeannie repo-sync [--remote REMOTE] [--branch BRANCH]" >&2; exit 2 ;;
esac
done
[[ -d "${repo_root}/.git" ]] || { echo "Git repository not found: ${repo_root}" >&2; exit 1; }
git_cmd=(git -C "${repo_root}")
current_branch="$("${git_cmd[@]}" branch --show-current)"
[[ -n "${branch}" ]] || branch="${current_branch}"
[[ -n "${branch}" ]] || { echo "Repository is in detached HEAD; specify --branch." >&2; exit 2; }
"${git_cmd[@]}" remote get-url "${remote}" >/dev/null || {
echo "Git remote not found: ${remote}" >&2
exit 2
}
if [[ -n "$("${git_cmd[@]}" status --porcelain)" ]]; then
echo "Refusing repo sync: working tree is not clean." >&2
"${git_cmd[@]}" status --short >&2
exit 1
fi
before="$("${git_cmd[@]}" rev-parse HEAD)"
printf 'Repository: %s\nRemote: %s\nBranch: %s\nBefore: %s\n' "${repo_root}" "${remote}" "${branch}" "${before}"
"${git_cmd[@]}" fetch --prune "${remote}" "${branch}"
remote_ref="${remote}/${branch}"
"${git_cmd[@]}" rev-parse --verify "${remote_ref}" >/dev/null || {
echo "Remote branch not found: ${remote_ref}" >&2
exit 1
}
"${git_cmd[@]}" merge --ff-only "${remote_ref}"
after="$("${git_cmd[@]}" rev-parse HEAD)"
if [[ "${before}" == "${after}" ]]; then
echo "Already up to date."
else
printf 'Updated: %s -> %s\n' "${before}" "${after}"
fi