#!/usr/bin/env bash # Pre-startup Validator Prerequisites Check # Validates all required files and configurations before starting Besu set -euo pipefail # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_info() { echo -e "${GREEN}[INFO]${NC} $1"; } check_file() { local file=$1 local description=$2 if [ -f "$file" ]; then log_info "$description: OK ($file)" return 0 else log_error "$description: MISSING ($file)" return 1 fi } fix_missing_file() { local file=$1 local description=$2 local fallback=$3 if [ ! -f "$file" ]; then log_warn "Fixing missing $description..." if [ -f "$fallback" ]; then mkdir -p "$(dirname "$file")" ln -sf "$fallback" "$file" log_info "Created symlink: $file -> $fallback" else log_error "Cannot fix: $description missing and no fallback" return 1 fi fi } main() { local errors=0 # Check genesis file if ! check_file "/genesis/genesis.json" "Genesis file"; then fix_missing_file "/genesis/genesis.json" "genesis file" "/etc/besu/genesis.json" || ((errors++)) fi # Check static-nodes file if ! check_file "/genesis/static-nodes.json" "Static nodes file"; then fix_missing_file "/genesis/static-nodes.json" "static-nodes file" "/etc/besu/static-nodes.json" || { # Create empty file if no fallback mkdir -p /genesis echo "[]" > /genesis/static-nodes.json log_info "Created empty static-nodes.json" } fi # Check permissions file if ! check_file "/permissions/permissions-accounts.toml" "Permissions file"; then fix_missing_file "/permissions/permissions-accounts.toml" "permissions file" "/etc/besu/permissions-accounts.toml" || { # Create proper empty file mkdir -p /permissions cat > /permissions/permissions-accounts.toml < /permissions/permissions-accounts.toml <