Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
82 lines (72 loc) · 4.1 KB
/
Copy pathinstall.ps1
File metadata and controls
82 lines (72 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# kit — Online-Installer für Windows
#
# irm https://raw.githubusercontent.com/jli-software/kit/master/install.ps1 | iex
#
# Optionen (Umgebungsvariablen):
# $env:KIT_VERSION = 'v0.10.0' bestimmte Version statt der neusten
# $env:KIT_INSTALL_DIR = 'C:\Tools' Zielordner (Default: %LOCALAPPDATA%\Programs\kit)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest ist sonst sehr langsam
$repo = 'jli-software/kit'
$asset = 'kit-windows-x64.exe'
$installDir = if ($env:KIT_INSTALL_DIR) { $env:KIT_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\kit' }
if (-not [Environment]::Is64BitOperatingSystem) { throw 'Nur 64-Bit-Windows wird unterstützt.' }
# Neuste Version über die API auflösen: die "latest/download"-Links cached
# GitHub pro Datei, kurz nach einem Release können sie gemischt alt/neu zeigen.
$version = if ($env:KIT_VERSION) { $env:KIT_VERSION }
else { (Invoke-RestMethod "https://api.github.com/repos/$repo/releases/latest").tag_name }
$base = "https://github.com/$repo/releases/download/$version"
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("kit-" + [guid]::NewGuid())
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
Write-Host "kit ($version) für Windows x64 wird geladen ..."
Invoke-WebRequest -Uri "$base/$asset" -OutFile (Join-Path $tmp 'kit.exe') -UseBasicParsing
Invoke-WebRequest -Uri "$base/SHA256SUMS" -OutFile (Join-Path $tmp 'SHA256SUMS') -UseBasicParsing
$expected = Get-Content (Join-Path $tmp 'SHA256SUMS') |
ForEach-Object { $parts = $_ -split '\s+'; if ($parts[1] -in @($asset, "*$asset")) { $parts[0] } } |
Select-Object -First 1
$actual = (Get-FileHash (Join-Path $tmp 'kit.exe') -Algorithm SHA256).Hash
if (-not $expected -or $expected -ne $actual.ToLower()) {
throw 'Prüfsumme stimmt nicht — Installation abgebrochen.'
}
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
$target = Join-Path $installDir 'kit.exe'
# Alte Version zuerst beiseite schieben: eine gesperrte oder laufende Exe
# lässt sich unter Windows nicht überschreiben, wohl aber umbenennen.
# Eindeutiger Name, weil eine ältere .old-Datei selbst noch gesperrt sein kann.
if (Test-Path $target) {
$old = "kit.exe.$(Get-Date -Format 'yyyyMMddHHmmss').old"
try { Rename-Item $target $old -Force }
catch { throw "$target lässt sich nicht ersetzen — laufendes kit schliessen und nochmals starten." }
}
Copy-Item (Join-Path $tmp 'kit.exe') $target
# Alte Kopien aufräumen; gesperrte bleiben bis zum nächsten Mal liegen
Get-ChildItem $installDir -Filter 'kit.exe*.old' | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "Installiert: $target"
}
finally {
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
}
# Zielordner an den Anfang des Benutzer-PATH, damit er vor alten kit-Kopien liegt
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$entries = @(if ($userPath) { $userPath -split ';' | Where-Object { $_ } })
if ($entries[0] -ne $installDir) {
$rest = @($entries | Where-Object { $_ -ne $installDir })
[Environment]::SetEnvironmentVariable('Path', ((@($installDir) + $rest) -join ';'), 'User')
Write-Host "$installDir steht jetzt vorne im Benutzer-PATH (neues Terminal öffnen)."
}
$env:Path = "$installDir;" + (($env:Path -split ';' | Where-Object { $_ -and $_ -ne $installDir }) -join ';')
# Andere kit.exe, die vorher im PATH liegen (z. B. alte pipx-Installation)?
$others = Get-Command kit -All -CommandType Application -ErrorAction SilentlyContinue |
Where-Object { $_.Source -ne $target }
foreach ($other in $others) {
Write-Warning "Weitere kit-Installation gefunden: $($other.Source) — entfernen (pipx: 'pipx uninstall kit')."
}
$codexHome = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $HOME '.codex' }
if (-not (Test-Path (Join-Path $codexHome 'auth.json'))) {
Write-Host ''
Write-Host 'Für den Codex-Provider (ChatGPT-Abo) einmal mit Codex CLI anmelden:'
Write-Host ' codex login'
}
Write-Host ''
Write-Host "Fertig — 'kit --help' zeigt alle Modi."