#!/usr/bin/env bash # Complete Chain 138 RPC setup using .env: DNS → NPMplus create/update → verify. # Run from repo root. Requires: .env with Cloudflare + NPMplus credentials. # See: docs/04-configuration/NEXT_STEPS_CHAIN138_RPC.md set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_ROOT" # Child scripts load .env themselves. Load here only for skip-logic checks. # Preserve NPM credentials from environment so "export NPM_PASSWORD=...; ./script" works even if .env has empty NPM_* _orig_npm_email="${NPM_EMAIL:-}" _orig_npm_password="${NPM_PASSWORD:-}" if [ -f .env ]; then set +u set -a # shellcheck source=/dev/null source .env 2>/dev/null || true set +a set -u [ -n "$_orig_npm_email" ] && export NPM_EMAIL="$_orig_npm_email" [ -n "$_orig_npm_password" ] && export NPM_PASSWORD="$_orig_npm_password" fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔧 Complete Chain 138 RPC Setup (from .env)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # 1. Cloudflare DNS: rpc + wss.defi-oracle.io and all RPC domains → PUBLIC_IP echo "📋 Step 1: Cloudflare DNS (all zones → PUBLIC_IP, DNS only)" if [ -z "${CLOUDFLARE_API_TOKEN:-}" ] && { [ -z "${CLOUDFLARE_EMAIL:-}" ] || [ -z "${CLOUDFLARE_API_KEY:-}" ]; }; then echo " ⚠️ Skipped: set CLOUDFLARE_API_TOKEN or (CLOUDFLARE_EMAIL + CLOUDFLARE_API_KEY) in .env" else if [ -z "${CLOUDFLARE_ZONE_ID_DEFI_ORACLE_IO:-}" ]; then echo " ⚠️ Skipped defi-oracle.io: set CLOUDFLARE_ZONE_ID_DEFI_ORACLE_IO in .env" fi "$SCRIPT_DIR/update-all-dns-to-public-ip.sh" || true fi echo "" # 2. NPMplus: create rpc.d-bis.org / rpc2.d-bis.org / ws.* and defi-oracle hosts if missing echo "📋 Step 2a: NPMplus – create rpc.d-bis.org / rpc2.d-bis.org / ws.* proxy hosts if missing" if [ -z "${NPM_PASSWORD:-}" ]; then echo " ⚠️ Skipped: set NPM_PASSWORD in .env" else "$SCRIPT_DIR/nginx-proxy-manager/create-npmplus-rpc-d-bis-hosts.sh" || true fi echo "" echo "📋 Step 2b: NPMplus – create Defi Oracle proxy hosts if missing" if [ -z "${NPM_PASSWORD:-}" ]; then echo " ⚠️ Skipped: set NPM_PASSWORD in .env" else "$SCRIPT_DIR/nginx-proxy-manager/create-npmplus-defi-oracle-hosts.sh" || true fi echo "" # 3. NPMplus: update all proxy hosts (forward_host/port, WebSocket) echo "📋 Step 3: NPMplus – update all proxy hosts" if [ -z "${NPM_PASSWORD:-}" ]; then echo " ⚠️ Skipped: set NPM_PASSWORD in .env" else "$SCRIPT_DIR/nginx-proxy-manager/update-npmplus-proxy-hosts-api.sh" || true fi echo "" # 4. NPMplus: request Let's Encrypt SSL for proxy hosts (incl. rpc/wss.defi-oracle.io) echo "📋 Step 4: NPMplus – request SSL certificates for proxy hosts" if [ -z "${NPM_PASSWORD:-}" ]; then echo " ⚠️ Skipped: set NPM_PASSWORD in .env" else "$SCRIPT_DIR/request-npmplus-certificates.sh" || true fi echo "" # 5. Verify public RPC echo "📋 Step 5: Verify public RPC (eth_chainId)" "$SCRIPT_DIR/fix-rpc-chain138-npmplus.sh" 2>/dev/null || true echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "Done. See docs/04-configuration/NEXT_STEPS_CHAIN138_RPC.md for UDM Pro port forwarding and Chainlist." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"