Files
proxmox/scripts/cleanup-empty-comments.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

173 lines
5.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Cleanup Empty Comment Sections in Besu Config Files
# Removes empty comment headers left after deprecated option cleanup
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Dry-run mode flag
DRY_RUN="${1:-}"
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Function to backup a file
backup_file() {
local file="$1"
if [ -f "$file" ]; then
local backup="${file}.backup.$(date +%Y%m%d_%H%M%S)"
if [ "$DRY_RUN" != "--dry-run" ]; then
cp "$file" "$backup"
echo "$backup"
else
echo "${file}.backup.TIMESTAMP"
fi
fi
}
# Function to clean empty comment sections
clean_empty_comments() {
local file="$1"
if [ ! -f "$file" ]; then
log_warn "File not found: $file (skipping)"
return 1
fi
# Count empty sections before cleanup
local empty_before=$(grep -cE '^#[^#]' "$file" 2>/dev/null | awk '{s+=$1} END {print s+0}' || echo "0")
log_info "Cleaning empty comment sections from: $file"
if [ "$DRY_RUN" != "--dry-run" ]; then
# Backup file
local backup=$(backup_file "$file")
log_info " Backup created: $backup"
# Use Python to clean empty comments more reliably
# Pattern: comment line followed by blank lines until next section/key
python3 <<EOF
import re
with open('$file', 'r') as f:
lines = f.readlines()
cleaned = []
i = 0
while i < len(lines):
line = lines[i]
# Check if this is a comment line starting with #
if re.match(r'^\s*#.*', line) and not re.match(r'^\s*##', line):
# Look ahead to see if this comment is followed by empty lines and then another section
j = i + 1
empty_count = 0
# Count consecutive empty lines
while j < len(lines) and lines[j].strip() == '':
empty_count += 1
j += 1
# Check if next non-empty line is a section header [section] or a new key/value
if j < len(lines):
next_line = lines[j]
# If next line is a section header or new key/value, this comment is standalone
if re.match(r'^\s*\[', next_line) or re.match(r'^\s*[a-zA-Z]', next_line):
# This is an empty comment section - skip it and empty lines
i = j
continue
cleaned.append(line)
i += 1
# Write cleaned content back
with open('$file', 'w') as f:
f.writelines(cleaned)
EOF
log_success " Empty comment sections removed"
return 0
else
log_info " [DRY-RUN] Would remove empty comment sections"
# Show what would be removed
grep -nE '^#.*' "$file" | grep -A 2 -B 2 '^[0-9]*:\s*#' | head -10
return 0
fi
}
# Main execution
echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ BESU CONFIG EMPTY COMMENTS CLEANUP ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
if [ "$DRY_RUN" == "--dry-run" ]; then
log_warn "DRY-RUN MODE: No files will be modified"
echo ""
fi
# Track statistics
CLEANED=0
SKIPPED=0
# All config files
CONFIG_FILES=(
"$PROJECT_ROOT/smom-dbis-138/config/config-validator.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-core.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-public.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-perm.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-thirdweb.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-4.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-putu-1.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-putu-8a.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-luis-1.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-rpc-luis-8a.toml"
"$PROJECT_ROOT/smom-dbis-138/config/config-member.toml"
"$PROJECT_ROOT/smom-dbis-138-proxmox/templates/besu-configs/config-validator.toml"
"$PROJECT_ROOT/smom-dbis-138-proxmox/templates/besu-configs/config-rpc-core.toml"
"$PROJECT_ROOT/smom-dbis-138-proxmox/templates/besu-configs/config-rpc.toml"
"$PROJECT_ROOT/smom-dbis-138-proxmox/templates/besu-configs/config-rpc-4.toml"
"$PROJECT_ROOT/smom-dbis-138-proxmox/templates/besu-configs/config-sentry.toml"
)
for file in "${CONFIG_FILES[@]}"; do
if clean_empty_comments "$file"; then
CLEANED=$((CLEANED + 1))
else
SKIPPED=$((SKIPPED + 1))
fi
echo ""
done
# Summary
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}Summary${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo "Files cleaned: $CLEANED"
echo "Files skipped: $SKIPPED"
echo ""
if [ "$DRY_RUN" == "--dry-run" ]; then
log_warn "This was a dry-run. No files were modified."
echo "Run without --dry-run to apply changes."
else
log_success "Empty comment cleanup complete!"
echo ""
echo "Next steps:"
echo " 1. Review cleaned configuration files"
echo " 2. Validate configs still pass validation"
fi