Repository navigation
Expand file tree
/
Copy pathInstall.ps1
More file actions
693 lines (575 loc) · 25.4 KB
/
Copy pathInstall.ps1
File metadata and controls
693 lines (575 loc) · 25.4 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# MarkItDown API - Installation Script
# Run as Administrator for full functionality
param(
[string]$PythonVersion = "3.12",
[switch]$SkipPythonInstall,
[switch]$SkipIISPermissions,
[switch]$NonInteractive
)
$ErrorActionPreference = "Stop"
$scriptDir = $PSScriptRoot
$apiProjectDir = Join-Path $scriptDir "src\MarkItDownAPI.Api"
Write-Host "`n=========================================" -ForegroundColor Cyan
Write-Host " MarkItDown API - Installation Script" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
# Function to find Python installation (prefers 3.10-3.12 for compatibility)
function Find-Python {
param([string]$PreferredVersion = "3.12")
# Search compatible versions first (3.10, 3.11, 3.12 - in order of preference)
$searchPaths = @(
"C:\Python312",
"C:\Python311",
"C:\Python310",
"$env:LOCALAPPDATA\Programs\Python\Python312",
"$env:LOCALAPPDATA\Programs\Python\Python311",
"$env:LOCALAPPDATA\Programs\Python\Python310",
"$env:ProgramFiles\Python312",
"$env:ProgramFiles\Python311",
"$env:ProgramFiles\Python310"
)
# Search common locations FIRST (to prefer compatible versions)
foreach ($path in $searchPaths) {
if (Test-Path "$path\python.exe") {
return $path
}
}
# Check PYTHONHOME
if ($env:PYTHONHOME -and (Test-Path "$env:PYTHONHOME\python.exe")) {
# Check if it's a compatible version
$verOutput = & "$env:PYTHONHOME\python.exe" -c "import sys; print(sys.version_info.minor)" 2>$null
if ($verOutput -ge 10 -and $verOutput -le 12) {
return $env:PYTHONHOME
}
# Still return it, but we'll warn later
return $env:PYTHONHOME
}
# Check PATH as last resort
$pythonInPath = Get-Command python -ErrorAction SilentlyContinue
if ($pythonInPath) {
$pythonDir = Split-Path $pythonInPath.Source -Parent
if (Test-Path "$pythonDir\python.exe") {
return $pythonDir
}
}
return $null
}
# Python download URLs for different versions
$PythonDownloads = @{
"3.12" = @{
Url = "https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe"
Dir = "C:\Python312"
Dll = "python312.dll"
}
"3.11" = @{
Url = "https://www.python.org/ftp/python/3.11.11/python-3.11.11-amd64.exe"
Dir = "C:\Python311"
Dll = "python311.dll"
}
"3.10" = @{
Url = "https://www.python.org/ftp/python/3.10.16/python-3.10.16-amd64.exe"
Dir = "C:\Python310"
Dll = "python310.dll"
}
}
# Function to install Python (tries multiple methods)
function Install-Python {
param([string]$Version = "3.12")
# Method 1: Try direct download first (most reliable, works on servers)
Write-Host "Installing Python $Version..." -ForegroundColor Yellow
$result = Install-PythonViaDirect -Version $Version
if ($result) { return $result }
# Method 2: Try winget (if available on Windows 10/11 client)
$result = Install-PythonViaWinget -Version $Version
if ($result) { return $result }
# Method 3: Try Chocolatey (if installed)
$result = Install-PythonViaChocolatey -Version $Version
if ($result) { return $result }
return $null
}
# Function to install Python via direct download (primary method)
function Install-PythonViaDirect {
param([string]$Version = "3.12")
if (-not $PythonDownloads.ContainsKey($Version)) {
Write-Host "Unknown Python version: $Version. Using 3.12" -ForegroundColor Yellow
$Version = "3.12"
}
$config = $PythonDownloads[$Version]
$downloadUrl = $config.Url
$installDir = $config.Dir
$installerPath = Join-Path $env:TEMP "python-$Version-installer.exe"
Write-Host "Downloading Python $Version from python.org..." -ForegroundColor Yellow
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Show progress for large download
$ProgressPreference = 'SilentlyContinue' # Faster download
Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath -UseBasicParsing
$ProgressPreference = 'Continue'
Write-Host "Download complete. Installing to $installDir..." -ForegroundColor Yellow
}
catch {
Write-Host "Failed to download Python: $_" -ForegroundColor Red
return $null
}
# Check if we need admin rights
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
# Silent install with all options
$installArgs = @(
"/quiet",
"InstallAllUsers=1",
"TargetDir=$installDir",
"PrependPath=1",
"Include_pip=1",
"Include_test=0",
"Include_launcher=1"
)
if (-not $isAdmin) {
Write-Host "Note: Running without admin rights. Installing for current user only." -ForegroundColor Yellow
$installArgs = @(
"/quiet",
"InstallAllUsers=0",
"PrependPath=1",
"Include_pip=1",
"Include_test=0"
)
$installDir = "$env:LOCALAPPDATA\Programs\Python\Python$($Version -replace '\.','')"
}
try {
$process = Start-Process -FilePath $installerPath -ArgumentList $installArgs -Wait -PassThru -NoNewWindow
if ($process.ExitCode -ne 0) {
Write-Host "Python installer exited with code: $($process.ExitCode)" -ForegroundColor Yellow
}
}
catch {
Write-Host "Failed to run Python installer: $_" -ForegroundColor Red
return $null
}
finally {
# Cleanup
Remove-Item $installerPath -Force -ErrorAction SilentlyContinue
}
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# Wait a moment for installation to complete
Start-Sleep -Seconds 2
# Find the installed Python
$pythonPath = Find-Python -PreferredVersion $Version
if ($pythonPath) {
Write-Host "Python installed successfully to $pythonPath" -ForegroundColor Green
return $pythonPath
}
# Check default install location
if (Test-Path "$installDir\python.exe") {
return $installDir
}
return $null
}
# Function to install Python via winget (backup method for Windows 10/11)
function Install-PythonViaWinget {
param([string]$Version = "3.12")
$winget = Get-Command winget -ErrorAction SilentlyContinue
if (-not $winget) {
Write-Host "winget not available (normal on Windows Server)" -ForegroundColor Gray
return $null
}
Write-Host "Trying winget..." -ForegroundColor Yellow
$packageId = "Python.Python.$($Version -replace '\.', '')"
# Check if already installed
$installed = winget list --id $packageId 2>$null
if ($LASTEXITCODE -eq 0 -and $installed -match $packageId) {
Write-Host "Python $Version is already installed via winget" -ForegroundColor Green
return Find-Python -PreferredVersion $Version
}
# Install Python
winget install --id $packageId --accept-package-agreements --accept-source-agreements --silent 2>$null
if ($LASTEXITCODE -ne 0) {
return $null
}
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
Start-Sleep -Seconds 2
return Find-Python -PreferredVersion $Version
}
# Function to install Python via Chocolatey (if available)
function Install-PythonViaChocolatey {
param([string]$Version = "3.12")
$choco = Get-Command choco -ErrorAction SilentlyContinue
if (-not $choco) {
return $null
}
Write-Host "Trying Chocolatey..." -ForegroundColor Yellow
$packageName = "python$($Version -replace '\.', '')"
choco install $packageName -y --no-progress 2>$null
if ($LASTEXITCODE -ne 0) {
return $null
}
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
return Find-Python -PreferredVersion $Version
}
# Function to check if markitdown is installed
function Test-MarkItDownInstalled {
param([string]$PythonPath)
$ErrorActionPreference = 'SilentlyContinue'
$result = & "$PythonPath\python.exe" -c "import markitdown; print('OK')" 2>$null
$ErrorActionPreference = 'Stop'
return $result -eq "OK"
}
# Function to find ffmpeg installation
function Find-FFmpeg {
# Check PATH
$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
if ($ffmpeg) {
return $ffmpeg.Source
}
# Check common installation locations
$searchPaths = @(
"C:\ffmpeg\bin\ffmpeg.exe",
"C:\Program Files\ffmpeg\bin\ffmpeg.exe",
"C:\ProgramData\chocolatey\bin\ffmpeg.exe",
"$env:LOCALAPPDATA\Microsoft\WinGet\Packages\*ffmpeg*\ffmpeg.exe",
"$env:USERPROFILE\scoop\apps\ffmpeg\current\bin\ffmpeg.exe"
)
foreach ($path in $searchPaths) {
$resolved = Resolve-Path $path -ErrorAction SilentlyContinue
if ($resolved) {
return $resolved.Path
}
}
return $null
}
# Function to install ffmpeg
function Install-FFmpeg {
# Method 1: Try winget (Windows 10/11)
$winget = Get-Command winget -ErrorAction SilentlyContinue
if ($winget) {
Write-Host " Installing ffmpeg via winget..." -ForegroundColor Yellow
winget install --id Gyan.FFmpeg --accept-package-agreements --accept-source-agreements --silent 2>$null
if ($LASTEXITCODE -eq 0) {
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
return Find-FFmpeg
}
}
# Method 2: Try Chocolatey
$choco = Get-Command choco -ErrorAction SilentlyContinue
if ($choco) {
Write-Host " Installing ffmpeg via Chocolatey..." -ForegroundColor Yellow
choco install ffmpeg -y --no-progress 2>$null
if ($LASTEXITCODE -eq 0) {
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
return Find-FFmpeg
}
}
# Method 3: Direct download from GitHub (BtbN builds - very reliable)
Write-Host " Downloading ffmpeg..." -ForegroundColor Yellow
$ffmpegDir = "C:\ffmpeg"
$ffmpegZip = Join-Path $env:TEMP "ffmpeg.zip"
try {
# Remove any partial download
Remove-Item $ffmpegZip -Force -ErrorAction SilentlyContinue
# Try BtbN GitHub releases first (fast CDN), fallback to gyan.dev
$downloadUrls = @(
"https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip",
"https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
)
$downloaded = $false
$curl = Get-Command curl.exe -ErrorAction SilentlyContinue
foreach ($downloadUrl in $downloadUrls) {
Write-Host " Trying: $($downloadUrl.Split('/')[-1])..." -ForegroundColor Gray
try {
if ($curl) {
& curl.exe -L -o $ffmpegZip $downloadUrl --progress-bar --connect-timeout 30 --max-time 300
} else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = 'Continue'
Invoke-WebRequest -Uri $downloadUrl -OutFile $ffmpegZip -UseBasicParsing -TimeoutSec 300
}
# Verify download (should be at least 50MB)
if ((Test-Path $ffmpegZip) -and (Get-Item $ffmpegZip).Length -gt 50000000) {
$downloaded = $true
break
}
}
catch {
Write-Host " Download failed, trying next source..." -ForegroundColor Yellow
Remove-Item $ffmpegZip -Force -ErrorAction SilentlyContinue
}
}
if (-not $downloaded) {
throw "All download sources failed"
}
Write-Host " Extracting..." -ForegroundColor Gray
# Extract
if (Test-Path $ffmpegDir) {
Remove-Item $ffmpegDir -Recurse -Force
}
Expand-Archive -Path $ffmpegZip -DestinationPath $env:TEMP -Force
# Find extracted folder (handles both naming conventions)
$extractedDir = Get-ChildItem "$env:TEMP\ffmpeg-*" -Directory |
Where-Object { Test-Path "$($_.FullName)\bin\ffmpeg.exe" } |
Select-Object -First 1
if (-not $extractedDir) {
# BtbN structure might be different
$extractedDir = Get-ChildItem "$env:TEMP\ffmpeg-*" -Directory | Select-Object -First 1
}
if ($extractedDir) {
Move-Item $extractedDir.FullName $ffmpegDir -Force
}
# Verify ffmpeg.exe exists
if (-not (Test-Path "$ffmpegDir\bin\ffmpeg.exe")) {
throw "ffmpeg.exe not found after extraction"
}
# Add to system PATH (requires admin)
$ffmpegBin = "$ffmpegDir\bin"
try {
$currentPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentPath -notlike "*$ffmpegBin*") {
[System.Environment]::SetEnvironmentVariable("Path", "$currentPath;$ffmpegBin", "Machine")
Write-Host " Added to system PATH" -ForegroundColor Gray
}
}
catch {
Write-Host " Note: Could not add to system PATH (not running as admin)" -ForegroundColor Yellow
Write-Host " You may need to add $ffmpegBin to PATH manually" -ForegroundColor Yellow
}
# Refresh current session PATH
$env:Path = "$env:Path;$ffmpegBin"
return "$ffmpegBin\ffmpeg.exe"
}
catch {
Write-Host " Failed to download ffmpeg: $_" -ForegroundColor Red
return $null
}
finally {
Remove-Item $ffmpegZip -Force -ErrorAction SilentlyContinue
}
}
# ============================================
# MAIN SCRIPT
# ============================================
# Step 1: Find or Install Python
Write-Host "`n[1/6] Checking Python installation..." -ForegroundColor Cyan
$PythonPath = Find-Python -PreferredVersion $PythonVersion
# Check if found Python is compatible (3.10-3.12)
$needsInstall = $false
if ($PythonPath) {
$pyMinorVer = & "$PythonPath\python.exe" -c "import sys; print(sys.version_info.minor)" 2>$null
if ($pyMinorVer -and ([int]$pyMinorVer -lt 10 -or [int]$pyMinorVer -gt 12)) {
$foundVer = & "$PythonPath\python.exe" --version 2>&1
Write-Host "Found $foundVer, but MarkItDown requires Python 3.10-3.12" -ForegroundColor Yellow
if (-not $SkipPythonInstall) {
if (-not $NonInteractive) {
$install = Read-Host "Install Python $PythonVersion for compatibility? (Y/n)"
$needsInstall = ($install -ne "n" -and $install -ne "N")
} else {
$needsInstall = $true
}
}
if (-not $needsInstall) {
Write-Host "Continuing with $foundVer (some features may not work)" -ForegroundColor Yellow
} else {
$PythonPath = $null # Force installation
}
}
}
if (-not $PythonPath) {
if ($SkipPythonInstall) {
Write-Host "Python 3.10-3.12 not found and -SkipPythonInstall specified." -ForegroundColor Red
Write-Host "Please install Python 3.10-3.12 manually." -ForegroundColor Yellow
exit 1
}
if (-not $NonInteractive -and -not $needsInstall) {
$install = Read-Host "Python not found. Install Python $PythonVersion automatically? (Y/n)"
if ($install -eq "n" -or $install -eq "N") {
Write-Host "Please install Python 3.10-3.12 from https://www.python.org/downloads/" -ForegroundColor Yellow
exit 1
}
}
Write-Host "Installing Python $PythonVersion..." -ForegroundColor Yellow
$PythonPath = Install-Python -Version $PythonVersion
if (-not $PythonPath) {
Write-Host "Failed to install Python automatically." -ForegroundColor Red
Write-Host "Please install Python 3.10-3.12 manually from https://www.python.org/downloads/" -ForegroundColor Yellow
exit 1
}
}
$pythonVersionStr = & "$PythonPath\python.exe" --version 2>&1
Write-Host "Using: $pythonVersionStr at $PythonPath" -ForegroundColor Green
# Step 2: Install/Update pip
Write-Host "`n[2/6] Ensuring pip is up to date..." -ForegroundColor Cyan
# pip often outputs warnings to stderr, redirect to avoid script termination
$null = & "$PythonPath\python.exe" -m pip install --upgrade pip --quiet 2>&1
Write-Host "pip is ready" -ForegroundColor Green
# Step 3: Install MarkItDown
Write-Host "`n[3/6] Installing MarkItDown..." -ForegroundColor Cyan
$markitdownInstalled = Test-MarkItDownInstalled -PythonPath $PythonPath
if ($markitdownInstalled) {
Write-Host "MarkItDown is already installed. Checking for updates..." -ForegroundColor Yellow
}
# Try installing markitdown with all extras first
$pipOutput = & "$PythonPath\python.exe" -m pip install "markitdown[all]" --upgrade 2>&1
$pipExitCode = $LASTEXITCODE
# Check if [all] extra is not available (older version or incompatible Python)
if ($pipOutput -match "does not provide the extra 'all'" -or $pipExitCode -ne 0) {
Write-Host "Installing base markitdown package..." -ForegroundColor Yellow
# Install base package
$pipOutput = & "$PythonPath\python.exe" -m pip install markitdown --upgrade 2>&1
$pipExitCode = $LASTEXITCODE
if ($pipExitCode -eq 0) {
# Try to install common optional dependencies separately
Write-Host "Installing optional dependencies..." -ForegroundColor Yellow
$optionalDeps = @(
"python-pptx", # PowerPoint
"python-docx", # Word
"openpyxl", # Excel
"xlrd", # Older Excel
"pdfminer.six", # PDF
"beautifulsoup4", # HTML
"youtube-transcript-api", # YouTube
"requests" # HTTP
)
foreach ($dep in $optionalDeps) {
$null = & "$PythonPath\python.exe" -m pip install $dep --quiet 2>&1
}
}
}
if ($pipExitCode -ne 0) {
Write-Host "Failed to install MarkItDown" -ForegroundColor Red
Write-Host $pipOutput -ForegroundColor Gray
exit 1
}
# Verify installation (suppress warnings by redirecting stderr to null)
$verifyScript = "import markitdown; print('MarkItDown ' + markitdown.__version__)"
$ErrorActionPreference = 'SilentlyContinue'
$version = & "$PythonPath\python.exe" -c $verifyScript 2>$null
$verifyExitCode = $LASTEXITCODE
$ErrorActionPreference = 'Stop'
if ($verifyExitCode -eq 0 -and $version -match "MarkItDown") {
Write-Host "$version installed successfully" -ForegroundColor Green
# Warn about Python version if using 3.13+
$pyVerCheck = & "$PythonPath\python.exe" -c "import sys; print(sys.version_info.minor)" 2>$null
if ($pyVerCheck -match "^\d+$" -and [int]$pyVerCheck -ge 13) {
Write-Host "Note: Python 3.$pyVerCheck detected. MarkItDown officially supports Python 3.10-3.12." -ForegroundColor Yellow
Write-Host "Some features may not work. Consider using Python 3.12 for full compatibility." -ForegroundColor Yellow
}
} else {
Write-Host "MarkItDown verification failed" -ForegroundColor Red
$errorOutput = & "$PythonPath\python.exe" -c $verifyScript 2>&1
Write-Host $errorOutput -ForegroundColor Gray
exit 1
}
# Step 4: Install ffmpeg (required for audio processing)
Write-Host "`n[4/6] Checking ffmpeg installation..." -ForegroundColor Cyan
$ffmpegPath = Find-FFmpeg
if ($ffmpegPath) {
$ffmpegVersion = & $ffmpegPath -version 2>&1 | Select-Object -First 1
Write-Host "ffmpeg found: $ffmpegVersion" -ForegroundColor Green
} else {
Write-Host "ffmpeg not found (required for audio file processing)" -ForegroundColor Yellow
$installFfmpeg = $false
if ($NonInteractive) {
$installFfmpeg = $true
} else {
$response = Read-Host "Install ffmpeg automatically? (Y/n)"
$installFfmpeg = ($response -ne "n" -and $response -ne "N")
}
if ($installFfmpeg) {
$ffmpegPath = Install-FFmpeg
if ($ffmpegPath) {
Write-Host "ffmpeg installed successfully" -ForegroundColor Green
} else {
Write-Host "Warning: Could not install ffmpeg automatically." -ForegroundColor Yellow
Write-Host "Audio file conversion may not work. Install manually from https://ffmpeg.org/download.html" -ForegroundColor Yellow
}
} else {
Write-Host "Skipping ffmpeg installation. Audio file conversion may not work." -ForegroundColor Yellow
}
}
# Step 5: Update appsettings.json
Write-Host "`n[5/6] Configuring application..." -ForegroundColor Cyan
$appSettingsPath = Join-Path $apiProjectDir "appsettings.json"
if (Test-Path $appSettingsPath) {
$settings = Get-Content $appSettingsPath -Raw | ConvertFrom-Json
$settings.Python.PythonHome = $PythonPath
# Detect Python DLL (prefer pythonXXX.dll over python3.dll)
$pythonDll = Get-ChildItem "$PythonPath\python*.dll" -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match "^python\d{2,3}\.dll$" } |
Select-Object -First 1
if ($pythonDll) {
$settings.Python.PythonDll = $pythonDll.Name
Write-Host "Configured Python DLL: $($pythonDll.Name)" -ForegroundColor Green
} else {
# Fallback: construct from version
$pyVer = & "$PythonPath\python.exe" -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')" 2>$null
if ($pyVer) {
$settings.Python.PythonDll = "python$pyVer.dll"
Write-Host "Configured Python DLL: python$pyVer.dll" -ForegroundColor Green
}
}
$settings | ConvertTo-Json -Depth 10 | Set-Content $appSettingsPath -Encoding UTF8
Write-Host "appsettings.json updated with Python path" -ForegroundColor Green
} else {
Write-Host "Warning: appsettings.json not found at $appSettingsPath" -ForegroundColor Yellow
}
# Step 6: Build the project
Write-Host "`n[6/6] Building the project..." -ForegroundColor Cyan
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
if (-not $dotnet) {
Write-Host ".NET SDK not found. Please install from https://dot.net" -ForegroundColor Yellow
Write-Host "Skipping build step." -ForegroundColor Yellow
} else {
Push-Location $scriptDir
try {
dotnet build MarkItDownAPI.slnx -c Release --nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed" -ForegroundColor Red
exit 1
}
Write-Host "Build successful" -ForegroundColor Green
}
finally {
Pop-Location
}
}
# Optional: IIS permissions
if (-not $SkipIISPermissions) {
$grantPermissions = $false
if ($NonInteractive) {
$grantPermissions = $true
} else {
$response = Read-Host "`nGrant IIS_IUSRS permissions to Python folder for IIS hosting? (y/N)"
$grantPermissions = ($response -eq "y" -or $response -eq "Y")
}
if ($grantPermissions) {
Write-Host "Granting IIS permissions..." -ForegroundColor Yellow
icacls $PythonPath /grant "IIS_IUSRS:(OI)(CI)RX" /T /Q
if ($LASTEXITCODE -eq 0) {
Write-Host "IIS permissions granted" -ForegroundColor Green
} else {
Write-Host "Warning: Could not grant IIS permissions. Run as Administrator if needed." -ForegroundColor Yellow
}
}
}
# ============================================
# SUMMARY
# ============================================
Write-Host "`n=========================================" -ForegroundColor Cyan
Write-Host " Installation Complete!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "`nPython: $PythonPath" -ForegroundColor White
Write-Host "MarkItDown: Installed" -ForegroundColor White
if ($ffmpegPath) {
Write-Host "ffmpeg: Installed" -ForegroundColor White
} else {
Write-Host "ffmpeg: Not installed (audio conversion may not work)" -ForegroundColor Yellow
}
Write-Host "`nNext steps:" -ForegroundColor Yellow
Write-Host " 1. Run locally: .\start-dev.ps1" -ForegroundColor White
Write-Host " 2. Publish for IIS: dotnet publish -c Release -o ./publish" -ForegroundColor White
Write-Host " 3. API docs: https://localhost:5001/scalar/v1" -ForegroundColor White
Write-Host "`nUsage examples:" -ForegroundColor Yellow
Write-Host ' .\Install.ps1 # Interactive install' -ForegroundColor Gray
Write-Host ' .\Install.ps1 -NonInteractive # Automated install (CI/CD)' -ForegroundColor Gray
Write-Host ' .\Install.ps1 -PythonVersion 3.11' -ForegroundColor Gray
Write-Host "=========================================" -ForegroundColor Cyan