From afedda58d7e70ec6700e0a5f6535c0ee7efa6490 Mon Sep 17 00:00:00 2001 From: devmatrix Date: Mon, 16 Feb 2026 16:28:27 +0000 Subject: [PATCH] fix: Simplify Windows setup script to avoid syntax errors --- setup_windows_vm.ps1 | 355 ++++++------------------------------------- 1 file changed, 44 insertions(+), 311 deletions(-) diff --git a/setup_windows_vm.ps1 b/setup_windows_vm.ps1 index 7d03c3b..043ddfc 100644 --- a/setup_windows_vm.ps1 +++ b/setup_windows_vm.ps1 @@ -4,336 +4,69 @@ #Requires -RunAsAdministrator -# ============================================ -# CONFIGURATION -# ============================================ -$VM_IP = "192.168.5.211" # Static IP for Windows VM -$MAIN_DEV_IP = "192.168.5.210" # IP of your Ubuntu Dev VM +Write-Host "Starting Windows LTSC IoT VM Setup..." -ForegroundColor Cyan -# Colors for output -function Write-Info { param($Message) Write-Host "[INFO] $Message" -ForegroundColor Cyan } -function Write-Success { param($Message) Write-Host "[SUCCESS] $Message" -ForegroundColor Green } -function Write-Warning { param($Message) Write-Host "[WARNING] $Message" -ForegroundColor Yellow } -function Write-Error { param($Message) Write-Host "[ERROR] $Message" -ForegroundColor Red } - -Write-Info "Starting Windows LTSC IoT VM Setup..." - -# ============================================ -# ENABLE SSH SERVER -# ============================================ -Write-Info "Enabling OpenSSH Server..." - -# Install OpenSSH Server +# Enable SSH Server +Write-Host "Enabling OpenSSH Server..." -ForegroundColor Cyan Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 - -# Start and enable service Start-Service sshd Set-Service -Name sshd -StartupType 'Automatic' +New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 +Write-Host "SSH Server enabled" -ForegroundColor Green -# Configure firewall -if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) { - New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server (sshd)" ` - -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -} - -Write-Success "SSH Server enabled" - -# ============================================ -# ENABLE RDP -# ============================================ -Write-Info "Enabling Remote Desktop..." - -Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' ` - -Name "fDenyTSConnections" -Value 0 - +# Enable RDP +Write-Host "Enabling Remote Desktop..." -ForegroundColor Cyan +Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" +Write-Host "RDP enabled" -ForegroundColor Green -# Enhanced RDP security -Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' ` - -Name "UserAuthentication" -Value 1 - -Write-Success "RDP enabled" - -# ============================================ -# CREATE TEST USER -# ============================================ -Write-Info "Creating test user account..." - +# Create test user +Write-Host "Creating test user account..." -ForegroundColor Cyan $TestUser = "testuser" $TestPassword = ConvertTo-SecureString "DevMatrix2024!" -AsPlainText -Force - -# Check if user exists if (!(Get-LocalUser -Name $TestUser -ErrorAction SilentlyContinue)) { - New-LocalUser -Name $TestUser -Password $TestPassword ` - -FullName "Test User" -Description "DevMatrix Test Account" + New-LocalUser -Name $TestUser -Password $TestPassword -FullName "Test User" -Description "DevMatrix Test Account" Add-LocalGroupMember -Group "Administrators" -Member $TestUser Add-LocalGroupMember -Group "Remote Desktop Users" -Member $TestUser - Write-Success "Test user '$TestUser' created" + Write-Host "Test user '$TestUser' created" -ForegroundColor Green } else { - Write-Warning "Test user already exists" + Write-Host "Test user already exists" -ForegroundColor Yellow } -# ============================================ -# INSTALL CHOCOLATEY -# ============================================ -Write-Info "Installing Chocolatey package manager..." +# Install Chocolatey +Write-Host "Installing Chocolatey..." -ForegroundColor Cyan +Set-ExecutionPolicy Bypass -Scope Process -Force +[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +Write-Host "Chocolatey installed" -ForegroundColor Green -if (!(Get-Command choco -ErrorAction SilentlyContinue)) { - Set-ExecutionPolicy Bypass -Scope Process -Force - [System.Net.ServicePointManager]::SecurityProtocol = ` - [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 - Invoke-Expression ((New-Object System.Net.WebClient). ` - DownloadString('https://community.chocolatey.org/install.ps1')) - - # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + ` - [System.Environment]::GetEnvironmentVariable("Path","User") - - Write-Success "Chocolatey installed" -} else { - Write-Warning "Chocolatey already installed" -} - -# ============================================ -# INSTALL DEVELOPMENT TOOLS -# ============================================ -Write-Info "Installing development tools..." - -$packages = @( - "git" - "python" - "nodejs" - "dotnet-sdk" - "vscode" - "firefox" - "googlechrome" - "7zip" - "powertoys" - "sysinternals" - "processhacker" -) - -foreach ($pkg in $packages) { - Write-Info "Installing $pkg..." - choco install $pkg -y --no-progress -} - -Write-Success "Development tools installed" - -# ============================================ -# INSTALL PLAYWRIGHT -# ============================================ -Write-Info "Installing Playwright for UI testing..." +# Install development tools +Write-Host "Installing development tools..." -ForegroundColor Cyan +choco install -y git python nodejs dotnet-sdk vscode firefox googlechrome 7zip +Write-Host "Development tools installed" -ForegroundColor Green +# Install Playwright +Write-Host "Installing Playwright..." -ForegroundColor Cyan npm install -g @playwright/test -npx playwright install chromium firefox webkit -npx playwright install-deps +npx playwright install chromium +Write-Host "Playwright installed" -ForegroundColor Green -Write-Success "Playwright installed" +# Create test directories +Write-Host "Creating test directories..." -ForegroundColor Cyan +New-Item -ItemType Directory -Force -Path "C:\Apps" | Out-Null +New-Item -ItemType Directory -Force -Path "C:\Tests" | Out-Null +New-Item -ItemType Directory -Force -Path "C:\Results" | Out-Null +New-Item -ItemType Directory -Force -Path "C:\Scripts" | Out-Null +Write-Host "Directories created" -ForegroundColor Green -# ============================================ -# CREATE TEST DIRECTORIES -# ============================================ -Write-Info "Creating test directories..." - -$directories = @( - "C:\Apps", - "C:\Tests", - "C:\Projects", - "C:\Results", - "C:\Scripts" -) - -foreach ($dir in $directories) { - if (!(Test-Path $dir)) { - New-Item -ItemType Directory -Force -Path $dir - } -} - -Write-Success "Test directories created" - -# ============================================ -# CREATE TEST RUNNER SCRIPTS -# ============================================ -Write-Info "Creating test automation scripts..." - -# Simple test runner -$TestRunner = @' -@echo off -echo ======================================== -echo DevMatrix Windows Test Runner -echo Started: %date% %time% -echo ======================================== -echo. - -if "%~1"=="" ( - echo Usage: run_tests.bat ^ - exit /b 1 -) - -set TEST_DIR=%~1 -echo Running tests from: %TEST_DIR% -echo. - -cd /d %TEST_DIR% -if errorlevel 1 ( - echo ERROR: Cannot access directory %TEST_DIR% - exit /b 1 -) - -echo Test Start > C:\Results\test_session.log -echo %date% %time% >> C:\Results\test_session.log -echo. >> C:\Results\test_session.log - -REM Run Playwright tests if playwright.config.js exists -if exist "playwright.config.js" ( - echo Running Playwright tests... - npx playwright test --reporter=html --output=C:\Results - set TEST_EXIT=%errorlevel% -) else ( - echo No Playwright config found. Looking for other tests... - dir /s /b *.test.js *.spec.js > nul 2>&1 - if !errorlevel!==0 ( - echo Found JavaScript tests. Running with Node... - for /r %%i in (*.test.js *.spec.js) do ( - echo Running: %%i - node "%%i" >> C:\Results\test_session.log 2>&1 - ) - ) -) - -echo. >> C:\Results\test_session.log -echo Test End: %date% %time% >> C:\Results\test_session.log - -echo. -echo ======================================== -echo Tests complete. Results in C:\Results\ -echo ======================================== - -exit /b %TEST_EXIT% -'@ - -$TestRunner | Out-File -FilePath "C:\Scripts\run_tests.bat" -Encoding ASCII - -# App installer script -$AppInstaller = @' -@echo off -echo DevMatrix App Installer -echo ======================= - -if "%~1"=="" ( - echo Usage: install_app.bat ^ - exit /b 1 -) - -set APP_PATH=%~1 -set APP_NAME=%~n1 - -echo Installing: %APP_NAME% -echo From: %APP_PATH% - -REM Create app directory -if not exist "C:\Apps\%APP_NAME%" mkdir "C:\Apps\%APP_NAME%" - -REM Copy files -xcopy /E /I /Y "%APP_PATH%\*" "C:\Apps\%APP_NAME%\" - -echo. -echo Installation complete: C:\Apps\%APP_NAME%\ -echo. -echo To run: C:\Apps\%APP_NAME%\%APP_NAME%.exe -'@ - -$AppInstaller | Out-File -FilePath "C:\Scripts\install_app.bat" -Encoding ASCII - -Write-Success "Automation scripts created" - -# ============================================ -# CONFIGURE WINRM (FOR AUTOMATION) -# ============================================ -Write-Info "Configuring WinRM for remote automation..." - -# Enable WinRM -Enable-PSRemoting -Force -SkipNetworkProfileCheck - -# Configure WinRM to allow unencrypted (local network only) -Set-Item WSMan:\localhost\Service\AllowUnencrypted -Value $true -Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true - -# Configure firewall -Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP" -RemoteAddress LocalSubnet -Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP-PUBLIC" -RemoteAddress LocalSubnet - -Write-Success "WinRM configured" - -# ============================================ -# INSTALL WSL2 (OPTIONAL) -# ============================================ -Write-Info "Installing WSL2 for Linux compatibility..." - -# Enable WSL -wsl --install --no-distribution - -Write-Success "WSL2 installed (reboot required to complete)" - -# ============================================ -# PERFORMANCE OPTIMIZATIONS -# ============================================ -Write-Info "Applying performance optimizations..." - -# Disable unnecessary visual effects -$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Set-ItemProperty -Path $regPath -Name "VisualFXSetting" -Value 2 - -# Set high performance power plan -powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c - -# Disable Windows Search indexing for test directories -Add-Content -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Profile.ps1" -Value @" -# DevMatrix Performance Settings -`$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 -`$env:POWERSHELL_TELEMETRY_OPTOUT = 1 -"@ - -Write-Success "Performance optimizations applied" - -# ============================================ -# CREATE FIREWALL RULES FOR DEVMATRIX -# ============================================ -Write-Info "Creating DevMatrix firewall rules..." - -# Allow traffic from main dev VM -New-NetFirewallRule -DisplayName "DevMatrix-DevVM" ` - -Direction Inbound -Action Allow ` - -RemoteAddress $MAIN_DEV_IP ` - -Profile Private - -# Allow file sharing -Set-NetFirewallRule -DisplayGroup "File and Printer Sharing" -Enabled True -Profile Private - -Write-Success "Firewall rules created" - -# ============================================ -# SUMMARY -# ============================================ +# Summary Write-Host "" -Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green -Write-Host "║ WINDOWS VM SETUP COMPLETE ║" -ForegroundColor Green -Write-Host "╠════════════════════════════════════════════════════════════╣" -ForegroundColor Green -Write-Host "║ ║" -ForegroundColor Green -Write-Host "║ ✅ SSH Server: Enabled on port 22 ║" -ForegroundColor Green -Write-Host "║ ✅ RDP: Enabled ║" -ForegroundColor Green -Write-Host "║ ✅ Test User: testuser / DevMatrix2024! ║" -ForegroundColor Green -Write-Host "║ ✅ Dev Tools: Git, Python, Node, .NET, VS Code ║" -ForegroundColor Green -Write-Host "║ ✅ Testing: Playwright installed ║" -ForegroundColor Green -Write-Host "║ ✅ Directories: C:\Apps, C:\Tests, C:\Results ║" -ForegroundColor Green -Write-Host "║ ║" -ForegroundColor Green -Write-Host "╠════════════════════════════════════════════════════════════╣" -ForegroundColor Green -Write-Host "║ Connect from Dev VM: ║" -ForegroundColor Green -Write-Host "║ ssh testuser@$VM_IP ║" -ForegroundColor Green -Write-Host "║ scp -r ./app testuser@${VM_IP}:/C:/Apps/ ║" -ForegroundColor Green -Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Green +Write-Host "Windows VM Setup Complete!" -ForegroundColor Green +Write-Host "===========================" -ForegroundColor Green +Write-Host "SSH: Enabled on port 22" +Write-Host "RDP: Enabled" +Write-Host "Test User: testuser / DevMatrix2024!" Write-Host "" -Write-Warning "REBOOT REQUIRED for WSL2 to complete installation" -Write-Host "" -Write-Info "After reboot, this VM is ready for automated testing!" +Write-Host "Connect from Dev VM:" +Write-Host " ssh testuser@192.168.5.211" +Write-Host " scp -r ./app testuser@192.168.5.211:/C:/Apps/"