-
-
Notifications
You must be signed in to change notification settings - Fork 611
Expand file tree
/
Copy pathsetup.ps1
More file actions
274 lines (223 loc) · 10.9 KB
/
setup.ps1
File metadata and controls
274 lines (223 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Check if running as Administrator
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "This script must be run as Administrator. Please re-run PowerShell as Administrator." -ForegroundColor Red
exit 1
}
Write-Host "Starting Windows setup..." -ForegroundColor Yellow
function Test-Command($command) {
try { Get-Command $command -ErrorAction Stop; return $true } catch { return $false }
}
function Install-Chocolatey {
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'))
}
# ---- Install Chocolatey if not installed ----
if (-not (Test-Command choco)) {
Write-Host "Chocolatey is not installed. Installing..." -ForegroundColor Yellow
Install-Chocolatey
} else {
Write-Host "Chocolatey is already installed." -ForegroundColor Green
}
# Refresh PATH environment variable
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# ---- Install Visual Studio Build Tools (if not present) ----
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Yellow
winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
# ---- Check if Visual C++ Build Tools (cl.exe) are available ----
$vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
if (Test-Path $vsPath) {
$latestVersion = (Get-ChildItem $vsPath | Sort-Object Name -Descending | Select-Object -First 1).Name
$clPath = Join-Path -Path $vsPath -ChildPath "$latestVersion\bin\Hostx64\x64\cl.exe"
if (Test-Path $clPath) {
Write-Host "Visual C++ Build Tools found at: $clPath" -ForegroundColor Green
# Add to PATH if not already there
$env:Path = "$vsPath\$latestVersion\bin\Hostx64\x64;$env:Path"
} else {
Write-Host "Visual C++ Build Tools (cl.exe) not found." -ForegroundColor Red
Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow
Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow
Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow
Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow
}
} else {
Write-Host "Visual Studio Build Tools installation path not found." -ForegroundColor Red
Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow
Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow
Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow
Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow
}
# ---- Install Rust if not installed ----
if (-not (Test-Command rustc)) {
Write-Host "Installing Rust..." -ForegroundColor Yellow
Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile rustup-init.exe
.\rustup-init.exe -y
Remove-Item rustup-init.exe
# Update PATH for Rust
$env:Path = "$env:USERPROFILE\.cargo\bin;$env:Path"
} else {
Write-Host "Rust is already installed. Version: $(rustc --version)" -ForegroundColor Green
}
# ---- Install Node.js if not installed ----
if (-not (Test-Command node)) {
Write-Host "Installing Node.js..." -ForegroundColor Yellow
choco install nodejs-lts -y
# Refresh PATH for Node.js
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} else {
Write-Host "Node.js is already installed. Version: $(node --version)" -ForegroundColor Green
}
# ---- Install Python 3.12 directly (without pyenv) ----
if (-not (Test-Command python) -or -not ((python --version 2>&1) -match "3\.12")) {
Write-Host "Installing Python 3.12..." -ForegroundColor Yellow
choco install python312 -y
# Refresh PATH for Python
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# Verify Python installation
$pyVersion = python --version 2>&1
if ($pyVersion -match "3\.12") {
Write-Host "Python 3.12 is installed. Version: $pyVersion" -ForegroundColor Green
} else {
Write-Host "Failed to install Python 3.12. Please check your installation." -ForegroundColor Red
exit 1
}
} else {
Write-Host "Python 3.12 is already installed. Version: $(python --version)" -ForegroundColor Green
}
# ---- Install CMake if not installed ----
if (-not (Test-Command cmake)) {
Write-Host "Installing CMake..." -ForegroundColor Yellow
choco install cmake -y
# Refresh PATH for CMake
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} else {
Write-Host "CMake is already installed. Version: $(cmake --version)" -ForegroundColor Green
}
# --------------------------------------------------
# Miniconda
# --------------------------------------------------
$condaRoot = "$env:USERPROFILE\miniconda3"
$condaExe = "$condaRoot\Scripts\conda.exe"
if (-not (Test-Path $condaExe)) {
Write-Host "Installing Miniconda..." -ForegroundColor Yellow
$installer = "$env:TEMP\miniconda.exe"
Invoke-WebRequest `
-Uri "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" `
-OutFile $installer
if ($LASTEXITCODE -ne 0 -or !(Test-Path $installer)) {
throw "Failed to download Miniconda installer"
}
$installerArgs = "/InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=$condaRoot"
& $installer $installerArgs
if ($LASTEXITCODE -ne 0) {
throw "Miniconda installer failed with exit code $LASTEXITCODE"
}
Remove-Item $installer
# Validate installation
if (-not (Test-Path $condaExe)) {
throw "Conda executable not found after Miniconda installation"
}
Write-Host "Miniconda installed successfully." -ForegroundColor Green
}
else {
Write-Host "Miniconda already installed. Skipping installation." -ForegroundColor Green
}
# Permanently add Conda to USER environment PATH if missing
$currentMachinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentMachinePath -notlike "*$condaRoot*") {
$newMachinePath = "$currentMachinePath;$condaRoot;$condaRoot\Scripts;$condaRoot\condabin"
[System.Environment]::SetEnvironmentVariable("Path", $newMachinePath, "Machine")
Write-Host "Conda paths added permanently to MACHINE environment variables." -ForegroundColor Green
} else {
Write-Host "Conda paths already exist in MACHINE environment variables." -ForegroundColor Green
}
# --------------------------------------------------
# Initialize Conda (THIS WAS MISSING BEFORE)
# --------------------------------------------------
$env:Path = "$condaRoot;$condaRoot\Scripts;$condaRoot\condabin;$env:Path"
$condaBase = & $condaExe info --base
& "$condaBase\shell\condabin\conda-hook.ps1"
# ---- Set up the frontend ----
Write-Host "Setting up frontend..." -ForegroundColor Yellow
try {
Set-Location ..\frontend\
npm install
Set-Location .\src-tauri\
cargo build
Set-Location ..\..
Write-Host "Frontend setup completed successfully." -ForegroundColor Green
} catch {
Write-Host "Error setting up frontend: $_" -ForegroundColor Red
Set-Location $PSScriptRoot # Return to original directory
}
# ---- Set up the backend using Python 3.12 ----
Write-Host "Setting up backend..." -ForegroundColor Yellow
try {
Set-Location .\backend\
Write-Host "Setting up backend Conda environment..." -ForegroundColor Cyan
# Remove existing environment (ignore if it does not exist)
conda remove -p .env --all -y
if ($LASTEXITCODE -ne 0) {
Write-Host "Environment did not exist or could not be removed, continuing..." -ForegroundColor Yellow
}
# Create fresh environment
conda create -p .env python=3.12
if ($LASTEXITCODE -ne 0) {
throw "Failed to create Conda environment"
}
conda activate .\.env
# Upgrade pip inside the environment
python -m pip install --upgrade pip
if ($LASTEXITCODE -ne 0) {
throw "Failed to upgrade pip inside Conda environment"
}
# Install backend dependencies
pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install backend dependencies"
}
# Deactivate environment after setup
conda deactivate
Set-Location ..
Write-Host "Backend setup completed successfully." -ForegroundColor Green
} catch {
Write-Host "Error setting up backend: $_" -ForegroundColor Red
Set-Location $PSScriptRoot # Return to original directory
}
# ---- Set up the sync-microservice using Python 3.12 ----
Write-Host "Setting up sync-microservice..." -ForegroundColor Yellow
try {
Set-Location .\sync-microservice\
Write-Host "Setting up sync-microservice Conda environment..." -ForegroundColor Cyan
# Remove existing environment (ignore if it does not exist)
conda remove -p .sync-env --all -y
if ($LASTEXITCODE -ne 0) {
Write-Host "Environment did not exist or could not be removed, continuing..." -ForegroundColor Yellow
}
# Create fresh environment
conda create -p .sync-env python=3.12
if ($LASTEXITCODE -ne 0) {
throw "Failed to create Conda environment for sync-microservice"
}
conda activate .\.sync-env
# Upgrade pip inside the environment
python -m pip install --upgrade pip
if ($LASTEXITCODE -ne 0) {
throw "Failed to upgrade pip in sync_env"
}
# Install dependencies inside the environment
pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install sync-microservice dependencies"
}
# Deactivate environment after setup
conda deactivate
Set-Location ..
Write-Host "Sync-microservice setup completed successfully." -ForegroundColor Green
} catch {
Write-Host "Error setting up sync-microservice: $_" -ForegroundColor Red
Set-Location $PSScriptRoot # Return to original directory
}
Write-Host "Windows setup complete!" -ForegroundColor Green
Write-Host "Please restart your computer to ensure all changes take effect." -ForegroundColor Yellow