#!/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 calc/db.json if absent, creates top-level route symlinks, and pre-compresses (.br / .gz). # # Usage: # ./sync-vps-repos.sh all # Pull from git.libre.audio, audit & sync all 5 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}" # Use sudo only when writing to a root-owned target directory as a non-root user 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 5th 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" "${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 echo "[1/4] Updating ${REPOS_ROOT}/${repo} (${branch})..." git -C "${REPOS_ROOT}/${repo}" fetch origin "${branch}" --tags git -C "${REPOS_ROOT}/${repo}" merge --ff-only "origin/${branch}" fi done 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 # Ensure canonical ingglish-hyperdope-ci directory name exists in LIVE_REPOS if sourced from hyperdope-ci-build 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 "ingglish-hyperdope-ci" "${LIVE_REPOS}/ci" ${SUDO} ln -sfn "hyperstitionstudio-core/schemas" "${LIVE_REPOS}/schemas" echo "[4/4] Pre-compressing HTML, JS, JSON, XML, Canvas, MD & CSS assets (.br / .gz)..." ${SUDO} find "${LIVE_REPOS}" -type f \ \( -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 \ \( -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}"