-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c5c3af
commit 2ff5b52
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |