#!/bin/bash # MongoDB Migration Web Interface # Serves migration progress at ROOT_URL/migration-progress # Source settings source $SNAP/bin/wekan-read-settings # Configuration MIGRATION_STATUS="${SNAP_COMMON}/mongodb-migration-status.json" MIGRATION_LOG="${SNAP_COMMON}/mongodb-migration-log.txt" MIGRATION_PROGRESS="${SNAP_COMMON}/mongodb-migration-progress.html" PORT="${MIGRATION_WEB_PORT:-8081}" # Create a simple HTTP server using netcat and bash serve_migration_progress() { while true; do { echo "HTTP/1.1 200 OK" echo "Content-Type: text/html; charset=utf-8" echo "Cache-Control: no-cache" echo "Connection: close" echo "" # Generate HTML page if [ -f "$MIGRATION_STATUS" ]; then local status=$(jq -r '.status' "$MIGRATION_STATUS" 2>/dev/null || echo "unknown") local step=$(jq -r '.step' "$MIGRATION_STATUS" 2>/dev/null || echo "0") local total_steps=$(jq -r '.total_steps' "$MIGRATION_STATUS" 2>/dev/null || echo "0") local percentage=$(jq -r '.percentage' "$MIGRATION_STATUS" 2>/dev/null || echo "0") local description=$(jq -r '.description' "$MIGRATION_STATUS" 2>/dev/null || echo "Unknown") local timestamp=$(jq -r '.timestamp' "$MIGRATION_STATUS" 2>/dev/null || echo "Unknown") cat << EOF MongoDB Migration Progress

MongoDB Migration Progress

Migrating from MongoDB 3 to MongoDB 7

${percentage}%

Status: ${status}

Progress: $step of $total_steps steps

Current Step: $description

Last Updated: $timestamp

Migration Log (Last 20 lines):

$(tail -20 "$MIGRATION_LOG" 2>/dev/null || echo "No log available")

This page will refresh automatically every 5 seconds.
Migration URL: ${ROOT_URL:-http://localhost:8080}/migration-progress

EOF else cat << EOF MongoDB Migration Progress

MongoDB Migration

No migration in progress.

This page will refresh automatically every 5 seconds.

EOF fi } | nc -l -p "$PORT" -q 1 done } # Start the web server serve_migration_progress