|
|
|
@@ -1,13 +1,12 @@
|
|
|
|
|
#!/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.
|
|
|
|
|
# supplies untracked haiperdohp-jemaytreeah/.gitignore files (config.js, db.json, db_lite.json),
|
|
|
|
|
# creates top-level route symlinks, pre-compresses (.br / .gz) static assets, and idempotently
|
|
|
|
|
# syncs/validates/reloads /etc/caddy/Caddyfile and systemd units by default (negated via --no-caddy).
|
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
# ./sync-vps-repos.sh [all|<repo-name>] [--no-pull] [--no-caddy|--no-services]
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
|
|
@@ -15,10 +14,27 @@ 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}"
|
|
|
|
|
|
|
|
|
|
TARGET_REPO="all"
|
|
|
|
|
DO_PULL=1
|
|
|
|
|
DO_CADDY=1
|
|
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
|
case "${arg}" in
|
|
|
|
|
--no-pull)
|
|
|
|
|
DO_PULL=0
|
|
|
|
|
;;
|
|
|
|
|
--no-caddy|--no-services)
|
|
|
|
|
DO_CADDY=0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
TARGET_REPO="${arg}"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
SUDO=""
|
|
|
|
|
if [[ "${EUID:-$(id -u)}" -ne 0 ]] && [[ ! -w "$(dirname "${LIVE_REPOS}")" ]] && command -v sudo >/dev/null 2>&1; then
|
|
|
|
|
if [[ "${EUID:-$(id -u)}" -ne 0 ]] && command -v sudo >/dev/null 2>&1; then
|
|
|
|
|
SUDO="sudo"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@@ -46,7 +62,7 @@ REPOS=(
|
|
|
|
|
"${CI_REPO_DIR}:feat/ingglish-aq-corpus"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if [[ "${TARGET_REPO}" != "--no-pull" ]]; then
|
|
|
|
|
if [[ "${DO_PULL}" -eq 1 ]]; then
|
|
|
|
|
for entry in "${REPOS[@]}"; do
|
|
|
|
|
repo="${entry%%:*}"
|
|
|
|
|
branch="${entry##*:}"
|
|
|
|
@@ -58,7 +74,7 @@ if [[ "${TARGET_REPO}" != "--no-pull" ]]; then
|
|
|
|
|
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})..."
|
|
|
|
|
echo "[1/5] 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
|
|
|
|
@@ -77,47 +93,102 @@ if [[ -d "${REPOS_ROOT}/haiperdohp-jemaytreeah" ]]; then
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "[2/4] Running hs-doctor and 6-Gate Knowledge Graph Verification..."
|
|
|
|
|
echo "[2/5] 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}"
|
|
|
|
|
echo "[3/5] Syncing per-repository install directories into ${LIVE_REPOS}..."
|
|
|
|
|
LIVE_SUDO=""
|
|
|
|
|
if [[ ! -w "$(dirname "${LIVE_REPOS}")" ]] && [[ -n "${SUDO}" ]]; then
|
|
|
|
|
LIVE_SUDO="${SUDO}"
|
|
|
|
|
fi
|
|
|
|
|
${LIVE_SUDO} mkdir -p "${LIVE_REPOS}"
|
|
|
|
|
for entry in "${REPOS[@]}"; do
|
|
|
|
|
repo="${entry%%:*}"
|
|
|
|
|
if [[ "${TARGET_REPO}" != "all" && "${TARGET_REPO}" != "--no-pull" && "${TARGET_REPO}" != "${repo}" ]]; then
|
|
|
|
|
if [[ "${TARGET_REPO}" != "all" && "${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}/"
|
|
|
|
|
${LIVE_SUDO} mkdir -p "${LIVE_REPOS}/${repo}"
|
|
|
|
|
${LIVE_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"
|
|
|
|
|
${LIVE_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 "hyperstitionstudio-core/site/learn" "${LIVE_REPOS}/learn"
|
|
|
|
|
${SUDO} ln -sfn "hyperstitionstudio-core/site/gallery" "${LIVE_REPOS}/gallery"
|
|
|
|
|
${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"
|
|
|
|
|
# Create relative route symlinks inside LIVE_REPOS so both Caddy and standalone HTTP servers resolve all active routes
|
|
|
|
|
${LIVE_SUDO} ln -sfn "hyperstitionstudio-core/site/index.html" "${LIVE_REPOS}/index.html"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "hyperstitionstudio-core/site/learn" "${LIVE_REPOS}/learn"
|
|
|
|
|
# Note: /gallery is disabled for now (tracked as a long-term plan in docs/PLAN-MEMETIC-GALLERY-SUBPAGE.pdf)
|
|
|
|
|
${LIVE_SUDO} rm -rf "${LIVE_REPOS}/gallery" "${LIVE_REPOS}/hyperstitionstudio-core/site/gallery"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "encyclopedia-knowledge-graph" "${LIVE_REPOS}/graph"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "technocapital-singularity-zoology/encyclopedia" "${LIVE_REPOS}/encyclopedia"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "technocapital-singularity-zoology" "${LIVE_REPOS}/zoology"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "ingglish-hyperdope-gematria/ingglish-aq-archive" "${LIVE_REPOS}/archive"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "haiperdohp-jemaytreeah" "${LIVE_REPOS}/calc"
|
|
|
|
|
${LIVE_SUDO} ln -sfn "ingglish-hyperdope-ci" "${LIVE_REPOS}/ci"
|
|
|
|
|
${LIVE_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 \
|
|
|
|
|
echo "[4/5] Pre-compressing static HTML, JS, JSON, XML, Canvas, MD & CSS assets (< 5 MB) (.br / .gz)..."
|
|
|
|
|
${LIVE_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 \
|
|
|
|
|
${LIVE_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
|
|
|
|
|
|
|
|
|
|
# Step 5: Idempotent systemd unit & /etc/caddy/Caddyfile synchronization (enabled by default; skip with --no-caddy)
|
|
|
|
|
if [[ "${DO_CADDY}" -eq 1 ]]; then
|
|
|
|
|
DEPLOY_DIR="${REPOS_ROOT}/hyperstitionstudio-core/deploy"
|
|
|
|
|
if command -v systemctl >/dev/null 2>&1 && [[ -d "/run/systemd/system" ]]; then
|
|
|
|
|
UNITS_CHANGED=0
|
|
|
|
|
for unit_name in "hyperstition-tmpfs-sync.service" "hyperstition-mcp.service"; do
|
|
|
|
|
src_u="${DEPLOY_DIR}/${unit_name}"
|
|
|
|
|
dst_u="/etc/systemd/system/${unit_name}"
|
|
|
|
|
if [[ -f "${src_u}" ]] && ! cmp -s "${src_u}" "${dst_u}" 2>/dev/null; then
|
|
|
|
|
echo "[5/5] Updating systemd unit ${dst_u}..."
|
|
|
|
|
${SUDO} cp "${src_u}" "${dst_u}"
|
|
|
|
|
UNITS_CHANGED=1
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if [[ "${UNITS_CHANGED}" -eq 1 ]]; then
|
|
|
|
|
${SUDO} systemctl daemon-reload
|
|
|
|
|
${SUDO} systemctl enable hyperstition-tmpfs-sync.service >/dev/null 2>&1 || true
|
|
|
|
|
${SUDO} systemctl enable --now hyperstition-mcp.service >/dev/null 2>&1 || true
|
|
|
|
|
${SUDO} systemctl restart hyperstition-mcp.service >/dev/null 2>&1 || true
|
|
|
|
|
elif ! systemctl is-active --quiet hyperstition-mcp.service 2>/dev/null && [[ -f "/etc/systemd/system/hyperstition-mcp.service" ]]; then
|
|
|
|
|
${SUDO} systemctl enable --now hyperstition-mcp.service >/dev/null 2>&1 || true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
SRC_CADDY="${DEPLOY_DIR}/Caddyfile"
|
|
|
|
|
DST_CADDY="/etc/caddy/Caddyfile"
|
|
|
|
|
if command -v caddy >/dev/null 2>&1 && [[ -d "/etc/caddy" ]] && [[ -f "${SRC_CADDY}" ]]; then
|
|
|
|
|
if cmp -s "${SRC_CADDY}" "${DST_CADDY}" 2>/dev/null; then
|
|
|
|
|
echo "[5/5] /etc/caddy/Caddyfile is already identical to deploy/Caddyfile (no reload needed)."
|
|
|
|
|
else
|
|
|
|
|
echo "[5/5] Validating and updating ${DST_CADDY} from ${SRC_CADDY}..."
|
|
|
|
|
${SUDO} caddy validate --config "${SRC_CADDY}" --adapter caddyfile >/dev/null
|
|
|
|
|
${SUDO} cp "${SRC_CADDY}" "${DST_CADDY}"
|
|
|
|
|
if command -v systemctl >/dev/null 2>&1 && [[ -d "/run/systemd/system" ]]; then
|
|
|
|
|
if systemctl is-active --quiet caddy 2>/dev/null; then
|
|
|
|
|
${SUDO} systemctl reload caddy
|
|
|
|
|
echo "[5/5] Reloaded Caddy with updated /etc/caddy/Caddyfile."
|
|
|
|
|
else
|
|
|
|
|
${SUDO} systemctl enable --now caddy
|
|
|
|
|
echo "[5/5] Started Caddy with updated /etc/caddy/Caddyfile."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "[5/5] Caddy or /etc/caddy not present on this host; skipping Caddyfile reload."
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "[5/5] Skipping Caddyfile & systemd service sync (--no-caddy)."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "[OK] Per-repository install directories hydrated and pre-compressed at ${LIVE_REPOS}"
|