|
| 1 | +# Mammouth Code Installer for Windows |
| 2 | +# Usage: irm https://code.mammouth.ai/install.ps1 | iex |
| 3 | + |
| 4 | +$ErrorActionPreference = "Stop" |
| 5 | + |
| 6 | +$Repo = "mammouth-ai/code" |
| 7 | +$BinaryName = "mammouth" |
| 8 | +$InstallDir = "$env:USERPROFILE\.mammouth\bin" |
| 9 | + |
| 10 | +function Write-Info { param($Message) Write-Host "[INFO] $Message" -ForegroundColor Green } |
| 11 | +function Write-Warn { param($Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow } |
| 12 | +function Write-Err { param($Message) Write-Host "[ERROR] $Message" -ForegroundColor Red; exit 1 } |
| 13 | + |
| 14 | +# Detect architecture |
| 15 | +function Get-Platform { |
| 16 | + $arch = if ([Environment]::Is64BitOperatingSystem) { |
| 17 | + switch ($env:PROCESSOR_ARCHITECTURE) { |
| 18 | + "ARM64" { "arm64" } |
| 19 | + "AMD64" { "x64" } |
| 20 | + default { "x64" } |
| 21 | + } |
| 22 | + } else { |
| 23 | + Write-Err "32-bit systems are not supported." |
| 24 | + } |
| 25 | + |
| 26 | + return "mammouth-windows-$arch" |
| 27 | +} |
| 28 | + |
| 29 | +# Get latest version from GitHub API |
| 30 | +function Get-LatestVersion { |
| 31 | + if ($env:VERSION) { |
| 32 | + return $env:VERSION |
| 33 | + } |
| 34 | + |
| 35 | + try { |
| 36 | + $release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers @{ "User-Agent" = "MammouthInstaller" } |
| 37 | + $version = $release.tag_name -replace "^v", "" |
| 38 | + if (-not $version) { |
| 39 | + Write-Err "Failed to determine latest version." |
| 40 | + } |
| 41 | + return $version |
| 42 | + } catch { |
| 43 | + Write-Err "Failed to fetch latest release: $_" |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +function Install-Mammouth { |
| 48 | + $platform = Get-Platform |
| 49 | + $version = Get-LatestVersion |
| 50 | + |
| 51 | + Write-Info "Installing Mammouth Code v$version for $platform..." |
| 52 | + |
| 53 | + # Create install directory |
| 54 | + if (-not (Test-Path $InstallDir)) { |
| 55 | + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
| 56 | + } |
| 57 | + |
| 58 | + $downloadUrl = "https://github.com/$Repo/releases/download/v$version/$platform.zip" |
| 59 | + $tempDir = Join-Path $env:TEMP "mammouth-install-$(Get-Random)" |
| 60 | + $archivePath = Join-Path $tempDir "$platform.zip" |
| 61 | + |
| 62 | + New-Item -ItemType Directory -Path $tempDir -Force | Out-Null |
| 63 | + |
| 64 | + Write-Info "Downloading from $downloadUrl..." |
| 65 | + try { |
| 66 | + Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath -UseBasicParsing |
| 67 | + } catch { |
| 68 | + Write-Err "Failed to download. Check if the release exists for your platform: $_" |
| 69 | + } |
| 70 | + |
| 71 | + Write-Info "Extracting..." |
| 72 | + Expand-Archive -Path $archivePath -DestinationPath $tempDir -Force |
| 73 | + |
| 74 | + # Find the binary |
| 75 | + $binaryPath = Get-ChildItem -Path $tempDir -Recurse -Filter "$BinaryName.exe" | Select-Object -First 1 |
| 76 | + if (-not $binaryPath) { |
| 77 | + # Bun may produce the binary without .exe extension |
| 78 | + $binaryPath = Get-ChildItem -Path $tempDir -Recurse -Filter $BinaryName | Where-Object { -not $_.PSIsContainer } | Select-Object -First 1 |
| 79 | + } |
| 80 | + |
| 81 | + if (-not $binaryPath) { |
| 82 | + Write-Err "Binary not found in archive." |
| 83 | + } |
| 84 | + |
| 85 | + $destPath = Join-Path $InstallDir "$BinaryName.exe" |
| 86 | + Copy-Item -Path $binaryPath.FullName -Destination $destPath -Force |
| 87 | + |
| 88 | + # Cleanup |
| 89 | + Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
| 90 | + |
| 91 | + Write-Info "Installed to $destPath" |
| 92 | + |
| 93 | + # Add to PATH |
| 94 | + Add-ToPath |
| 95 | +} |
| 96 | + |
| 97 | +function Add-ToPath { |
| 98 | + $currentPath = [Environment]::GetEnvironmentVariable("Path", "User") |
| 99 | + |
| 100 | + if ($currentPath -like "*\.mammouth\bin*") { |
| 101 | + Write-Info "Mammouth Code is ready! Run 'mammouth' to get started." |
| 102 | + return |
| 103 | + } |
| 104 | + |
| 105 | + $newPath = "$InstallDir;$currentPath" |
| 106 | + [Environment]::SetEnvironmentVariable("Path", $newPath, "User") |
| 107 | + |
| 108 | + # Also update current session |
| 109 | + $env:Path = "$InstallDir;$env:Path" |
| 110 | + |
| 111 | + Write-Info "Added to user PATH." |
| 112 | + Write-Host "" |
| 113 | + Write-Info "Installation complete!" |
| 114 | + Write-Host "" |
| 115 | + Write-Host "To start using Mammouth Code, either:" |
| 116 | + Write-Host " 1. Open a new terminal, or" |
| 117 | + Write-Host " 2. Run: `$env:Path = '$InstallDir;' + `$env:Path" |
| 118 | + Write-Host "" |
| 119 | + Write-Host "Then run: mammouth" |
| 120 | +} |
| 121 | + |
| 122 | +Install-Mammouth |
0 commit comments