Files
proxmox/scripts/besu/deploy-genesis-and-node-lists-to-rpcs.sh
defiQUG 0d29343941 chore: update .env.master.example with new deployment scripts and treasury manager parameters; enhance AGENTS.md with GRU reference primacy details
- Added new deployment script references for Aave quote-push and treasury manager in .env.master.example.
- Updated AGENTS.md to include information on GRU reference primacy versus public PMM mesh execution model.
- Minor updates to various documentation files to reflect changes in policy and operational guidelines.

Made-with: Cursor
2026-04-12 18:20:41 -07:00

112 lines
4.3 KiB
Bash

#!/usr/bin/env bash
# Deploy canonical genesis.json, static-nodes.json, permissions-nodes.toml to selected RPC VMIDs
# and restart Besu.
# Usage:
# bash scripts/besu/deploy-genesis-and-node-lists-to-rpcs.sh
# bash scripts/besu/deploy-genesis-and-node-lists-to-rpcs.sh --vmid 2401
# bash scripts/besu/deploy-genesis-and-node-lists-to-rpcs.sh --apply --vmid 2401
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
DRY_RUN=true
TARGET_VMIDS=()
usage() {
cat <<'EOF'
Usage: bash scripts/besu/deploy-genesis-and-node-lists-to-rpcs.sh [--apply] [--dry-run] [--vmid <N>]
Options:
--dry-run Print intended actions only (default)
--apply Deploy files and restart Besu on selected RPC nodes
--vmid <N> Limit to one VMID; repeatable
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
shift
;;
--apply)
DRY_RUN=false
shift
;;
--vmid)
[[ $# -ge 2 ]] || { usage >&2; exit 2; }
TARGET_VMIDS+=("$2")
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
RPC_VMIDS=(2401 2402 2403 2420 2430 2440 2460 2470 2480)
GENESIS="${PROJECT_ROOT}/smom-dbis-138-proxmox/config/genesis.json"
STATIC="${PROJECT_ROOT}/config/besu-node-lists/static-nodes.json"
PERMS="${PROJECT_ROOT}/config/besu-node-lists/permissions-nodes.toml"
SSH_OPTS="-o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new"
[[ ! -f "$GENESIS" ]] && { echo "ERROR: $GENESIS not found"; exit 1; }
[[ ! -f "$STATIC" ]] && { echo "ERROR: $STATIC not found"; exit 1; }
[[ ! -f "$PERMS" ]] && { echo "ERROR: $PERMS not found"; exit 1; }
selected_vmid() {
local vmid="$1"
[[ ${#TARGET_VMIDS[@]} -eq 0 ]] && return 0
local wanted
for wanted in "${TARGET_VMIDS[@]}"; do
[[ "$vmid" == "$wanted" ]] && return 0
done
return 1
}
echo "Deploying genesis.json + static-nodes.json + permissions-nodes.toml to selected RPC VMIDs"
if $DRY_RUN; then echo " [dry-run]"; fi
echo ""
for vmid in "${RPC_VMIDS[@]}"; do
selected_vmid "$vmid" || continue
host="$(get_host_for_vmid "$vmid")"
[[ -z "$host" ]] && { echo "VMID $vmid: no host"; continue; }
running=$(ssh $SSH_OPTS "root@$host" "pct status $vmid 2>/dev/null | awk '{print \$2}'" 2>/dev/null || echo "")
if [[ "$running" != "running" ]]; then
echo "VMID $vmid @ $host: skip (not running)"
continue
fi
echo "--- VMID $vmid @ $host ---"
if $DRY_RUN; then
echo " [dry-run] would deploy files and restart Besu"
continue
fi
scp -q $SSH_OPTS "$GENESIS" "$STATIC" "$PERMS" "root@${host}:/tmp/" || { echo " scp failed"; continue; }
ssh $SSH_OPTS "root@$host" "pct exec $vmid -- mkdir -p /etc/besu"
ssh $SSH_OPTS "root@$host" "pct push $vmid /tmp/genesis.json /etc/besu/genesis.json && pct push $vmid /tmp/static-nodes.json /etc/besu/static-nodes.json && pct push $vmid /tmp/permissions-nodes.toml /etc/besu/permissions-nodes.toml"
ssh $SSH_OPTS "root@$host" "pct exec $vmid -- chown besu:besu /etc/besu/genesis.json /etc/besu/static-nodes.json /etc/besu/permissions-nodes.toml 2>/dev/null || pct exec $vmid -- chown root:root /etc/besu/genesis.json /etc/besu/static-nodes.json /etc/besu/permissions-nodes.toml"
# Point config to /etc/besu/ (any .toml in /etc/besu/)
ssh $SSH_OPTS "root@$host" "pct exec $vmid -- sed -i 's|genesis-file=.*|genesis-file=\"/etc/besu/genesis.json\"|; s|static-nodes-file=.*|static-nodes-file=\"/etc/besu/static-nodes.json\"|; s|permissions-nodes-config-file=.*|permissions-nodes-config-file=\"/etc/besu/permissions-nodes.toml\"|' /etc/besu/*.toml 2>/dev/null || true"
# Restart Besu
result=$(ssh $SSH_OPTS "root@$host" "pct exec $vmid -- bash -c 'svc=\$(systemctl list-units --type=service --no-legend 2>/dev/null | grep -iE \"besu-validator|besu-sentry|besu-rpc|besu\\.service\" | head -1 | awk \"{print \\\$1}\"); if [ -n \"\$svc\" ]; then systemctl restart \"\$svc\" && echo \"OK:\$svc\"; else echo \"NONE\"; fi'" 2>/dev/null || echo "FAIL")
if [[ "$result" == OK:* ]]; then
echo " deployed + restarted (${result#OK:})"
else
echo " deployed; restart result: $result"
fi
ssh $SSH_OPTS "root@$host" "rm -f /tmp/genesis.json /tmp/static-nodes.json /tmp/permissions-nodes.toml"
done
echo ""
echo "Done."