# scripts/download-ollama.ps1 # Downloads the portable Ollama Windows binary into resources/ollama/. # Usage: powershell -ExecutionPolicy Bypass -File scripts/download-ollama.ps1 # # Note: Ollama only ships an NSIS installer officially. We use the # ollama-windows-amd64.zip release asset on GitHub instead. $ErrorActionPreference = "Stop" $OLLAMA_VERSION = if ($env:OLLAMA_VERSION) { $env:OLLAMA_VERSION } else { "v0.5.7" } $OLLAMA_URL = "https://github.com/ollama/ollama/releases/download/$OLLAMA_VERSION/ollama-windows-amd64.zip" $DEST_DIR = Join-Path $PSScriptRoot "..\resources\ollama" $TEMP_ZIP = Join-Path $env:TEMP "ollama-$OLLAMA_VERSION-windows-amd64.zip" $TEMP_DIR = Join-Path $env:TEMP "ollama-extract" Write-Host "=== Ollama $OLLAMA_VERSION (Windows amd64) ===" -ForegroundColor Cyan if (Test-Path (Join-Path $DEST_DIR "ollama.exe")) { Write-Host "Ollama already present: $DEST_DIR\ollama.exe" -ForegroundColor Green exit 0 } if (Test-Path $TEMP_ZIP) { Remove-Item -Force $TEMP_ZIP } Write-Host "Downloading: $OLLAMA_URL" try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -Uri $OLLAMA_URL -OutFile $TEMP_ZIP -UseBasicParsing } catch { Write-Host "Auto-download failed: $_" -ForegroundColor Red Write-Host "" Write-Host "=== Manual install ===" -ForegroundColor Yellow Write-Host "Download ollama-windows-amd64.zip from:" Write-Host " https://github.com/ollama/ollama/releases" Write-Host "and extract its contents into:" Write-Host " $DEST_DIR" exit 1 } $fileSize = (Get-Item $TEMP_ZIP).Length if ($fileSize -lt 1000000) { Write-Host ("Downloaded file too small ({0} bytes)." -f $fileSize) -ForegroundColor Red exit 1 } $sizeMB = [math]::Round($fileSize / 1MB, 1) Write-Host ("Download complete ({0} MB)" -f $sizeMB) Write-Host "Extracting..." if (Test-Path $TEMP_DIR) { Remove-Item -Recurse -Force $TEMP_DIR } Expand-Archive -Path $TEMP_ZIP -DestinationPath $TEMP_DIR -Force New-Item -ItemType Directory -Force -Path $DEST_DIR | Out-Null # zip layout: ollama.exe + lib/ (DLLs). Copy everything. Get-ChildItem -Path $TEMP_DIR -Force | ForEach-Object { Copy-Item $_.FullName -Destination $DEST_DIR -Recurse -Force Write-Host (" copied: {0}" -f $_.Name) -ForegroundColor Green } Remove-Item -Recurse -Force $TEMP_DIR -ErrorAction SilentlyContinue Remove-Item -Force $TEMP_ZIP -ErrorAction SilentlyContinue if (Test-Path (Join-Path $DEST_DIR "ollama.exe")) { $ollamaSize = (Get-Item (Join-Path $DEST_DIR "ollama.exe")).Length $ollamaMB = [math]::Round($ollamaSize / 1MB, 1) Write-Host "" Write-Host ("Ollama installed: {0} ({1} MB)" -f $DEST_DIR, $ollamaMB) -ForegroundColor Green } else { Write-Host "ollama.exe not found after extraction. Inspect the zip layout." -ForegroundColor Red exit 1 }