|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | + |
| 3 | +Write-Host "Preparing installation for kill-tree..." |
| 4 | + |
| 5 | +$binPath = Join-Path -Path $env:USERPROFILE -ChildPath "bin" |
| 6 | +if (-not (Test-Path $binPath)) { |
| 7 | + New-Item -ItemType Directory -Path $binPath |
| 8 | + Write-Host "Created bin directory at $binPath" |
| 9 | +} |
| 10 | + |
| 11 | +if (-not ($env:PATH -split ";" -contains $binPath)) { |
| 12 | + $env:PATH += ";$binPath" |
| 13 | + [System.Environment]::SetEnvironmentVariable("PATH", $env:PATH, [System.EnvironmentVariableTarget]::User) |
| 14 | + Write-Host "Added $binPath to user's PATH environment variable" |
| 15 | +} |
| 16 | + |
| 17 | +Write-Host "Downloading and installing kill-tree..." |
| 18 | + |
| 19 | +$tempDir = New-Item -ItemType Directory -Force -Path "$env:TEMP\kill-tree$(Get-Date -Format 'yyyyMMddHHmmss')" |
| 20 | + |
| 21 | +try { |
| 22 | + $latestReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/oneofthezombies/kill-tree/releases/latest" -Headers @{"Accept"="application/vnd.github.v3+json"} |
| 23 | + $asset = $latestReleaseInfo.assets | Where-Object { $_.name -match "kill-tree-windows-x86_64" } |
| 24 | + |
| 25 | + if (-not $asset) { |
| 26 | + Write-Error "kill-tree asset not found in the latest release" |
| 27 | + exit 1 |
| 28 | + } |
| 29 | + |
| 30 | + $downloadUrl = $asset.browser_download_url |
| 31 | + |
| 32 | + $localPath = Join-Path -Path $tempDir -ChildPath $asset.name |
| 33 | + Invoke-WebRequest -Uri $downloadUrl -OutFile $localPath |
| 34 | + |
| 35 | + $finalPath = Join-Path -Path $binPath -ChildPath "kill-tree.exe" |
| 36 | + Move-Item -Path $localPath -Destination $finalPath -Force |
| 37 | + |
| 38 | + Write-Host "kill-tree installed to $finalPath" |
| 39 | + |
| 40 | + Write-Host "Trying to print version..." |
| 41 | + & "$finalPath" --version |
| 42 | + |
| 43 | + Write-Host "kill-tree installed successfully." |
| 44 | +} |
| 45 | +catch { |
| 46 | + Write-Error "An error occurred: $_" |
| 47 | +} |
| 48 | +finally { |
| 49 | + Remove-Item -Path $tempDir -Recurse -Force |
| 50 | +} |
0 commit comments