-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.ps1
More file actions
83 lines (67 loc) · 2.78 KB
/
Copy pathinstall.ps1
File metadata and controls
83 lines (67 loc) · 2.78 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
83
# Authy install script — Windows (PowerShell)
# Usage: irm https://raw.githubusercontent.com/eric8810/authy/main/install.ps1 | iex
$ErrorActionPreference = "Stop"
$Repo = "eric8810/authy"
$Binary = "authy"
$Target = "x86_64-pc-windows-msvc"
function Main {
$version = Get-Version
Download-And-Install $version
Verify-Install
}
function Get-Version {
if ($env:AUTHY_VERSION) {
Write-Host "Using specified version: $env:AUTHY_VERSION" -ForegroundColor Green
return $env:AUTHY_VERSION
}
Write-Host "Fetching latest version..." -ForegroundColor Green
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$version = $release.tag_name
if (-not $version) {
throw "Failed to determine latest version"
}
Write-Host "Latest version: $version" -ForegroundColor Green
return $version
}
function Download-And-Install($version) {
$archive = "$Binary-$Target.zip"
$url = "https://github.com/$Repo/releases/download/$version/$archive"
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $tmpDir | Out-Null
try {
Write-Host "Downloading $url..." -ForegroundColor Green
Invoke-WebRequest -Uri $url -OutFile (Join-Path $tmpDir $archive) -UseBasicParsing
Write-Host "Extracting..." -ForegroundColor Green
Expand-Archive -Path (Join-Path $tmpDir $archive) -DestinationPath $tmpDir
$installDir = Join-Path $env:LOCALAPPDATA "authy"
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir | Out-Null
}
Copy-Item -Path (Join-Path $tmpDir "$Binary.exe") -Destination (Join-Path $installDir "$Binary.exe") -Force
Write-Host "Installed to $installDir\$Binary.exe" -ForegroundColor Green
# Add to User PATH if not present
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$pathEntries = $userPath -split ";" | Where-Object { $_ -ne "" }
if ($installDir -notin $pathEntries) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$installDir", "User")
$env:Path = "$env:Path;$installDir"
Write-Host "Added $installDir to User PATH" -ForegroundColor Green
}
}
finally {
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
}
}
function Verify-Install {
$exe = Join-Path $env:LOCALAPPDATA "authy\$Binary.exe"
if (Test-Path $exe) {
try {
$ver = & $exe --version 2>&1
Write-Host "Verification: $ver" -ForegroundColor Green
}
catch {
Write-Host "Install complete. Restart your terminal to use '$Binary'." -ForegroundColor Green
}
}
}
Main