297 lines
12 KiB
Bash
Executable File
297 lines
12 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# /workspace/ingglish-hyperdope-gematria/packaging/bundle/scripts/run_exegesis_and_push_fedora41.sh
|
|
# Installed as /usr/bin/ingglish-exegesis-push on Fedora 41 (`ingglish-isopsephic-exegesis` RPM).
|
|
#
|
|
# End-to-End Turnkey Runner for populating the hyperstitionstud.io repositories with LLM-dependent
|
|
# daily 00:00 UTC current-events exegesis data from a Fedora 41 machine and pushing to git.libre.audio.
|
|
# Enforces full stdout/stderr visibility, flock concurrency protection, and 4-gate CI verification.
|
|
set -euo pipefail
|
|
|
|
on_error() {
|
|
local exit_code=$?
|
|
local line_no="${1:-unknown}"
|
|
echo "[ERROR] run_exegesis_and_push_fedora41.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
|
|
}
|
|
|
|
SYSCONFIG_FILE="${INGGLISH_SYSCONFIG_FILE:-/etc/sysconfig/ingglish-exegesis}"
|
|
if [[ -f "${SYSCONFIG_FILE}" && -r "${SYSCONFIG_FILE}" ]]; then
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "${SYSCONFIG_FILE}"
|
|
set +a
|
|
fi
|
|
|
|
TARGET_DATE=""
|
|
DO_PUSH=1
|
|
DRY_RUN=0
|
|
ALLOW_FALLBACK=0
|
|
FORCE_RUN=0
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--date=*)
|
|
TARGET_DATE="${1#*=}"
|
|
shift
|
|
;;
|
|
--date)
|
|
TARGET_DATE="${2:-}"
|
|
shift 2
|
|
;;
|
|
--workspace-dir=*)
|
|
WORKSPACE_DIR="${1#*=}"
|
|
shift
|
|
;;
|
|
--workspace-dir)
|
|
WORKSPACE_DIR="${2:-}"
|
|
shift 2
|
|
;;
|
|
--no-push)
|
|
DO_PUSH=0
|
|
shift
|
|
;;
|
|
--dry-run)
|
|
DRY_RUN=1
|
|
shift
|
|
;;
|
|
--allow-deterministic-fallback)
|
|
ALLOW_FALLBACK=1
|
|
shift
|
|
;;
|
|
--force)
|
|
FORCE_RUN=1
|
|
shift
|
|
;;
|
|
*)
|
|
echo "[ERROR] Unknown argument: $1" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "${WORKSPACE_DIR:-}" ]]; then
|
|
if [[ -d "/workspace/ingglish-hyperdope-gematria" ]]; then
|
|
WORKSPACE_DIR="/workspace"
|
|
else
|
|
WORKSPACE_DIR="/var/lib/ingglish-exegesis/workspace"
|
|
fi
|
|
fi
|
|
export WORKSPACE_DIR
|
|
export TZ="UTC"
|
|
export FORGE_SSH="${FORGE_SSH:-ssh://git@git.libre.audio:2222/seasharp}"
|
|
export OPENROUTER_API_URL="${OPENROUTER_API_URL:-https://openrouter.ai/api/v1/chat/completions}"
|
|
export OPENROUTER_MODEL="${OPENROUTER_MODEL:-google/gemini-2.5-pro}"
|
|
export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-Hyperstition Studio Exegesis Worker}"
|
|
export GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-exegesis@hyperstitionstud.io}"
|
|
export GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-${GIT_AUTHOR_NAME}}"
|
|
export GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-${GIT_AUTHOR_EMAIL}}"
|
|
|
|
if [[ -n "${INGGLISH_SSH_KEY_PATH:-}" ]] && [[ -f "${INGGLISH_SSH_KEY_PATH}" ]] && [[ -z "${GIT_SSH_COMMAND:-}" ]]; then
|
|
export GIT_SSH_COMMAND="ssh -i ${INGGLISH_SSH_KEY_PATH} -o BatchMode=yes -o StrictHostKeyChecking=accept-new"
|
|
fi
|
|
|
|
if [[ -z "${INGGLISH_LOCK_FILE:-}" ]]; then
|
|
if [[ -d "/var/lib/ingglish-exegesis" ]] && [[ -w "/var/lib/ingglish-exegesis" ]]; then
|
|
LOCK_FILE="/var/lib/ingglish-exegesis/ingglish-exegesis-fedora41.lock"
|
|
else
|
|
LOCK_FILE="${XDG_RUNTIME_DIR:-/tmp}/ingglish-exegesis-fedora41-$(id -u).lock"
|
|
fi
|
|
else
|
|
LOCK_FILE="${INGGLISH_LOCK_FILE}"
|
|
fi
|
|
exec 9>"${LOCK_FILE}"
|
|
if ! flock -n 9; then
|
|
echo "[SKIP] Another ingglish-exegesis-push run holds ${LOCK_FILE}; exiting cleanly."
|
|
exit 0
|
|
fi
|
|
|
|
echo "[1/5] Verifying Fedora 41 environment, OpenRouter API configuration, and workspace directory (${WORKSPACE_DIR})..."
|
|
if [[ -z "${OPENROUTER_API_KEY:-}" ]] && [[ "${DRY_RUN}" -eq 0 ]] && [[ "${ALLOW_FALLBACK}" -eq 0 ]]; then
|
|
echo "[ERROR] OPENROUTER_API_KEY is not set. Configure OPENROUTER_API_KEY in ${SYSCONFIG_FILE} or environment." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "${WORKSPACE_DIR}"
|
|
if [[ "${WORKSPACE_DIR}" == "/var/lib/ingglish-exegesis/workspace" ]] && [[ -w "/var/lib/ingglish-exegesis" ]]; then
|
|
export HOME="/var/lib/ingglish-exegesis"
|
|
fi
|
|
cd "${WORKSPACE_DIR}"
|
|
|
|
sync_or_clone_repo() {
|
|
local repo_dir="$1"
|
|
local remote_url="$2"
|
|
local branch="$3"
|
|
local remote_name="${4:-origin}"
|
|
|
|
if [[ -d "${repo_dir}/.git" ]]; then
|
|
if [[ "${DRY_RUN}" -eq 0 ]]; then
|
|
echo " -> Updating ${repo_dir} (${remote_name}/${branch})..."
|
|
if ! git -C "${repo_dir}" diff --quiet -- README.md 2>&1; then
|
|
git -C "${repo_dir}" checkout -- README.md || true
|
|
fi
|
|
run_checked "git fetch ${repo_dir}" git -C "${repo_dir}" fetch --force "${remote_name}" "${branch}" --tags
|
|
run_checked "git pull --rebase ${repo_dir}" git -C "${repo_dir}" pull --rebase --autostash "${remote_name}" "${branch}"
|
|
fi
|
|
else
|
|
if [[ "${DRY_RUN}" -eq 0 ]]; then
|
|
echo " -> Cloning ${remote_url} (${branch}) into ${repo_dir}..."
|
|
run_checked "git clone ${remote_url}" git clone --branch "${branch}" "${remote_url}" "${repo_dir}"
|
|
else
|
|
echo " -> [dry-run] Would clone ${remote_url} (${branch}) into ${repo_dir}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
echo "[2/5] Synchronizing target repositories from ${FORGE_SSH}..."
|
|
sync_or_clone_repo "${WORKSPACE_DIR}/hyperstitionstudio-core" "${FORGE_SSH}/hyperstitionstudio-core.git" "main" "origin"
|
|
sync_or_clone_repo "${WORKSPACE_DIR}/ingglish-hyperdope-gematria" "${FORGE_SSH}/ingglish-hyperdope-gematria.git" "main" "origin"
|
|
sync_or_clone_repo "${WORKSPACE_DIR}/hyperdope-ci-build" "${FORGE_SSH}/ingglish-hyperdope-ci.git" "feat/ingglish-aq-corpus" "origin"
|
|
sync_or_clone_repo "${WORKSPACE_DIR}/haiperdohp-jemaytreeah" "${FORGE_SSH}/haiperdohp-jemaytreeah.git" "main" "origin"
|
|
|
|
ARCHIVE_REPO="${WORKSPACE_DIR}/ingglish-hyperdope-gematria"
|
|
ARCHIVE_DIR="${ARCHIVE_REPO}/ingglish-aq-archive"
|
|
CI_REPO="${WORKSPACE_DIR}/hyperdope-ci-build"
|
|
CALC_REPO="${WORKSPACE_DIR}/haiperdohp-jemaytreeah"
|
|
export PYTHONPATH="${WORKSPACE_DIR}/hyperstitionstudio-core/src${PYTHONPATH:+:${PYTHONPATH}}"
|
|
|
|
# Ensure offline-vendored ingglish npm runtime is unpacked in ARCHIVE_REPO/node_modules
|
|
if [[ ! -d "${ARCHIVE_REPO}/node_modules/ingglish" ]]; then
|
|
for v_tgz in \
|
|
"${ARCHIVE_REPO}/packaging/bundle/vendor/ingglish-vendor.tgz" \
|
|
"/usr/libexec/ingglish-exegesis/vendor/ingglish-vendor.tgz"; do
|
|
if [[ -f "${v_tgz}" ]]; then
|
|
echo " -> Unpacking offline-vendored ingglish runtime from ${v_tgz}..."
|
|
mkdir -p "${ARCHIVE_REPO}/node_modules"
|
|
run_checked "tar -xzf ${v_tgz}" tar -xzf "${v_tgz}" -C "${ARCHIVE_REPO}/node_modules"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
SCRIPTS_DIR="${ARCHIVE_DIR}/scripts"
|
|
if [[ ! -d "${SCRIPTS_DIR}" ]] && [[ -d "/usr/libexec/ingglish-exegesis/scripts" ]]; then
|
|
SCRIPTS_DIR="/usr/libexec/ingglish-exegesis/scripts"
|
|
elif [[ -d "/usr/libexec/ingglish-exegesis/scripts" ]] && [[ -f "${SCRIPTS_DIR}/ci_provision_ingglish.py" ]] && grep -q 'Path("/workspace/ingglish-hyperdope-gematria/ONBOARDING-INGGLISH-AQ.md")' "${SCRIPTS_DIR}/ci_provision_ingglish.py" 2>&1; then
|
|
SCRIPTS_DIR="/usr/libexec/ingglish-exegesis/scripts"
|
|
fi
|
|
|
|
if [[ "${DRY_RUN}" -eq 1 ]]; then
|
|
echo "[DRY-RUN] Environment, scripts (${SCRIPTS_DIR}), and repository paths verified."
|
|
exit 0
|
|
fi
|
|
|
|
if [[ -d "/var/lib/ingglish-exegesis" ]] && [[ -w "/var/lib/ingglish-exegesis" ]]; then
|
|
HARVEST_JSON="/var/lib/ingglish-exegesis/news-aq-harvest-$$.json"
|
|
else
|
|
HARVEST_JSON="${XDG_RUNTIME_DIR:-/tmp}/news-aq-harvest-$(id -u)-$$.json"
|
|
fi
|
|
trap 'rm -f "${HARVEST_JSON}"' EXIT
|
|
|
|
echo "[3/5] Step A (0 LLM tokens): Harvesting 00:00 UTC news headlines & computing Ingglish Base-36 AQ locks..."
|
|
COLLECT_ARGS=(--mode closing-bell --archive-dir "${ARCHIVE_DIR}" --workdir "${ARCHIVE_REPO}" --out "${HARVEST_JSON}")
|
|
if [[ -n "${TARGET_DATE}" ]]; then
|
|
COLLECT_ARGS+=(--date "${TARGET_DATE}")
|
|
fi
|
|
run_checked "collect_news_aq.py" python3 "${SCRIPTS_DIR}/collect_news_aq.py" "${COLLECT_ARGS[@]}"
|
|
|
|
echo "[4/5] Step B (OpenRouter API ${OPENROUTER_MODEL}) & Step C (4-Gate CI Provisioning)..."
|
|
SYNTH_ARGS=(--harvest "${HARVEST_JSON}" --archive-dir "${ARCHIVE_DIR}" --model "${OPENROUTER_MODEL}" --api-url "${OPENROUTER_API_URL}")
|
|
if [[ "${ALLOW_FALLBACK}" -eq 1 ]]; then
|
|
SYNTH_ARGS+=(--allow-deterministic-fallback)
|
|
fi
|
|
if [[ "${FORCE_RUN}" -eq 1 ]]; then
|
|
SYNTH_ARGS+=(--force)
|
|
fi
|
|
SYNTH_OUT="$(python3 "${SCRIPTS_DIR}/synthesize_news_dossier_openrouter.py" "${SYNTH_ARGS[@]}")"
|
|
echo "${SYNTH_OUT}"
|
|
|
|
RESOLVED_DATE="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1]).get("target_date_utc",""))' "${SYNTH_OUT}")"
|
|
DOSSIER_PATH="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1]).get("dossier_path",""))' "${SYNTH_OUT}")"
|
|
|
|
echo " -> Running Step C: 4-Gate CI Provisioner (ci_provision_ingglish.py --tier 2 --apply-repo)..."
|
|
CI_ARGS=(--archive-dir "${ARCHIVE_DIR}" --out-dir "${CI_REPO}" --tier 2 --generate-docs)
|
|
if [[ -d "${CALC_REPO}/.git" ]]; then
|
|
CI_ARGS+=(--repo-dir "${CALC_REPO}" --apply-repo)
|
|
fi
|
|
run_checked "ci_provision_ingglish.py" python3 "${SCRIPTS_DIR}/ci_provision_ingglish.py" "${CI_ARGS[@]}"
|
|
|
|
if [[ -f "${CALC_REPO}/config.default.js" ]] && [[ ! -f "${CALC_REPO}/config.js" ]]; then
|
|
cp -f "${CALC_REPO}/config.default.js" "${CALC_REPO}/config.js"
|
|
fi
|
|
if [[ -f "${CALC_REPO}/tools/generate_db_json.py" ]] && [[ -f "${CALC_REPO}/db.txt" ]]; then
|
|
(cd "${CALC_REPO}" && run_checked "generate_db_json.py" python3 tools/generate_db_json.py db.txt db.json)
|
|
fi
|
|
|
|
if [[ -d "${WORKSPACE_DIR}/hyperstitionstudio-core/src" ]]; then
|
|
run_checked "hs-readme-sync" python3 -c '
|
|
import os
|
|
from pathlib import Path
|
|
from hyperstitionstud_io.publishing.readme_sync import sync_all_repo_readmes
|
|
|
|
ws = Path(os.environ["WORKSPACE_DIR"])
|
|
for target in ("ingglish-hyperdope-gematria", "hyperdope-ci-build", "haiperdohp-jemaytreeah"):
|
|
sync_all_repo_readmes(ws_root=ws, target_repo=target)
|
|
'
|
|
fi
|
|
|
|
if [[ "${DO_PUSH}" -eq 0 ]]; then
|
|
echo "[5/5] Skipping Git commit & push (--no-push). Synthesized dossier: ${DOSSIER_PATH}"
|
|
exit 0
|
|
fi
|
|
|
|
echo "[5/5] Committing and pushing LLM-populated exegesis artifacts to ${FORGE_SSH}..."
|
|
COMMIT_MSG="Automated 00:00 UTC Exegesis (${RESOLVED_DATE}): Ingest $(basename "${DOSSIER_PATH}") and provision 4-gate Ingglish AQ CI corpus"
|
|
|
|
for entry in \
|
|
"ingglish-hyperdope-gematria:main:origin" \
|
|
"hyperdope-ci-build:feat/ingglish-aq-corpus:origin" \
|
|
"haiperdohp-jemaytreeah:main:origin"; do
|
|
r_name="${entry%%:*}"
|
|
rest="${entry#*:}"
|
|
r_branch="${rest%%:*}"
|
|
r_remote="${rest##*:}"
|
|
r_dir="${WORKSPACE_DIR}/${r_name}"
|
|
if [[ ! -d "${r_dir}/.git" ]]; then
|
|
continue
|
|
fi
|
|
if [[ "${r_name}" == "haiperdohp-jemaytreeah" ]] && git -C "${r_dir}" remote | grep -qx "downstream"; then
|
|
r_remote="downstream"
|
|
fi
|
|
cur_b="$(git -C "${r_dir}" branch --show-current)"
|
|
if [[ -n "${cur_b}" ]] && [[ "${cur_b}" != "${r_branch}" ]]; then
|
|
run_checked "git checkout ${r_branch} (${r_name})" git -C "${r_dir}" checkout "${r_branch}"
|
|
run_checked "git merge --ff-only ${cur_b} (${r_name})" git -C "${r_dir}" merge --ff-only "${cur_b}"
|
|
fi
|
|
git -C "${r_dir}" add -A
|
|
if ! git -C "${r_dir}" diff --cached --quiet; then
|
|
run_checked "git commit (${r_name})" git -C "${r_dir}" commit -m "${COMMIT_MSG}"
|
|
fi
|
|
local_sha="$(git -C "${r_dir}" rev-parse HEAD)"
|
|
remote_sha="$(git -C "${r_dir}" rev-parse "${r_remote}/${r_branch}" 2>&1 || echo "")"
|
|
if [[ "${local_sha}" != "${remote_sha}" ]]; then
|
|
run_checked "git pull --rebase (${r_name})" git -C "${r_dir}" pull --rebase --autostash "${r_remote}" "${r_branch}"
|
|
run_checked "git push (${r_name})" git -C "${r_dir}" push "${r_remote}" "${r_branch}"
|
|
echo " -> Pushed ${r_name} (${r_remote}/${r_branch})"
|
|
else
|
|
echo " -> No new changes to push in ${r_name}"
|
|
fi
|
|
done
|
|
|
|
echo "[OK] Fedora 41 00:00 UTC exegesis harvest, OpenRouter synthesis, 4-gate CI provisioning, and Git push complete (${RESOLVED_DATE})."
|