|
| 1 | +# Check if running as Administrator |
| 2 | +$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) |
| 3 | +if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { |
| 4 | + Write-Host "This script must be run as Administrator. Please re-run PowerShell as Administrator." -ForegroundColor Red |
| 5 | + exit 1 |
| 6 | +} |
| 7 | + |
| 8 | +Write-Host "Starting Windows setup..." -ForegroundColor Yellow |
| 9 | + |
| 10 | +function Test-Command($command) { |
| 11 | + try { Get-Command $command -ErrorAction Stop; return $true } catch { return $false } |
| 12 | +} |
| 13 | + |
| 14 | +function Install-Chocolatey { |
| 15 | + Set-ExecutionPolicy Bypass -Scope Process -Force |
| 16 | + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 |
| 17 | + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) |
| 18 | +} |
| 19 | + |
| 20 | +# ---- Install Chocolatey if not installed ---- |
| 21 | +if (-not (Test-Command choco)) { |
| 22 | + Write-Host "Chocolatey is not installed. Installing..." -ForegroundColor Yellow |
| 23 | + Install-Chocolatey |
| 24 | +} else { |
| 25 | + Write-Host "Chocolatey is already installed." -ForegroundColor Green |
| 26 | +} |
| 27 | + |
| 28 | +# Refresh PATH environment variable |
| 29 | +$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 30 | + |
| 31 | +# ---- Install Visual Studio Build Tools (if not present) ---- |
| 32 | +Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Yellow |
| 33 | +winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621" |
| 34 | + |
| 35 | +# ---- Check if Visual C++ Build Tools (cl.exe) are available ---- |
| 36 | +$vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC" |
| 37 | +if (Test-Path $vsPath) { |
| 38 | + $latestVersion = (Get-ChildItem $vsPath | Sort-Object Name -Descending | Select-Object -First 1).Name |
| 39 | + $clPath = Join-Path -Path $vsPath -ChildPath "$latestVersion\bin\Hostx64\x64\cl.exe" |
| 40 | + |
| 41 | + if (Test-Path $clPath) { |
| 42 | + Write-Host "Visual C++ Build Tools found at: $clPath" -ForegroundColor Green |
| 43 | + # Add to PATH if not already there |
| 44 | + $env:Path = "$vsPath\$latestVersion\bin\Hostx64\x64;$env:Path" |
| 45 | + } else { |
| 46 | + Write-Host "Visual C++ Build Tools (cl.exe) not found." -ForegroundColor Red |
| 47 | + Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow |
| 48 | + Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow |
| 49 | + Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow |
| 50 | + Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow |
| 51 | + } |
| 52 | +} else { |
| 53 | + Write-Host "Visual Studio Build Tools installation path not found." -ForegroundColor Red |
| 54 | + Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow |
| 55 | + Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow |
| 56 | + Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow |
| 57 | + Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow |
| 58 | +} |
| 59 | + |
| 60 | +# ---- Install Rust if not installed ---- |
| 61 | +if (-not (Test-Command rustc)) { |
| 62 | + Write-Host "Installing Rust..." -ForegroundColor Yellow |
| 63 | + Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile rustup-init.exe |
| 64 | + .\rustup-init.exe -y |
| 65 | + Remove-Item rustup-init.exe |
| 66 | + |
| 67 | + # Update PATH for Rust |
| 68 | + $env:Path = "$env:USERPROFILE\.cargo\bin;$env:Path" |
| 69 | +} else { |
| 70 | + Write-Host "Rust is already installed. Version: $(rustc --version)" -ForegroundColor Green |
| 71 | +} |
| 72 | + |
| 73 | +# ---- Install Node.js if not installed ---- |
| 74 | +if (-not (Test-Command node)) { |
| 75 | + Write-Host "Installing Node.js..." -ForegroundColor Yellow |
| 76 | + choco install nodejs-lts -y |
| 77 | + |
| 78 | + # Refresh PATH for Node.js |
| 79 | + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 80 | +} else { |
| 81 | + Write-Host "Node.js is already installed. Version: $(node --version)" -ForegroundColor Green |
| 82 | +} |
| 83 | + |
| 84 | +# ---- Install Python 3.12 directly (without pyenv) ---- |
| 85 | +if (-not (Test-Command python) -or -not ((python --version 2>&1) -match "3\.12")) { |
| 86 | + Write-Host "Installing Python 3.12..." -ForegroundColor Yellow |
| 87 | + choco install python312 -y |
| 88 | + |
| 89 | + # Refresh PATH for Python |
| 90 | + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 91 | + |
| 92 | + # Verify Python installation |
| 93 | + $pyVersion = python --version 2>&1 |
| 94 | + if ($pyVersion -match "3\.12") { |
| 95 | + Write-Host "Python 3.12 is installed. Version: $pyVersion" -ForegroundColor Green |
| 96 | + } else { |
| 97 | + Write-Host "Failed to install Python 3.12. Please check your installation." -ForegroundColor Red |
| 98 | + exit 1 |
| 99 | + } |
| 100 | +} else { |
| 101 | + Write-Host "Python 3.12 is already installed. Version: $(python --version)" -ForegroundColor Green |
| 102 | +} |
| 103 | + |
| 104 | +# ---- Install CMake if not installed ---- |
| 105 | +if (-not (Test-Command cmake)) { |
| 106 | + Write-Host "Installing CMake..." -ForegroundColor Yellow |
| 107 | + choco install cmake -y |
| 108 | + |
| 109 | + # Refresh PATH for CMake |
| 110 | + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 111 | +} else { |
| 112 | + Write-Host "CMake is already installed. Version: $(cmake --version)" -ForegroundColor Green |
| 113 | +} |
| 114 | + |
| 115 | +# ---- Set up the frontend ---- |
| 116 | +Write-Host "Setting up frontend..." -ForegroundColor Yellow |
| 117 | +try { |
| 118 | + Set-Location .\frontend\ |
| 119 | + npm install |
| 120 | + |
| 121 | + Set-Location .\src-tauri\ |
| 122 | + cargo build |
| 123 | + |
| 124 | + Set-Location ..\.. |
| 125 | + Write-Host "Frontend setup completed successfully." -ForegroundColor Green |
| 126 | +} catch { |
| 127 | + Write-Host "Error setting up frontend: $_" -ForegroundColor Red |
| 128 | + Set-Location $PSScriptRoot # Return to original directory |
| 129 | +} |
| 130 | + |
| 131 | +# ---- Set up the backend using Python 3.12 ---- |
| 132 | +Write-Host "Setting up backend..." -ForegroundColor Yellow |
| 133 | +try { |
| 134 | + Set-Location .\backend\ |
| 135 | + |
| 136 | + # Create virtual environment |
| 137 | + python -m venv venv |
| 138 | + |
| 139 | + # Activate virtual environment and install dependencies |
| 140 | + .\venv\Scripts\Activate.ps1 |
| 141 | + python -m pip install --upgrade pip |
| 142 | + python -m pip install -r requirements.txt |
| 143 | + deactivate |
| 144 | + |
| 145 | + Set-Location .. |
| 146 | + Write-Host "Backend setup completed successfully." -ForegroundColor Green |
| 147 | +} catch { |
| 148 | + Write-Host "Error setting up backend: $_" -ForegroundColor Red |
| 149 | + Set-Location $PSScriptRoot # Return to original directory |
| 150 | +} |
| 151 | + |
| 152 | +Write-Host "Windows setup complete!" -ForegroundColor Green |
| 153 | +Write-Host "Please restart your computer to ensure all changes take effect." -ForegroundColor Yellow |
| 154 | + |
0 commit comments