install.ps1 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # ==============================================================================
  2. # lf_mri_platform — One-time installation script
  3. # Run as: .\install.ps1
  4. # Requires: Windows 10/11, PowerShell 5.1+, internet access
  5. # ==============================================================================
  6. param(
  7. [string]$PythonExe = "python",
  8. [string]$GuiDir = "..\lf_mri\MRI-testing\lf_mri_gui",
  9. [string]$RepoRoot = "..\lf_mri\MRI-testing"
  10. )
  11. $ErrorActionPreference = "Stop"
  12. function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
  13. function Write-OK($msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
  14. function Write-Warn($msg) { Write-Host " [!!] $msg" -ForegroundColor Yellow }
  15. function Write-Fail($msg) { Write-Host " [FAIL] $msg" -ForegroundColor Red; exit 1 }
  16. # ── 1. Check prerequisites ────────────────────────────────────────────────────
  17. Write-Step "Checking prerequisites"
  18. # Python
  19. try {
  20. $pyVer = & $PythonExe --version 2>&1
  21. if ($pyVer -match "3\.(1[0-9]|[0-9]+)") {
  22. Write-OK "Python: $pyVer"
  23. } else {
  24. Write-Fail "Python 3.10+ required, found: $pyVer"
  25. }
  26. } catch {
  27. Write-Fail "Python not found. Install from https://python.org (add to PATH)"
  28. }
  29. # Docker
  30. try {
  31. $dockerVer = & docker --version 2>&1
  32. Write-OK "Docker: $dockerVer"
  33. } catch {
  34. Write-Warn "Docker not found — services (orchestrator, seq_interp, etc.) won't start."
  35. Write-Warn "Install Docker Desktop: https://www.docker.com/products/docker-desktop/"
  36. }
  37. # Docker Compose
  38. try {
  39. $composeVer = & docker compose version 2>&1
  40. Write-OK "Docker Compose: $composeVer"
  41. } catch {
  42. Write-Warn "Docker Compose not found (included in Docker Desktop >= 3.0)"
  43. }
  44. # ── 2. Create Python virtual environment for the GUI ─────────────────────────
  45. Write-Step "Creating Python virtual environment"
  46. $venvPath = Join-Path $GuiDir ".venv"
  47. $absGuiDir = Resolve-Path $GuiDir -ErrorAction SilentlyContinue
  48. if (-not $absGuiDir) { Write-Fail "GUI directory not found: $GuiDir" }
  49. if (Test-Path $venvPath) {
  50. Write-Warn "Venv already exists at $venvPath — skipping creation"
  51. } else {
  52. & $PythonExe -m venv $venvPath
  53. Write-OK "Created venv at $venvPath"
  54. }
  55. $pip = Join-Path $venvPath "Scripts\pip.exe"
  56. # ── 3. Install GUI dependencies ───────────────────────────────────────────────
  57. Write-Step "Installing GUI dependencies"
  58. # Install root requirements first (numpy, scipy, etc.)
  59. $rootReqs = Join-Path $RepoRoot "requirements.txt"
  60. if (Test-Path $rootReqs) {
  61. & $pip install -r $rootReqs --quiet
  62. Write-OK "Root requirements installed"
  63. }
  64. # Install GUI-specific requirements
  65. $guiReqs = Join-Path $GuiDir "requirements.txt"
  66. if (Test-Path $guiReqs) {
  67. & $pip install -r $guiReqs --quiet
  68. Write-OK "GUI requirements installed"
  69. }
  70. # Install LF_scanner as editable package
  71. $lfScannerSetup = Join-Path $RepoRoot "LF_scanner\setup.py"
  72. if (Test-Path $lfScannerSetup) {
  73. & $pip install -e (Join-Path $RepoRoot "LF_scanner") --quiet
  74. Write-OK "LF_scanner installed (editable)"
  75. } else {
  76. Write-Warn "LF_scanner/setup.py not found — skipping"
  77. }
  78. # ── 4. Copy .env for Docker services ─────────────────────────────────────────
  79. Write-Step "Setting up Docker environment config"
  80. $envFile = Join-Path $PSScriptRoot ".env"
  81. $envExample = Join-Path $PSScriptRoot ".env.example"
  82. if (-not (Test-Path $envFile)) {
  83. Copy-Item $envExample $envFile
  84. Write-OK ".env created from .env.example"
  85. } else {
  86. Write-Warn ".env already exists — not overwriting"
  87. }
  88. # ── 5. Create desktop shortcut ────────────────────────────────────────────────
  89. Write-Step "Creating desktop shortcuts"
  90. $desktopPath = [Environment]::GetFolderPath("Desktop")
  91. $pythonExePath = Join-Path $venvPath "Scripts\python.exe"
  92. $appScript = Resolve-Path (Join-Path $GuiDir "app.py")
  93. # Shortcut: Start GUI only
  94. $wsh = New-Object -ComObject WScript.Shell
  95. $sc = $wsh.CreateShortcut("$desktopPath\LF-MRI GUI.lnk")
  96. $sc.TargetPath = $pythonExePath
  97. $sc.Arguments = "`"$appScript`""
  98. $sc.WorkingDirectory = (Resolve-Path $RepoRoot).Path
  99. $sc.Description = "LF-MRI System GUI"
  100. $sc.Save()
  101. Write-OK "Shortcut: 'LF-MRI GUI.lnk' on Desktop"
  102. # Shortcut: Start all (services + GUI)
  103. $startAll = Resolve-Path (Join-Path $PSScriptRoot "start.ps1")
  104. $scAll = $wsh.CreateShortcut("$desktopPath\LF-MRI Start All.lnk")
  105. $scAll.TargetPath = "powershell.exe"
  106. $scAll.Arguments = "-ExecutionPolicy Bypass -File `"$startAll`""
  107. $scAll.WorkingDirectory = $PSScriptRoot
  108. $scAll.Description = "Start LF-MRI services + GUI"
  109. $scAll.Save()
  110. Write-OK "Shortcut: 'LF-MRI Start All.lnk' on Desktop"
  111. # ── 6. Summary ────────────────────────────────────────────────────────────────
  112. Write-Host ""
  113. Write-Host "============================================================" -ForegroundColor Green
  114. Write-Host " Installation complete!" -ForegroundColor Green
  115. Write-Host "============================================================" -ForegroundColor Green
  116. Write-Host ""
  117. Write-Host " Next steps:"
  118. Write-Host " 1. Start all services + GUI: .\start.ps1"
  119. Write-Host " 2. GUI only (no services): .\start.ps1 -GuiOnly"
  120. Write-Host " 3. Stop services: .\stop.ps1"
  121. Write-Host ""
  122. Write-Host " Config: edit .env to change ports or switch mode (plug/real)"
  123. Write-Host ""