fix: Simplify Windows setup script to avoid syntax errors
This commit is contained in:
parent
3a2cdaca3a
commit
afedda58d7
|
|
@ -4,336 +4,69 @@
|
||||||
|
|
||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
# ============================================
|
Write-Host "Starting Windows LTSC IoT VM Setup..." -ForegroundColor Cyan
|
||||||
# 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
|
|
||||||
|
|
||||||
# Colors for output
|
# Enable SSH Server
|
||||||
function Write-Info { param($Message) Write-Host "[INFO] $Message" -ForegroundColor Cyan }
|
Write-Host "Enabling OpenSSH Server..." -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
|
|
||||||
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
|
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
|
||||||
|
|
||||||
# Start and enable service
|
|
||||||
Start-Service sshd
|
Start-Service sshd
|
||||||
Set-Service -Name sshd -StartupType 'Automatic'
|
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
|
# Enable RDP
|
||||||
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
|
Write-Host "Enabling Remote Desktop..." -ForegroundColor Cyan
|
||||||
New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server (sshd)" `
|
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
|
||||||
-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-NetFirewallRule -DisplayGroup "Remote Desktop"
|
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
|
||||||
|
Write-Host "RDP enabled" -ForegroundColor Green
|
||||||
|
|
||||||
# Enhanced RDP security
|
# Create test user
|
||||||
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' `
|
Write-Host "Creating test user account..." -ForegroundColor Cyan
|
||||||
-Name "UserAuthentication" -Value 1
|
|
||||||
|
|
||||||
Write-Success "RDP enabled"
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# CREATE TEST USER
|
|
||||||
# ============================================
|
|
||||||
Write-Info "Creating test user account..."
|
|
||||||
|
|
||||||
$TestUser = "testuser"
|
$TestUser = "testuser"
|
||||||
$TestPassword = ConvertTo-SecureString "DevMatrix2024!" -AsPlainText -Force
|
$TestPassword = ConvertTo-SecureString "DevMatrix2024!" -AsPlainText -Force
|
||||||
|
|
||||||
# Check if user exists
|
|
||||||
if (!(Get-LocalUser -Name $TestUser -ErrorAction SilentlyContinue)) {
|
if (!(Get-LocalUser -Name $TestUser -ErrorAction SilentlyContinue)) {
|
||||||
New-LocalUser -Name $TestUser -Password $TestPassword `
|
New-LocalUser -Name $TestUser -Password $TestPassword -FullName "Test User" -Description "DevMatrix Test Account"
|
||||||
-FullName "Test User" -Description "DevMatrix Test Account"
|
|
||||||
Add-LocalGroupMember -Group "Administrators" -Member $TestUser
|
Add-LocalGroupMember -Group "Administrators" -Member $TestUser
|
||||||
Add-LocalGroupMember -Group "Remote Desktop Users" -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 {
|
} else {
|
||||||
Write-Warning "Test user already exists"
|
Write-Host "Test user already exists" -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
# ============================================
|
# Install Chocolatey
|
||||||
# INSTALL CHOCOLATEY
|
Write-Host "Installing Chocolatey..." -ForegroundColor Cyan
|
||||||
# ============================================
|
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||||
Write-Info "Installing Chocolatey package manager..."
|
[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)) {
|
# Install development tools
|
||||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
Write-Host "Installing development tools..." -ForegroundColor Cyan
|
||||||
[System.Net.ServicePointManager]::SecurityProtocol = `
|
choco install -y git python nodejs dotnet-sdk vscode firefox googlechrome 7zip
|
||||||
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
Write-Host "Development tools installed" -ForegroundColor Green
|
||||||
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 Playwright
|
||||||
|
Write-Host "Installing Playwright..." -ForegroundColor Cyan
|
||||||
npm install -g @playwright/test
|
npm install -g @playwright/test
|
||||||
npx playwright install chromium firefox webkit
|
npx playwright install chromium
|
||||||
npx playwright install-deps
|
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
|
||||||
|
|
||||||
# ============================================
|
# Summary
|
||||||
# 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 ^<test-directory^>
|
|
||||||
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 ^<path-to-app-files^>
|
|
||||||
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
|
|
||||||
# ============================================
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green
|
Write-Host "Windows VM Setup Complete!" -ForegroundColor Green
|
||||||
Write-Host "║ WINDOWS VM SETUP COMPLETE ║" -ForegroundColor Green
|
Write-Host "===========================" -ForegroundColor Green
|
||||||
Write-Host "╠════════════════════════════════════════════════════════════╣" -ForegroundColor Green
|
Write-Host "SSH: Enabled on port 22"
|
||||||
Write-Host "║ ║" -ForegroundColor Green
|
Write-Host "RDP: Enabled"
|
||||||
Write-Host "║ ✅ SSH Server: Enabled on port 22 ║" -ForegroundColor Green
|
Write-Host "Test User: testuser / DevMatrix2024!"
|
||||||
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 ""
|
Write-Host ""
|
||||||
Write-Warning "REBOOT REQUIRED for WSL2 to complete installation"
|
Write-Host "Connect from Dev VM:"
|
||||||
Write-Host ""
|
Write-Host " ssh testuser@192.168.5.211"
|
||||||
Write-Info "After reboot, this VM is ready for automated testing!"
|
Write-Host " scp -r ./app testuser@192.168.5.211:/C:/Apps/"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue