Files
proxmox/scripts/xdc-zero/merge-endpointconfig-chain138.sh
defiQUG 6390174bb7 feat(xdc-zero): Chain 138 bridge runbook, config fragments, merge helper
- Add CHAIN138_XDC_ZERO_BRIDGE_RUNBOOK and 07-ccip pointer doc
- Add config/xdc-zero templates, parent register fragment, README
- Add merge-endpointconfig-chain138.sh (jq merge, XDC_ZERO_ENDPOINT_DIR)
- Add xdc-zero-chain138-preflight.sh; trim XDC URL vars in load-project-env
- Wire AGENTS.md, MASTER_INDEX, verify README, .env.master.example

Made-with: Cursor
2026-03-31 23:10:36 -07:00

81 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Merge Chain 138 XDC-Zero fragments into an existing endpointconfig.json (upstream XDC-Zero layout).
# Requires jq. Backs up the target file unless --dry-run or explicit stdout.
#
# Usage:
# bash scripts/xdc-zero/merge-endpointconfig-chain138.sh path/to/endpointconfig.json
# bash scripts/xdc-zero/merge-endpointconfig-chain138.sh path/to/endpointconfig.json path/to/out.json
# bash scripts/xdc-zero/merge-endpointconfig-chain138.sh path/to/endpointconfig.json --dry-run
# bash scripts/xdc-zero/merge-endpointconfig-chain138.sh --dry-run path/to/endpointconfig.json
# Or set XDC_ZERO_ENDPOINT_DIR to an XDC-Zero/endpoint clone path (uses .../endpointconfig.json).
#
# Sources: config/xdc-zero/endpointconfig.fragment.chain138.example.json,
# config/xdc-zero/xdcparentnet-register-chain138.fragment.json
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
FRAG="$PROJECT_ROOT/config/xdc-zero/endpointconfig.fragment.chain138.example.json"
REG_FRAG="$PROJECT_ROOT/config/xdc-zero/xdcparentnet-register-chain138.fragment.json"
DRY_RUN=false
BASE=""
OUT=""
POSITIONAL=()
for a in "$@"; do
if [[ "$a" == "--dry-run" ]]; then
DRY_RUN=true
else
POSITIONAL+=("$a")
fi
done
if [[ ${#POSITIONAL[@]} -ge 1 ]]; then
BASE="${POSITIONAL[0]}"
fi
if [[ ${#POSITIONAL[@]} -ge 2 ]]; then
OUT="${POSITIONAL[1]}"
fi
if [[ -z "$BASE" && -n "${XDC_ZERO_ENDPOINT_DIR:-}" ]]; then
BASE="${XDC_ZERO_ENDPOINT_DIR%/}/endpointconfig.json"
fi
if [[ -z "$BASE" || ! -f "$BASE" ]]; then
echo "Usage: $0 <endpointconfig.json> [out.json] [--dry-run]" >&2
echo " Or: XDC_ZERO_ENDPOINT_DIR=/path/to/XDC-Zero/endpoint $0 [--dry-run]" >&2
exit 1
fi
if [[ ! -f "$FRAG" || ! -f "$REG_FRAG" ]]; then
echo "ERROR: missing fragment under config/xdc-zero/" >&2
exit 1
fi
command -v jq >/dev/null 2>&1 || { echo "ERROR: jq required" >&2; exit 1; }
_step1="$(jq --slurpfile f "$FRAG" '.chain138 = $f[0].chain138' "$BASE")"
MERGED="$(printf '%s\n' "$_step1" | jq --slurpfile r "$REG_FRAG" '
(if .xdcparentnet == null then . + {xdcparentnet: {registers: []}} else . end)
| .xdcparentnet.registers += $r[0]
')"
_c138_count="$(printf '%s' "$MERGED" | jq '[.xdcparentnet.registers[]? | select(.chainId == 138)] | length')"
if [[ "${_c138_count:-0}" -gt 1 ]]; then
echo "WARN: xdcparentnet.registers has ${_c138_count} entries with chainId 138 — review manually." >&2
fi
if $DRY_RUN; then
printf '%s\n' "$MERGED"
exit 0
fi
if [[ -n "$OUT" ]]; then
printf '%s\n' "$MERGED" >"$OUT"
echo "Wrote $OUT"
exit 0
fi
cp -a "$BASE" "${BASE}.bak.$(date +%Y%m%d%H%M%S)"
printf '%s\n' "$MERGED" >"$BASE"
echo "Merged into $BASE (backup beside file)."