Files
hyperstitionstudio-core/deploy/sync-vps-repos.sh
T

122 lines
5.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# /workspace/hyperstitionstudio-core/deploy/sync-vps-repos.sh
# Hydrates per-repository install directories from REPOS_ROOT into LIVE_REPOS (tmpfs RAM mount),
# builds haiperdohp-jemaytreeah/db_lite.json if absent, creates top-level route symlinks, and
# pre-compresses (.br / .gz) static assets.
#
# Usage:
# ./sync-vps-repos.sh all # Pull from git.libre.audio, audit & sync all repos
# ./sync-vps-repos.sh encyclopedia-knowledge-graph # Pull, audit & sync a single repo
# ./sync-vps-repos.sh --no-pull # Audit & sync existing local clones without network fetch
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
DEFAULT_REPOS_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
export REPOS_ROOT="${REPOS_ROOT:-${DEFAULT_REPOS_ROOT}}"
export LIVE_REPOS="${LIVE_REPOS:-/var/www/hyperstitionstud.io/repos}"
TARGET_REPO="${1:-all}"
SUDO=""
if [[ "${EUID:-$(id -u)}" -ne 0 ]] && [[ ! -w "$(dirname "${LIVE_REPOS}")" ]] && command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
fi
PYTHON_BIN="python3"
if [[ -x "${REPOS_ROOT}/.venv/bin/python3" ]]; then
PYTHON_BIN="${REPOS_ROOT}/.venv/bin/python3"
fi
export PYTHONPATH="${REPOS_ROOT}/hyperstitionstudio-core/src${PYTHONPATH:+:${PYTHONPATH}}"
if [[ -f "${REPOS_ROOT}/workspace.toml" ]]; then
export HYPERSTITIONSTUDIO_CONFIG="${REPOS_ROOT}/workspace.toml"
fi
# Detect whether the CI artifact repository is cloned as ingglish-hyperdope-ci or hyperdope-ci-build
CI_REPO_DIR="ingglish-hyperdope-ci"
if [[ ! -d "${REPOS_ROOT}/${CI_REPO_DIR}" ]] && [[ -d "${REPOS_ROOT}/hyperdope-ci-build" ]]; then
CI_REPO_DIR="hyperdope-ci-build"
fi
REPOS=(
"hyperstitionstudio-core:main"
"ingglish-hyperdope-gematria:main"
"technocapital-singularity-zoology:main"
"encyclopedia-knowledge-graph:main"
"haiperdohp-jemaytreeah:main"
"${CI_REPO_DIR}:feat/ingglish-aq-corpus"
)
if [[ "${TARGET_REPO}" != "--no-pull" ]]; then
for entry in "${REPOS[@]}"; do
repo="${entry%%:*}"
branch="${entry##*:}"
if [[ "${TARGET_REPO}" != "all" && "${TARGET_REPO}" != "${repo}" ]]; then
continue
fi
if [[ -d "${REPOS_ROOT}/${repo}/.git" ]]; then
remote_name="origin"
if [[ "${repo}" == "haiperdohp-jemaytreeah" ]] && git -C "${REPOS_ROOT}/${repo}" remote get-url downstream >/dev/null 2>&1; then
remote_name="downstream"
fi
echo "[1/4] Updating ${REPOS_ROOT}/${repo} (${remote_name}/${branch})..."
git -C "${REPOS_ROOT}/${repo}" fetch --force "${remote_name}" "${branch}" --tags
git -C "${REPOS_ROOT}/${repo}" merge --ff-only "${remote_name}/${branch}"
fi
done
fi
# Supply untracked files listed in haiperdohp-jemaytreeah/.gitignore (config.js, db.json, db_lite.json)
if [[ -d "${REPOS_ROOT}/haiperdohp-jemaytreeah" ]]; then
if [[ ! -f "${REPOS_ROOT}/haiperdohp-jemaytreeah/config.js" ]] && [[ -f "${REPOS_ROOT}/haiperdohp-jemaytreeah/config.default.js" ]]; then
echo "[build] Copying haiperdohp-jemaytreeah/config.default.js -> config.js..."
cp "${REPOS_ROOT}/haiperdohp-jemaytreeah/config.default.js" "${REPOS_ROOT}/haiperdohp-jemaytreeah/config.js"
fi
if [[ ! -f "${REPOS_ROOT}/haiperdohp-jemaytreeah/db_lite.json" || ! -f "${REPOS_ROOT}/haiperdohp-jemaytreeah/db.json" ]] && [[ -f "${REPOS_ROOT}/haiperdohp-jemaytreeah/tools/generate_db_json.py" ]]; then
echo "[build] Generating haiperdohp-jemaytreeah/db.json and db_lite.json from db.txt..."
(cd "${REPOS_ROOT}/haiperdohp-jemaytreeah" && "${PYTHON_BIN}" tools/generate_db_json.py db.txt db.json)
fi
fi
echo "[2/4] Running hs-doctor and 6-Gate Knowledge Graph Verification..."
"${PYTHON_BIN}" -m hyperstitionstud_io.ci.doctor >/dev/null
"${PYTHON_BIN}" "${REPOS_ROOT}/encyclopedia-knowledge-graph/scripts/build_encyclopedia_knowledge_graph.py" --verify-only >/dev/null
echo "[3/4] Syncing per-repository install directories into ${LIVE_REPOS}..."
${SUDO} mkdir -p "${LIVE_REPOS}"
for entry in "${REPOS[@]}"; do
repo="${entry%%:*}"
if [[ "${TARGET_REPO}" != "all" && "${TARGET_REPO}" != "--no-pull" && "${TARGET_REPO}" != "${repo}" ]]; then
continue
fi
if [[ -d "${REPOS_ROOT}/${repo}" ]]; then
${SUDO} mkdir -p "${LIVE_REPOS}/${repo}"
${SUDO} rsync -a --delete --exclude='.git' "${REPOS_ROOT}/${repo}/" "${LIVE_REPOS}/${repo}/"
fi
done
if [[ "${CI_REPO_DIR}" == "hyperdope-ci-build" ]] && [[ -d "${LIVE_REPOS}/hyperdope-ci-build" ]] && [[ ! -e "${LIVE_REPOS}/ingglish-hyperdope-ci" ]]; then
${SUDO} ln -sfn "hyperdope-ci-build" "${LIVE_REPOS}/ingglish-hyperdope-ci"
fi
# Create relative route symlinks inside LIVE_REPOS so both Caddy and standalone HTTP servers resolve all routes
${SUDO} ln -sfn "hyperstitionstudio-core/site/index.html" "${LIVE_REPOS}/index.html"
${SUDO} ln -sfn "encyclopedia-knowledge-graph" "${LIVE_REPOS}/graph"
${SUDO} ln -sfn "technocapital-singularity-zoology/encyclopedia" "${LIVE_REPOS}/encyclopedia"
${SUDO} ln -sfn "technocapital-singularity-zoology" "${LIVE_REPOS}/zoology"
${SUDO} ln -sfn "ingglish-hyperdope-gematria/ingglish-aq-archive" "${LIVE_REPOS}/archive"
${SUDO} ln -sfn "haiperdohp-jemaytreeah" "${LIVE_REPOS}/calc"
${SUDO} ln -sfn "ingglish-hyperdope-ci" "${LIVE_REPOS}/ci"
${SUDO} ln -sfn "hyperstitionstudio-core/schemas" "${LIVE_REPOS}/schemas"
echo "[4/4] Pre-compressing static HTML, JS, JSON, XML, Canvas, MD & CSS assets (< 5 MB) (.br / .gz)..."
${SUDO} find "${LIVE_REPOS}" -type f -size -5M \
\( -name "*.html" -o -name "*.js" -o -name "*.json" -o -name "*.graphml" -o -name "*.gexf" -o -name "*.canvas" -o -name "*.css" -o -name "*.md" \) \
-exec gzip -9 -k -f {} \;
if command -v brotli >/dev/null 2>&1; then
${SUDO} find "${LIVE_REPOS}" -type f -size -5M \
\( -name "*.html" -o -name "*.js" -o -name "*.json" -o -name "*.graphml" -o -name "*.gexf" -o -name "*.canvas" -o -name "*.css" -o -name "*.md" \) \
-exec brotli -q 11 -k -f {} \;
fi
echo "[OK] Per-repository install directories hydrated and pre-compressed at ${LIVE_REPOS}"