diff --git a/deploy/run-vps-data-production.sh b/deploy/run-vps-data-production.sh index 56f21a3..4ac201e 100755 --- a/deploy/run-vps-data-production.sh +++ b/deploy/run-vps-data-production.sh @@ -128,9 +128,11 @@ fi if [[ "${DO_PUSH}" -eq 1 ]] && [[ -f "/etc/hyperstitionstud.io/id_ed25519_git_libre_audio" ]]; then echo "[4/5] Committing and pushing automated VPS telemetry updates to git.libre.audio..." - run_checked "hs-readme-sync --all" "${PYTHON_BIN}" -m hyperstitionstud_io.publishing.readme_sync --all + run_checked "hs-readme-sync --install-hooks" "${PYTHON_BIN}" -m hyperstitionstud_io.publishing.readme_sync --install-hooks DEPLOY_KEY="/etc/hyperstitionstud.io/id_ed25519_git_libre_audio" GIT_SSH_CMD="ssh -i ${DEPLOY_KEY} -p 2222 -o IdentitiesOnly=yes -o IdentityAgent=none -o BatchMode=yes -o StrictHostKeyChecking=accept-new" + export GIT_SSH_COMMAND="${GIT_SSH_CMD}" + unset SSH_AUTH_SOCK || true GIT_SSH_FLAGS=(-c "core.sshCommand=${GIT_SSH_CMD}") STAMP_UTC="$(date -u +%Y-%m-%dT%H:%M:%SZ)" for r in hyperstitionstudio-core ingglish-hyperdope-gematria encyclopedia-knowledge-graph; do @@ -138,18 +140,19 @@ if [[ "${DO_PUSH}" -eq 1 ]] && [[ -f "/etc/hyperstitionstud.io/id_ed25519_git_li if [[ "${PUSH_ONLY}" -eq 1 ]]; then echo " -> Inspecting ${r} for telemetry updates..." fi - if ! git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" config user.name 2>&1; then + if [[ -z "$(git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" config user.name || true)" ]]; then git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" config user.name "Hyperstition VPS Bot" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" config user.email "vps-bot@hyperstitionstud.io" fi forge_ssh="ssh://git@git.libre.audio:2222/seasharp" + git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" config core.sshCommand "${GIT_SSH_CMD}" || true git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" remote set-url origin "${forge_ssh}/${r}.git" || true git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" add -A if ! git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" diff --cached --quiet; then if [[ "${PUSH_ONLY}" -eq 1 ]]; then echo " [commit] Committing new telemetry changes in ${r}..." fi - run_checked "git commit (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" commit -m "chore(telemetry): automated VPS ${WINDOW_MODE} harvest (${STAMP_UTC})" || true + run_checked "git commit (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" commit -m "chore(telemetry): automated VPS ${WINDOW_MODE} harvest (${STAMP_UTC})" else if [[ "${PUSH_ONLY}" -eq 1 ]]; then echo " [clean] Repository ${r} working tree is clean (no new local telemetry changes to commit)." @@ -158,13 +161,22 @@ if [[ "${DO_PUSH}" -eq 1 ]] && [[ -f "/etc/hyperstitionstud.io/id_ed25519_git_li if [[ "${PUSH_ONLY}" -eq 1 ]]; then echo " [sync] Pulling and rebasing origin/main for ${r}..." fi - run_checked "git pull --rebase --autostash (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" pull --rebase --autostash origin main || true + run_checked "git pull --rebase --autostash (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" pull --rebase -X theirs --autostash origin main + unmerged_paths="$(git -C "${REPOS_ROOT}/${r}" diff --name-only --diff-filter=U || true)" + if [[ -n "${unmerged_paths}" ]]; then + while IFS= read -r uf; do + [[ -z "${uf}" ]] && continue + git -C "${REPOS_ROOT}/${r}" checkout --theirs -- "${uf}" + git -C "${REPOS_ROOT}/${r}" reset HEAD -- "${uf}" + done <<< "${unmerged_paths}" + git -C "${REPOS_ROOT}/${r}" stash drop -q || true + fi if [[ "${PUSH_ONLY}" -eq 1 ]]; then echo " [push] Pushing ${r} to git.libre.audio..." fi - run_checked "git push (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" push origin main || true + run_checked "git push (${r})" git "${GIT_SSH_FLAGS[@]}" -C "${REPOS_ROOT}/${r}" push origin main if [[ "${PUSH_ONLY}" -eq 1 ]]; then - echo " [ok] Repository ${r} successfully pushed to git.libre.audio." + echo " [ok] Repository ${r} successfully pushed to git.libre.audio ($(git -C "${REPOS_ROOT}/${r}" rev-parse --short HEAD))." fi fi done diff --git a/deploy/sync-vps-repos.sh b/deploy/sync-vps-repos.sh index c9a9eeb..681a384 100755 --- a/deploy/sync-vps-repos.sh +++ b/deploy/sync-vps-repos.sh @@ -45,10 +45,13 @@ export REPOS_ROOT="${REPOS_ROOT:-${DEFAULT_REPOS_ROOT}}" export LIVE_REPOS="${LIVE_REPOS:-/var/www/hyperstitionstud.io/repos}" DEPLOY_KEY="/etc/hyperstitionstud.io/id_ed25519_git_libre_audio" +GIT_SSH_CMD="" GIT_SSH_FLAGS=() if [[ -f "${DEPLOY_KEY}" ]]; then # Force OpenSSH to use only the deploy key (ignore forwarded ssh-agent / default ~/.ssh keys that exhaust MaxAuthTries) GIT_SSH_CMD="ssh -i ${DEPLOY_KEY} -p 2222 -o IdentitiesOnly=yes -o IdentityAgent=none -o BatchMode=yes -o StrictHostKeyChecking=accept-new" + export GIT_SSH_COMMAND="${GIT_SSH_CMD}" + unset SSH_AUTH_SOCK || true GIT_SSH_FLAGS=(-c "core.sshCommand=${GIT_SSH_CMD}") fi @@ -128,18 +131,36 @@ if [[ "${DO_PULL}" -eq 1 ]]; then if [[ "${repo}" == "haiperdohp-jemaytreeah" ]] && git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" remote | grep -qx "downstream"; then remote_name="downstream" fi - forge_ssh="ssh://git@git.libre.audio:2222/seasharp" slug="${repo}" if [[ "${repo}" == "hyperdope-ci-build" || "${repo}" == "ingglish-hyperdope-ci" ]]; then slug="ingglish-hyperdope-ci" fi - git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" remote set-url "${remote_name}" "${forge_ssh}/${slug}.git" || true + if [[ -f "${DEPLOY_KEY}" ]]; then + if [[ "${repo}" == "hyperstitionstudio-core" || "${repo}" == "ingglish-hyperdope-gematria" || "${repo}" == "encyclopedia-knowledge-graph" ]]; then + git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" config core.sshCommand "${GIT_SSH_CMD}" || true + git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" remote set-url "${remote_name}" "ssh://git@git.libre.audio:2222/seasharp/${slug}.git" || true + else + git -C "${REPOS_ROOT}/${repo}" config --unset core.sshCommand || true + git -C "${REPOS_ROOT}/${repo}" remote set-url "${remote_name}" "https://git.libre.audio/seasharp/${slug}.git" || true + fi + fi echo "[1/5] Updating ${REPOS_ROOT}/${repo} (${remote_name}/${branch}) with autostash rebase..." prev_head="$(git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" rev-parse HEAD)" if [[ "${#GIT_PULL_PREFIX[@]}" -gt 0 ]]; then - run_checked "git pull --rebase --autostash ${repo}" "${GIT_PULL_PREFIX[@]}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -c "safe.directory=${REPOS_ROOT}/${repo}" -C "${REPOS_ROOT}/${repo}" pull --rebase --autostash "${remote_name}" "${branch}" + run_checked "git fetch ${repo}" "${GIT_PULL_PREFIX[@]}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -c "safe.directory=${REPOS_ROOT}/${repo}" -C "${REPOS_ROOT}/${repo}" fetch --force "${remote_name}" "${branch}" --tags + run_checked "git pull --rebase --autostash ${repo}" "${GIT_PULL_PREFIX[@]}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -c "safe.directory=${REPOS_ROOT}/${repo}" -C "${REPOS_ROOT}/${repo}" pull --rebase -X theirs --autostash "${remote_name}" "${branch}" else - run_checked "git pull --rebase --autostash ${repo}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" pull --rebase --autostash "${remote_name}" "${branch}" + run_checked "git fetch ${repo}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" fetch --force "${remote_name}" "${branch}" --tags + run_checked "git pull --rebase --autostash ${repo}" git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" pull --rebase -X theirs --autostash "${remote_name}" "${branch}" + fi + unmerged_paths="$(git -C "${REPOS_ROOT}/${repo}" diff --name-only --diff-filter=U || true)" + if [[ -n "${unmerged_paths}" ]]; then + while IFS= read -r uf; do + [[ -z "${uf}" ]] && continue + git -C "${REPOS_ROOT}/${repo}" checkout --theirs -- "${uf}" + git -C "${REPOS_ROOT}/${repo}" reset HEAD -- "${uf}" + done <<< "${unmerged_paths}" + git -C "${REPOS_ROOT}/${repo}" stash drop -q || true fi new_head="$(git ${GIT_SSH_FLAGS[@]+"${GIT_SSH_FLAGS[@]}"} -C "${REPOS_ROOT}/${repo}" rev-parse HEAD)" if [[ "${repo}" == "hyperstitionstudio-core" && "${prev_head}" != "${new_head}" && -z "${HYPERSTITION_SYNC_REEXEC:-}" ]]; then @@ -180,7 +201,7 @@ if p.is_file(): p.write_text(u, encoding="utf-8") ' fi -run_checked "hs-readme-sync --hooks-only" "${PYTHON_BIN}" -m hyperstitionstud_io.publishing.readme_sync --hooks-only +run_checked "hs-readme-sync --install-hooks" "${PYTHON_BIN}" -m hyperstitionstud_io.publishing.readme_sync --install-hooks run_checked "hs-deploy-scripts-sync --check" "${PYTHON_BIN}" -m hyperstitionstud_io.ci.deploy_scripts_sync --workspace-root "${REPOS_ROOT}" --check run_checked "hs-closeups-sync --check" "${PYTHON_BIN}" -m hyperstitionstud_io.publishing.closeups_sync --check run_checked "version_sync --check" "${PYTHON_BIN}" -m hyperstitionstud_io.version_sync --check