#!/usr/bin/env bash # Apply public RPC config to VMID 2201 (besu-rpc-public-1). # Ensures no permissions allow contract deployment: account permissioning enabled # with empty allowlist (permissions-accounts-public.toml). # Run from project root; requires pct (typically on Proxmox host). set -euo pipefail VMID=2201 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" SOURCE_CONFIG="$PROJECT_ROOT/smom-dbis-138/config" CONFIG_RPC_PUBLIC="$SOURCE_CONFIG/config-rpc-public.toml" PERM_ACCOUNTS_PUBLIC="$SOURCE_CONFIG/permissions-accounts-public.toml" PERM_NODES="$SOURCE_CONFIG/permissions-nodes.toml" log() { echo "[INFO] $1"; } success() { echo "[✓] $1"; } warn() { echo "[WARN] $1"; } err() { echo "[ERROR] $1"; } if [[ ! -f "$CONFIG_RPC_PUBLIC" ]]; then err "Config not found: $CONFIG_RPC_PUBLIC" exit 1 fi if [[ ! -f "$PERM_ACCOUNTS_PUBLIC" ]]; then err "Permissions file not found: $PERM_ACCOUNTS_PUBLIC" exit 1 fi if ! pct status "$VMID" &>/dev/null; then err "VMID $VMID not found or pct not available (run on Proxmox host?)." exit 1 fi if ! pct status "$VMID" 2>/dev/null | grep -q running; then warn "VMID $VMID is not running. Start it first, then re-run." exit 1 fi log "Applying public RPC config to VMID $VMID (no contract deployment)..." # Copy main config (paths in config use /data/besu, /genesis/, /permissions/) pct push "$VMID" "$CONFIG_RPC_PUBLIC" "/etc/besu/config-rpc-public.toml" pct exec "$VMID" -- chown besu:besu /etc/besu/config-rpc-public.toml 2>/dev/null || true # Ensure /permissions exists and copy permissions-accounts-public.toml pct exec "$VMID" -- mkdir -p /permissions pct push "$VMID" "$PERM_ACCOUNTS_PUBLIC" "/permissions/permissions-accounts-public.toml" pct exec "$VMID" -- chown -R besu:besu /permissions 2>/dev/null || true if [[ -f "$PERM_NODES" ]]; then pct push "$VMID" "$PERM_NODES" "/permissions/permissions-nodes.toml" pct exec "$VMID" -- chown besu:besu /permissions/permissions-nodes.toml 2>/dev/null || true fi # Point systemd to config-rpc-public.toml if besu-rpc.service exists if pct exec "$VMID" -- systemctl cat besu-rpc.service &>/dev/null; then pct exec "$VMID" -- bash -c 'sed -i "s|--config-file=\$BESU_CONFIG/[^ ]*|--config-file=\$BESU_CONFIG/config-rpc-public.toml|g" /etc/systemd/system/besu-rpc.service 2>/dev/null || true' pct exec "$VMID" -- systemctl daemon-reload log "Restarting besu-rpc.service..." pct exec "$VMID" -- systemctl restart besu-rpc.service success "Config applied and besu-rpc restarted." else log "besu-rpc.service not found; config files are in place. Restart Besu manually if needed." success "Config files applied." fi