- 번들 v0.5.7이 gemma4 요구(0.20+) 미달 → 온보딩 다운로드 412 실패 - 다운로드 스크립트: .ollama-version 스탬프로 runner 캐시 무효화 - cuda*/rocm* 재귀 가지치기 (신구 zip 레이아웃 모두 대응) + 1.5GB 경고 - darwin: v0.6+ tgz 자산 복귀 (bin/ollama·루트 바이너리 모두 지원)
103 lines
4.7 KiB
PowerShell
103 lines
4.7 KiB
PowerShell
# 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.32.1" }
|
|
$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"
|
|
$VERSION_STAMP = Join-Path $DEST_DIR ".ollama-version"
|
|
|
|
Write-Host "=== Ollama $OLLAMA_VERSION (Windows amd64) ===" -ForegroundColor Cyan
|
|
|
|
# Version-aware cache: CI runner reuses the checkout dir, so an old bundle can
|
|
# linger. Re-download whenever the stamped version differs from the wanted one.
|
|
if (Test-Path (Join-Path $DEST_DIR "ollama.exe")) {
|
|
$stamped = if (Test-Path $VERSION_STAMP) { (Get-Content $VERSION_STAMP -Raw).Trim() } else { "" }
|
|
if ($stamped -eq $OLLAMA_VERSION) {
|
|
Write-Host "Ollama $OLLAMA_VERSION already present: $DEST_DIR\ollama.exe" -ForegroundColor Green
|
|
exit 0
|
|
}
|
|
Write-Host "Cached Ollama version '$stamped' != '$OLLAMA_VERSION' - re-downloading" -ForegroundColor Yellow
|
|
Remove-Item -Recurse -Force $DEST_DIR
|
|
}
|
|
|
|
if (Test-Path $TEMP_ZIP) { Remove-Item -Force $TEMP_ZIP }
|
|
|
|
Write-Host "Downloading: $OLLAMA_URL"
|
|
# curl.exe (Win10+ native) handles GitHub redirects, progress output, large files
|
|
# better than Invoke-WebRequest. -L follow redirects, --fail error on HTTP >=400,
|
|
# --retry 3, --max-time 1800 (30min), --progress-bar human readable.
|
|
$curlExe = "$env:SystemRoot\System32\curl.exe"
|
|
if (-not (Test-Path $curlExe)) { $curlExe = "curl.exe" }
|
|
& $curlExe -L --fail --retry 3 --max-time 1800 --progress-bar `
|
|
-o $TEMP_ZIP $OLLAMA_URL
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "curl download failed with exit code $LASTEXITCODE" -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/ (runners + DLLs).
|
|
# Prune GPU runners (CUDA v11/v12, ROCm) to keep installer under NSIS 2GB limit.
|
|
# CPU runners (cpu_avx2, cpu_avx) are sufficient for initial bundle; users needing GPU
|
|
# can install Ollama separately or via future builds.
|
|
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 heavy GPU runtimes to stay below NSIS size limits.
|
|
# Layout differs across versions (old: lib\ollama\runners\cuda*, new: lib\ollama\cuda_v12 etc.)
|
|
# so prune ANY cuda*/rocm* directory recursively - version-agnostic.
|
|
Get-ChildItem -Path $DEST_DIR -Directory -Recurse |
|
|
Where-Object { $_.Name -like "cuda*" -or $_.Name -like "rocm*" } |
|
|
ForEach-Object {
|
|
if (Test-Path $_.FullName) {
|
|
Remove-Item -Recurse -Force $_.FullName
|
|
Write-Host (" pruned GPU runtime: {0}" -f $_.FullName.Substring($DEST_DIR.Length)) -ForegroundColor Yellow
|
|
}
|
|
}
|
|
|
|
Remove-Item -Recurse -Force $TEMP_DIR -ErrorAction SilentlyContinue
|
|
Remove-Item -Force $TEMP_ZIP -ErrorAction SilentlyContinue
|
|
|
|
if (Test-Path (Join-Path $DEST_DIR "ollama.exe")) {
|
|
Set-Content -Path $VERSION_STAMP -Value $OLLAMA_VERSION
|
|
$totalSize = (Get-ChildItem $DEST_DIR -Recurse -File | Measure-Object -Property Length -Sum).Sum
|
|
$totalMB = [math]::Round($totalSize / 1MB, 0)
|
|
Write-Host ""
|
|
Write-Host ("Ollama $OLLAMA_VERSION installed: {0} (pruned total {1} MB)" -f $DEST_DIR, $totalMB) -ForegroundColor Green
|
|
if ($totalSize -gt 1500MB) {
|
|
Write-Host "WARNING: pruned bundle exceeds 1.5GB - NSIS 2GB installer limit at risk" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
Write-Host "ollama.exe not found after extraction. Inspect the zip layout." -ForegroundColor Red
|
|
exit 1
|
|
}
|