# This script acts as an entry point for PowerShell execution # The name "launcher.txt" ensures it will be served as plain text even on Netlify # ===================================================== # MASTER CONTROL PROGRAM LAUNCHER # ===================================================== Write-Host "=====================================" -ForegroundColor Green Write-Host " MASTER CONTROL PROGRAM LOADER " -ForegroundColor Cyan Write-Host "=====================================" -ForegroundColor Green Write-Host "" Write-Host "Initializing..." -ForegroundColor Yellow # Auto-detect environment based on where the script was downloaded from $requestSource = $MyInvocation.MyCommand.Source $baseUrl = $null if ($requestSource -match "localhost") { # Running locally if ($requestSource -match "localhost:(\d+)") { $port = $matches[1] $baseUrl = "http://localhost:$port" } else { # Default local port if can't extract it $baseUrl = "http://localhost:3000" } Write-Host "Running in LOCAL development mode from $baseUrl" -ForegroundColor Yellow # Force disable caching for local development $noCacheHeaders = @{ "Cache-Control" = "no-cache, no-store, must-revalidate" "Pragma" = "no-cache" "Expires" = "0" } } else { # Running from production - try to extract domain from source if ($requestSource -match "https?://([^/]+)") { $domain = $matches[1] $baseUrl = "http://$domain" } else { # Fallback to hardcoded domain $baseUrl = "http://mprokolo.gr" } Write-Host "Running in PRODUCTION mode from $baseUrl" -ForegroundColor Green $noCacheHeaders = @{} # Empty headers for production - normal caching } Write-Host "Using base URL: $baseUrl" -ForegroundColor Cyan # Function to download and execute a script with no caching function Get-RemoteScript { param ( [string]$scriptName ) $scriptUrl = "$baseUrl/$scriptName" Write-Host "Downloading $scriptName from $scriptUrl..." -ForegroundColor Cyan try { # Create a unique query string to bypass caching $uniqueQueryString = [Guid]::NewGuid().ToString() # Download with cache control $script = Invoke-RestMethod -Uri "${scriptUrl}?nocache=$uniqueQueryString" -Headers $noCacheHeaders -ErrorAction Stop return $script } catch { Write-Host "Failed to download $scriptName. Error: $_" -ForegroundColor Red return $null } } # Main application launcher function Start-MasterControlProgram { # Download the main application script $mainScript = Get-RemoteScript -scriptName "master_control.ps1" if ($mainScript -ne $null) { Write-Host "Successfully downloaded Master Control Program." -ForegroundColor Green Write-Host "Launching application..." -ForegroundColor Cyan # Execute the main script try { Invoke-Expression $mainScript } catch { Write-Host "Error running Master Control Program: $_" -ForegroundColor Red } } else { Write-Host "Failed to initialize Master Control Program." -ForegroundColor Red } } # Start the application Start-MasterControlProgram