Skip to content

Commit

Permalink
build: add windows script
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Feb 12, 2024
1 parent 6c5c3af commit 2ff5b52
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions installs/windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$ErrorActionPreference = "Stop"

Write-Host "Preparing installation for kill-tree..."

$binPath = Join-Path -Path $env:USERPROFILE -ChildPath "bin"
if (-not (Test-Path $binPath)) {
New-Item -ItemType Directory -Path $binPath
Write-Host "Created bin directory at $binPath"
}

if (-not ($env:PATH -split ";" -contains $binPath)) {
$env:PATH += ";$binPath"
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH, [System.EnvironmentVariableTarget]::User)
Write-Host "Added $binPath to user's PATH environment variable"
}

Write-Host "Downloading and installing kill-tree..."

$tempDir = New-Item -ItemType Directory -Force -Path "$env:TEMP\kill-tree$(Get-Date -Format 'yyyyMMddHHmmss')"

try {
$latestReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/oneofthezombies/kill-tree/releases/latest" -Headers @{"Accept"="application/vnd.github.v3+json"}
$asset = $latestReleaseInfo.assets | Where-Object { $_.name -match "kill-tree-windows-x86_64" }

if (-not $asset) {
Write-Error "kill-tree asset not found in the latest release"
exit 1
}

$downloadUrl = $asset.browser_download_url

$localPath = Join-Path -Path $tempDir -ChildPath $asset.name
Invoke-WebRequest -Uri $downloadUrl -OutFile $localPath

$finalPath = Join-Path -Path $binPath -ChildPath "kill-tree.exe"
Move-Item -Path $localPath -Destination $finalPath -Force

Write-Host "kill-tree installed to $finalPath"

Write-Host "Trying to print version..."
& "$finalPath" --version

Write-Host "kill-tree installed successfully."
}
catch {
Write-Error "An error occurred: $_"
}
finally {
Remove-Item -Path $tempDir -Recurse -Force
}

0 comments on commit 2ff5b52

Please sign in to comment.