|
| 1 | +# Digstore Bootstrap Installer |
| 2 | +# This script downloads and installs the latest version of Digstore with version management |
| 3 | + |
| 4 | +param( |
| 5 | + [string]$Version = "latest", |
| 6 | + [switch]$Force = $false |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +Write-Host "🚀 Digstore Bootstrap Installer" -ForegroundColor Cyan |
| 12 | +Write-Host "=================================" -ForegroundColor Cyan |
| 13 | +Write-Host "" |
| 14 | + |
| 15 | +# Determine installation directory |
| 16 | +$ProgramFiles = $env:ProgramFiles |
| 17 | +if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64" -and $env:ProgramW6432) { |
| 18 | + $ProgramFiles = ${env:ProgramFiles(x86)} |
| 19 | +} |
| 20 | +$InstallBase = Join-Path $ProgramFiles "dig-network" |
| 21 | +$VersionDir = Join-Path $InstallBase "v$Version" |
| 22 | + |
| 23 | +Write-Host "Installing to: $VersionDir" -ForegroundColor Green |
| 24 | + |
| 25 | +# Check if already installed |
| 26 | +if (Test-Path $VersionDir -and -not $Force) { |
| 27 | + Write-Host "Version $Version is already installed at: $VersionDir" -ForegroundColor Yellow |
| 28 | + Write-Host "Use -Force to reinstall" -ForegroundColor Yellow |
| 29 | + exit 0 |
| 30 | +} |
| 31 | + |
| 32 | +# Create directories |
| 33 | +Write-Host "Creating installation directory..." -ForegroundColor Blue |
| 34 | +try { |
| 35 | + New-Item -ItemType Directory -Path $VersionDir -Force | Out-Null |
| 36 | +} catch { |
| 37 | + Write-Host "❌ Failed to create directory: $VersionDir" -ForegroundColor Red |
| 38 | + Write-Host "This script requires administrator privileges to install to Program Files." -ForegroundColor Red |
| 39 | + Write-Host "Please run as administrator or install to user directory manually." -ForegroundColor Red |
| 40 | + exit 1 |
| 41 | +} |
| 42 | + |
| 43 | +# Download the latest MSI |
| 44 | +$DownloadUrl = "https://github.com/DIG-Network/digstore/releases/latest/download/digstore-windows-x64.msi" |
| 45 | +if ($Version -ne "latest") { |
| 46 | + $DownloadUrl = "https://github.com/DIG-Network/digstore/releases/download/v$Version/digstore-windows-x64.msi" |
| 47 | +} |
| 48 | + |
| 49 | +$TempMsi = Join-Path $env:TEMP "digstore-installer.msi" |
| 50 | + |
| 51 | +Write-Host "Downloading from: $DownloadUrl" -ForegroundColor Blue |
| 52 | +try { |
| 53 | + Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempMsi -UserAgent "Digstore-Bootstrap" |
| 54 | + Write-Host "✅ Download completed" -ForegroundColor Green |
| 55 | +} catch { |
| 56 | + Write-Host "❌ Download failed: $($_.Exception.Message)" -ForegroundColor Red |
| 57 | + exit 1 |
| 58 | +} |
| 59 | + |
| 60 | +# Install MSI to system location |
| 61 | +Write-Host "Installing MSI..." -ForegroundColor Blue |
| 62 | +try { |
| 63 | + $InstallArgs = @("/i", $TempMsi, "/quiet", "/norestart") |
| 64 | + $Process = Start-Process "msiexec" -ArgumentList $InstallArgs -Wait -PassThru |
| 65 | + |
| 66 | + if ($Process.ExitCode -ne 0) { |
| 67 | + throw "MSI installation failed with exit code: $($Process.ExitCode)" |
| 68 | + } |
| 69 | + |
| 70 | + Write-Host "✅ MSI installation completed" -ForegroundColor Green |
| 71 | +} catch { |
| 72 | + Write-Host "❌ Installation failed: $($_.Exception.Message)" -ForegroundColor Red |
| 73 | + Remove-Item $TempMsi -ErrorAction SilentlyContinue |
| 74 | + exit 1 |
| 75 | +} |
| 76 | + |
| 77 | +# Wait for installation to complete |
| 78 | +Start-Sleep -Seconds 2 |
| 79 | + |
| 80 | +# Move installed files to versioned directory |
| 81 | +Write-Host "Organizing into versioned directory..." -ForegroundColor Blue |
| 82 | +$SourceBinary = Join-Path $InstallBase "digstore.exe" |
| 83 | +$TargetBinary = Join-Path $VersionDir "digstore.exe" |
| 84 | + |
| 85 | +if (Test-Path $SourceBinary) { |
| 86 | + # Move binary to versioned directory |
| 87 | + Move-Item $SourceBinary $TargetBinary -Force |
| 88 | + |
| 89 | + # Move any other files |
| 90 | + Get-ChildItem $InstallBase -File | ForEach-Object { |
| 91 | + $TargetPath = Join-Path $VersionDir $_.Name |
| 92 | + Move-Item $_.FullName $TargetPath -Force -ErrorAction SilentlyContinue |
| 93 | + } |
| 94 | + |
| 95 | + Write-Host "✅ Files organized into versioned directory" -ForegroundColor Green |
| 96 | +} else { |
| 97 | + Write-Host "❌ Binary not found at expected location: $SourceBinary" -ForegroundColor Red |
| 98 | + Remove-Item $TempMsi -ErrorAction SilentlyContinue |
| 99 | + exit 1 |
| 100 | +} |
| 101 | + |
| 102 | +# Update PATH |
| 103 | +Write-Host "Updating PATH..." -ForegroundColor Blue |
| 104 | +try { |
| 105 | + # Get current PATH |
| 106 | + $CurrentPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 107 | + |
| 108 | + # Remove any existing dig-network entries |
| 109 | + $PathEntries = $CurrentPath -split ";" | Where-Object { $_ -and -not $_.StartsWith($InstallBase) } |
| 110 | + |
| 111 | + # Add new version directory to front |
| 112 | + $NewPath = "$VersionDir;" + ($PathEntries -join ";") |
| 113 | + |
| 114 | + # Update PATH |
| 115 | + [Environment]::SetEnvironmentVariable("PATH", $NewPath, "User") |
| 116 | + $env:PATH = $NewPath |
| 117 | + |
| 118 | + Write-Host "✅ PATH updated to use version $Version" -ForegroundColor Green |
| 119 | +} catch { |
| 120 | + Write-Host "⚠️ Could not update PATH automatically: $($_.Exception.Message)" -ForegroundColor Yellow |
| 121 | + Write-Host "Please manually add to your PATH: $VersionDir" -ForegroundColor Yellow |
| 122 | +} |
| 123 | + |
| 124 | +# Save active version |
| 125 | +$ActiveFile = Join-Path $InstallBase "active" |
| 126 | +Set-Content -Path $ActiveFile -Value $Version -Force |
| 127 | + |
| 128 | +# Clean up |
| 129 | +Remove-Item $TempMsi -ErrorAction SilentlyContinue |
| 130 | + |
| 131 | +Write-Host "" |
| 132 | +Write-Host "🎉 Digstore $Version installed successfully!" -ForegroundColor Green |
| 133 | +Write-Host "Location: $VersionDir" -ForegroundColor Cyan |
| 134 | +Write-Host "" |
| 135 | +Write-Host "Usage:" -ForegroundColor Yellow |
| 136 | +Write-Host " digstore --version # Check installed version" |
| 137 | +Write-Host " digstore init # Initialize a repository" |
| 138 | +Write-Host " digstore version list # List installed versions" |
| 139 | +Write-Host " digstore version install-version 0.4.8 # Install specific version" |
| 140 | +Write-Host " digstore version set 0.4.8 # Switch to version" |
| 141 | +Write-Host " digstore update # Update to latest" |
| 142 | +Write-Host "" |
| 143 | +Write-Host "For help: digstore --help" -ForegroundColor Cyan |
| 144 | +Write-Host "" |
| 145 | +Write-Host "⚠️ Restart your terminal to use the new PATH" -ForegroundColor Yellow |
0 commit comments