-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
54 lines (41 loc) · 1.68 KB
/
install.ps1
File metadata and controls
54 lines (41 loc) · 1.68 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
$Owner = "sonesuke"
$Repo = "docgraph"
$BinaryName = "docgraph"
$OS = "pc-windows-msvc"
$Arch = "x86_64"
$Target = "$Arch-$OS"
Write-Host "Detecting latest version..."
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Owner/$Repo/releases/latest"
$LatestTag = $Release.tag_name
if (-not $LatestTag) {
Write-Error "Failed to fetch latest version."
exit 1
}
Write-Host "Downloading $BinaryName $LatestTag for $Target..."
$AssetName = "${BinaryName}-${Target}.zip"
$Asset = $Release.assets | Where-Object { $_.name -eq $AssetName }
if (-not $Asset) {
Write-Error "Asset not found: $AssetName"
exit 1
}
$DownloadUrl = $Asset.browser_download_url
$TempPath = Join-Path $env:TEMP $AssetName
$ExtractPath = Join-Path $env:TEMP "$BinaryName-install"
if (Test-Path $ExtractPath) { Remove-Item -Recurse -Force $ExtractPath }
New-Item -ItemType Directory -Path $ExtractPath
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempPath
Expand-Archive -Path $TempPath -DestinationPath $ExtractPath
$InstallDir = Join-Path $env:ProgramFiles $BinaryName
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir
}
Move-Item -Path (Join-Path $ExtractPath "$BinaryName.exe") -Destination (Join-Path $InstallDir "$BinaryName.exe") -Force
# Add to Path if not present
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
Write-Host "Added $InstallDir to User PATH. Please restart your terminal."
}
Remove-Item -Recurse -Force $ExtractPath
Remove-Item -Force $TempPath
Write-Host "Successfully installed $BinaryName $LatestTag"