#!/usr/bin/env bash # /workspace/push-all-to-git-libre-audio.sh # Release v2.17.1: Pre-push verification & topological push of all 6 repositories to git.libre.audio. set -euo pipefail on_error() { local exit_code=$? local line_no="${1:-unknown}" echo "[ERROR] push-all-to-git-libre-audio.sh failed at line ${line_no} with exit code ${exit_code} while running: ${BASH_COMMAND}" >&2 exit "${exit_code}" } trap 'on_error ${LINENO}' ERR run_checked() { local label="$1" shift local out="" local rc=0 out="$("$@" 2>&1)" || rc=$? if [[ "${rc}" -ne 0 ]]; then echo "[ERROR] ${label} failed (exit code ${rc}): $*" >&2 if [[ -n "${out}" ]]; then echo "${out}" >&2 fi return "${rc}" fi } ensure_remote_url() { local repo_dir="$1" local remote_name="$2" local target_url="$3" if git -C "${repo_dir}" remote | grep -qx "${remote_name}"; then run_checked "git remote set-url ${remote_name} (${repo_dir})" git -C "${repo_dir}" remote set-url "${remote_name}" "${target_url}" else run_checked "git remote add ${remote_name} (${repo_dir})" git -C "${repo_dir}" remote add "${remote_name}" "${target_url}" fi } SCRIPT_PATH="${BASH_SOURCE[0]:-$0}" DEFAULT_WS_DIR="$(cd "$(dirname "${SCRIPT_PATH}")" && pwd)" if [[ ! -d "${DEFAULT_WS_DIR}/hyperstitionstudio-core/src" ]] && [[ -d "/workspace/hyperstitionstudio-core/src" ]]; then DEFAULT_WS_DIR="/workspace" fi export WORKSPACE_DIR="${WORKSPACE_DIR:-${DEFAULT_WS_DIR}}" export PYTHONPATH="${WORKSPACE_DIR}/hyperstitionstudio-core/src${PYTHONPATH:+:${PYTHONPATH}}" export HYPERSTITIONSTUDIO_CONFIG="${HYPERSTITIONSTUDIO_CONFIG:-${WORKSPACE_DIR}/workspace.toml}" FORGE_SSH="${FORGE_SSH:-ssh://git@git.libre.audio:2222/seasharp}" EXEGESIS_HOST="${EXEGESIS_HOST:-}" EXEGESIS_UNINSTALL=0 SKIP_EXEGESIS_DEPLOY=0 while [[ $# -gt 0 ]]; do case "$1" in --exegesis-host=*) EXEGESIS_HOST="${1#*=}" shift ;; --exegesis-host) if [[ $# -lt 2 ]] || [[ -z "${2:-}" ]]; then echo "[ERROR] --exegesis-host requires a argument." >&2 exit 2 fi EXEGESIS_HOST="$2" shift 2 ;; --exegesis-uninstall) EXEGESIS_UNINSTALL=1 shift ;; --skip-exegesis-deploy) SKIP_EXEGESIS_DEPLOY=1 shift ;; -h|--help) echo "Usage: $0 [--exegesis-host=] [--exegesis-uninstall] [--skip-exegesis-deploy]" exit 0 ;; *) echo "[ERROR] Unknown option: $1" >&2 echo "Usage: $0 [--exegesis-host=] [--exegesis-uninstall] [--skip-exegesis-deploy]" >&2 exit 2 ;; esac done if [[ "${EXEGESIS_UNINSTALL}" -eq 1 ]]; then if [[ -z "${EXEGESIS_HOST}" ]] && [[ -t 0 ]]; then read -r -p "Enter target Fedora 41 host (user@host) to uninstall ingglish-isopsephic-exegesis: " EXEGESIS_HOST || EXEGESIS_HOST="" fi if [[ -z "${EXEGESIS_HOST}" ]]; then echo "[ERROR] --exegesis-uninstall requires --exegesis-host=." >&2 exit 2 fi echo "[uninstall] Verifying SSH connectivity to ${EXEGESIS_HOST}..." ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" true echo "[uninstall] Uninstalling ingglish-isopsephic-exegesis on ${EXEGESIS_HOST}..." if [[ -t 0 ]]; then ssh -t "${EXEGESIS_HOST}" sudo rpm -e ingglish-isopsephic-exegesis else ssh "${EXEGESIS_HOST}" sudo rpm -e ingglish-isopsephic-exegesis fi echo "[OK] Cleanly uninstalled ingglish-isopsephic-exegesis from ${EXEGESIS_HOST}." exit 0 fi echo "[info] WORKSPACE_DIR=${WORKSPACE_DIR}" echo "[info] PYTHONPATH=${PYTHONPATH}" echo "[1/3] Running pre-push verification gates (hs-archive-rotate, hs-readme-sync, version_sync --corpus-delta, periodic harvest CI/CD flow diagram PNG, Fedora 41 RPM & dry-run, test_core_suite, 6-gate graph verifier)..." run_checked "hs-archive-rotate --enforce-single-compression" python3 -m hyperstitionstud_io.publishing.archive_rotator --workspace-root "${WORKSPACE_DIR}" --enforce-single-compression run_checked "hs-readme-sync --install-hooks" python3 -m hyperstitionstud_io.publishing.readme_sync --install-hooks run_checked "version_sync --corpus-delta" python3 -m hyperstitionstud_io.version_sync --corpus-delta run_checked "generate & verify periodic-harvest-cicd-to-vps-flow-diagram.png" python3 -m hyperstitionstud_io.publishing.flow_diagram run_checked "verify periodic-harvest-cicd-to-vps-flow-diagram.png exists" test -s "${WORKSPACE_DIR}/encyclopedia-knowledge-graph/docs/periodic-harvest-cicd-to-vps-flow-diagram.png" run_checked "verify Fedora 41 packaging scripts & spec" "${WORKSPACE_DIR}/ingglish-hyperdope-gematria/packaging/build-fedora41-rpm.sh" run_checked "verify Fedora 41 exegesis push worker dry-run" "${WORKSPACE_DIR}/ingglish-hyperdope-gematria/packaging/bundle/scripts/run_exegesis_and_push_fedora41.sh" --dry-run python3 "${WORKSPACE_DIR}/hyperstitionstudio-core/tests/test_core_suite.py" run_checked "build_encyclopedia_knowledge_graph.py --verify-only" python3 "${WORKSPACE_DIR}/encyclopedia-knowledge-graph/scripts/build_encyclopedia_knowledge_graph.py" --verify-only echo "[2/3] Verifying git.libre.audio remote URLs across all repositories..." CI_REPO_DIR="hyperdope-ci-build" if [[ ! -d "${WORKSPACE_DIR}/${CI_REPO_DIR}" ]] && [[ -d "${WORKSPACE_DIR}/ingglish-hyperdope-ci" ]]; then CI_REPO_DIR="ingglish-hyperdope-ci" fi for pair in \ "hyperstitionstudio-core:hyperstitionstudio-core.git" \ "ingglish-hyperdope-gematria:ingglish-hyperdope-gematria.git" \ "technocapital-singularity-zoology:technocapital-singularity-zoology.git" \ "encyclopedia-knowledge-graph:encyclopedia-knowledge-graph.git" \ "${CI_REPO_DIR}:ingglish-hyperdope-ci.git"; do rdir="${WORKSPACE_DIR}/${pair%%:*}" rslug="${pair##*:}" ensure_remote_url "${rdir}" origin "${FORGE_SSH}/${rslug}" done push_head_tag() { local repo_dir="$1" local remote_name="$2" local head_tag="" head_tag="$(git -C "${repo_dir}" tag --points-at HEAD | sort -V | tail -n 1)" if [[ -n "${head_tag}" ]]; then run_checked "git push tag ${head_tag} (${repo_dir})" git -C "${repo_dir}" push --force "${remote_name}" "refs/tags/${head_tag}" fi } echo "[3/3] Rebasing any automated VPS telemetry commits & pushing all 6 repositories and HEAD release tags in topological dependency order to ${FORGE_SSH}..." echo " -> (1/6) hyperstitionstudio-core (main + HEAD tag)" run_checked "git pull --rebase (hyperstitionstudio-core main)" git -C "${WORKSPACE_DIR}/hyperstitionstudio-core" pull --rebase --autostash origin main git -C "${WORKSPACE_DIR}/hyperstitionstudio-core" push -u origin main push_head_tag "${WORKSPACE_DIR}/hyperstitionstudio-core" origin echo " -> (2/6) ingglish-hyperdope-gematria (main + HEAD tag)" run_checked "git pull --rebase (ingglish-hyperdope-gematria main)" git -C "${WORKSPACE_DIR}/ingglish-hyperdope-gematria" pull --rebase --autostash origin main git -C "${WORKSPACE_DIR}/ingglish-hyperdope-gematria" push -u origin main push_head_tag "${WORKSPACE_DIR}/ingglish-hyperdope-gematria" origin echo " -> (3/6) technocapital-singularity-zoology (main + HEAD tag)" run_checked "git pull --rebase (technocapital-singularity-zoology main)" git -C "${WORKSPACE_DIR}/technocapital-singularity-zoology" pull --rebase --autostash origin main git -C "${WORKSPACE_DIR}/technocapital-singularity-zoology" push -u origin main push_head_tag "${WORKSPACE_DIR}/technocapital-singularity-zoology" origin echo " -> (4/6) encyclopedia-knowledge-graph (main + HEAD tag)" run_checked "git pull --rebase (encyclopedia-knowledge-graph main)" git -C "${WORKSPACE_DIR}/encyclopedia-knowledge-graph" pull --rebase --autostash origin main git -C "${WORKSPACE_DIR}/encyclopedia-knowledge-graph" push -u origin main push_head_tag "${WORKSPACE_DIR}/encyclopedia-knowledge-graph" origin echo " -> (5/6) hyperdope-ci-build (${CI_REPO_DIR}, feat/ingglish-aq-corpus + HEAD tag)" run_checked "git pull --rebase (${CI_REPO_DIR} feat/ingglish-aq-corpus)" git -C "${WORKSPACE_DIR}/${CI_REPO_DIR}" pull --rebase --autostash origin feat/ingglish-aq-corpus git -C "${WORKSPACE_DIR}/${CI_REPO_DIR}" push -u origin feat/ingglish-aq-corpus push_head_tag "${WORKSPACE_DIR}/${CI_REPO_DIR}" origin if [[ -d "${WORKSPACE_DIR}/haiperdohp-jemaytreeah/.git" ]]; then echo " -> (6/6) haiperdohp-jemaytreeah (downstream main, feat/ingglish-aq-corpus, feat/ingglish-priority-toggle + HEAD tag)" ensure_remote_url "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" downstream "${FORGE_SSH}/haiperdohp-jemaytreeah.git" run_checked "git fetch downstream (haiperdohp-jemaytreeah)" git -C "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" fetch downstream run_checked "git pull --rebase (haiperdohp-jemaytreeah main)" git -C "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" pull --rebase --autostash downstream main run_checked "git pull --rebase (haiperdohp-jemaytreeah feat/ingglish-aq-corpus)" git -C "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" pull --rebase --autostash downstream feat/ingglish-aq-corpus run_checked "git pull --rebase (haiperdohp-jemaytreeah feat/ingglish-priority-toggle)" git -C "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" pull --rebase --autostash downstream feat/ingglish-priority-toggle git -C "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" push downstream main feat/ingglish-aq-corpus feat/ingglish-priority-toggle push_head_tag "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" downstream fi echo "[OK] All 6 repositories and release tags pushed to ${FORGE_SSH}." if [[ "${SKIP_EXEGESIS_DEPLOY}" -eq 1 ]]; then echo "[info] Skipping Fedora 41 exegesis RPM over-the-wire deployment (--skip-exegesis-deploy)." elif [[ -z "${EXEGESIS_HOST}" ]] && [[ -t 0 ]]; then read -r -p "Deploy built Fedora 41 exegesis RPM over the wire via SSH? [y/N / enter user@host]: " EXEGESIS_INPUT || EXEGESIS_INPUT="" EXEGESIS_INPUT="${EXEGESIS_INPUT#"${EXEGESIS_INPUT%%[![:space:]]*}"}" EXEGESIS_INPUT="${EXEGESIS_INPUT%"${EXEGESIS_INPUT##*[![:space:]]}"}" case "${EXEGESIS_INPUT}" in ""|n|N|no|NO) echo "[info] Skipping Fedora 41 exegesis RPM over-the-wire deployment." ;; y|Y|yes|YES) read -r -p "Enter target Fedora 41 host (user@host or IP): " EXEGESIS_HOST || EXEGESIS_HOST="" EXEGESIS_HOST="${EXEGESIS_HOST#"${EXEGESIS_HOST%%[![:space:]]*}"}" EXEGESIS_HOST="${EXEGESIS_HOST%"${EXEGESIS_HOST##*[![:space:]]}"}" ;; *) EXEGESIS_HOST="${EXEGESIS_INPUT}" ;; esac elif [[ -z "${EXEGESIS_HOST}" ]]; then echo "[info] Non-interactive session and --exegesis-host not set; skipping Fedora 41 exegesis RPM deployment." fi if [[ "${SKIP_EXEGESIS_DEPLOY}" -eq 0 ]] && [[ -n "${EXEGESIS_HOST}" ]]; then echo "[deploy] Verifying SSH connectivity to ${EXEGESIS_HOST}..." ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" true RPM_FILE="" shopt -s nullglob RPM_CANDIDATES=( "${WORKSPACE_DIR}/ingglish-hyperdope-gematria/packaging"/ingglish-isopsephic-exegesis-*.fc41.noarch.rpm "${WORKSPACE_DIR}/untracked/rpm-builds"/ingglish-isopsephic-exegesis-*.fc41.noarch.rpm ) shopt -u nullglob if [[ ${#RPM_CANDIDATES[@]} -gt 0 ]]; then RPM_FILE="$(printf '%s\n' "${RPM_CANDIDATES[@]}" | sort -V | tail -n 1)" fi if [[ -z "${RPM_FILE}" ]] || [[ ! -f "${RPM_FILE}" ]]; then echo "[ERROR] No built Fedora 41 RPM found in ${WORKSPACE_DIR}/ingglish-hyperdope-gematria/packaging/ or ${WORKSPACE_DIR}/untracked/rpm-builds/." >&2 exit 1 fi RPM_NAME="$(basename "${RPM_FILE}")" RPM_SIZE_BYTES="$(wc -c < "${RPM_FILE}" | tr -d '[:space:]')" MIN_STAGE_KB="$(( (RPM_SIZE_BYTES + 1023) / 1024 + 1024 ))" echo "[deploy] Found built RPM: ${RPM_FILE} (${RPM_SIZE_BYTES} bytes)" echo "[deploy] Resolving writable remote staging directory on ${EXEGESIS_HOST} (need >= ${MIN_STAGE_KB} KiB)..." REMOTE_STAGE_DIR="$( ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" bash -s -- "${MIN_STAGE_KB}" <<'EOF_STAGE' set -euo pipefail min_kb="${1:-2048}" home_dir="${HOME:-$(pwd)}" for cand in "/tmp" "${home_dir}/.cache/rpm-stage" "${home_dir}/rpm-stage"; do created_parent=0 if [[ "${cand}" != "/tmp" ]]; then if [[ ! -d "${cand}" ]]; then mkdir -p "${cand}" || continue created_parent=1 fi fi if [[ ! -d "${cand}" ]] || [[ ! -w "${cand}" ]]; then continue fi if mount_opts="$(findmnt -n -o OPTIONS -T "${cand}" 2>&1)"; then mount_opts="${mount_opts//[[:space:]]/}" case ",${mount_opts}," in *,noexec,*) if [[ "${created_parent}" -eq 1 ]]; then rmdir "${cand}" || true fi continue ;; esac fi avail_kb="$(df -Pk "${cand}" 2>&1 | awk 'NR==2 {print $4}')" case "${avail_kb}" in ''|*[!0-9]*) avail_kb=0 ;; esac if [[ "${avail_kb}" -lt "${min_kb}" ]]; then if [[ "${created_parent}" -eq 1 ]]; then rmdir "${cand}" || true fi continue fi if stage_dir="$(mktemp -d "${cand}/ingglish-exegesis-stage.XXXXXX" 2>&1)"; then if [[ -d "${stage_dir}" ]] && [[ -w "${stage_dir}" ]]; then printf '%s\n' "${stage_dir}" exit 0 fi fi if [[ "${created_parent}" -eq 1 ]]; then rmdir "${cand}" || true fi done echo "[ERROR] Failed to resolve a writable remote staging directory with >= ${min_kb} KiB free and without noexec." >&2 exit 1 EOF_STAGE )" if [[ -z "${REMOTE_STAGE_DIR}" ]]; then echo "[ERROR] Remote staging directory resolution returned an empty path on ${EXEGESIS_HOST}." >&2 exit 1 fi REMOTE_RPM_PATH="${REMOTE_STAGE_DIR}/${RPM_NAME}" echo "[deploy] Using remote staging directory: ${REMOTE_STAGE_DIR}" cleanup_remote_stage() { ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" "rm -rf '${REMOTE_STAGE_DIR}'; if [ -d \"\${HOME}/.cache/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/.cache/rpm-stage\" || true; fi; if [ -d \"\${HOME}/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/rpm-stage\" || true; fi" || true } echo "[deploy] Transferring ${RPM_NAME} to ${EXEGESIS_HOST}:${REMOTE_RPM_PATH}..." if ! scp "${RPM_FILE}" "${EXEGESIS_HOST}:${REMOTE_RPM_PATH}"; then cleanup_remote_stage exit 1 fi echo "[deploy] Installing/upgrading ${RPM_NAME} on ${EXEGESIS_HOST}..." INSTALL_CMD="rc=0; sudo rpm -Uvh --replacepkgs '${REMOTE_RPM_PATH}' || rc=\$?; rm -rf '${REMOTE_STAGE_DIR}'; if [ -d \"\${HOME}/.cache/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/.cache/rpm-stage\" || true; fi; if [ -d \"\${HOME}/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/rpm-stage\" || true; fi; exit \${rc}" if [[ -t 0 ]]; then ssh -t "${EXEGESIS_HOST}" "${INSTALL_CMD}" else ssh "${EXEGESIS_HOST}" "${INSTALL_CMD}" fi echo "[deploy] Running in-situ dry-run verification on ${EXEGESIS_HOST}..." ssh -t "${EXEGESIS_HOST}" "sudo -u ingglish /usr/bin/ingglish-exegesis-push --dry-run || sudo /usr/bin/ingglish-exegesis-push --dry-run" echo "[deploy] Verifying systemd timer state on ${EXEGESIS_HOST}..." ssh "${EXEGESIS_HOST}" "systemctl is-enabled ingglish-exegesis.timer || true" echo "[OK] Verified in-situ execution of /usr/bin/ingglish-exegesis-push --dry-run on ${EXEGESIS_HOST}." echo "[rollback] To reverse this installation on ${EXEGESIS_HOST}, run: ssh ${EXEGESIS_HOST} sudo rpm -e ingglish-isopsephic-exegesis" fi