1
0
Files
AnchorCli/installer.ps1

40 lines
1.4 KiB
PowerShell

$ErrorActionPreference = "Stop"
Write-Host "Publishing project..."
dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true -o ./publish
Write-Host "Finding binary..."
$binary = Get-ChildItem -Path ./publish -Filter "anchor.exe" -File | Select-Object -First 1
if (-not $binary) {
Write-Host "Error: Could not find anchor.exe in ./publish" -ForegroundColor Red
exit 1
}
Write-Host "Found binary: $($binary.FullName)"
# Define the installation directory in the user's profile
$installDir = Join-Path $env:USERPROFILE ".anchor\bin"
if (-not (Test-Path $installDir)) {
Write-Host "Creating installation directory: $installDir"
New-Item -ItemType Directory -Path $installDir | Out-Null
}
Write-Host "Copying to $installDir..."
Copy-Item -Path $binary.FullName -Destination $installDir -Force
# Check if the installation directory is in the User PATH
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -split ';' -notcontains $installDir) {
Write-Host "Adding $installDir to User PATH..."
$newPath = if ($userPath) { "$userPath;$installDir" } else { $installDir }
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Write-Host "PATH updated. You may need to restart your terminal for changes to take effect." -ForegroundColor Yellow
}
else {
Write-Host "$installDir is already in the PATH."
}
Write-Host "Installation complete!" -ForegroundColor Green