-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
100 lines (78 loc) · 3.02 KB
/
install.ps1
File metadata and controls
100 lines (78 loc) · 3.02 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Flashduty CLI installer for Windows
# Usage: irm https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.ps1 | iex
#
# Environment variables:
# FLASHDUTY_VERSION - specific version to install (e.g. "v0.1.2")
# FLASHDUTY_INSTALL_DIR - install directory (default: $HOME\.flashduty\bin)
$ErrorActionPreference = "Stop"
$Repo = "flashcatcloud/flashduty-cli"
$Binary = "flashduty-cli.exe"
$InstalledName = "flashduty.exe"
function Write-Info($msg) {
Write-Host "[flashduty] $msg"
}
function Fail($msg) {
Write-Error "[flashduty] $msg"
exit 1
}
# --- detect architecture ---
function Get-Arch {
switch ($env:PROCESSOR_ARCHITECTURE) {
"AMD64" { return "x86_64" }
"ARM64" { return "arm64" }
default { Fail "unsupported architecture: $env:PROCESSOR_ARCHITECTURE" }
}
}
# --- resolve version ---
function Get-Version {
if ($env:FLASHDUTY_VERSION) {
return $env:FLASHDUTY_VERSION
}
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -UseBasicParsing
return $release.tag_name
} catch {
Fail "could not determine latest version. Set FLASHDUTY_VERSION to install a specific version."
}
}
# --- main ---
$Arch = Get-Arch
$Version = Get-Version
$InstallDir = if ($env:FLASHDUTY_INSTALL_DIR) {
$env:FLASHDUTY_INSTALL_DIR
} else {
Join-Path $HOME ".flashduty\bin"
}
$Archive = "flashduty-cli_Windows_${Arch}.zip"
$Url = "https://github.com/$Repo/releases/download/$Version/$Archive"
Write-Info "Installing Flashduty CLI $Version (Windows/$Arch)"
Write-Info "Downloading $Url"
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "flashduty-install-$([System.Guid]::NewGuid().ToString('N'))"
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
try {
$ArchivePath = Join-Path $TmpDir $Archive
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $Url -OutFile $ArchivePath -UseBasicParsing
Expand-Archive -Path $ArchivePath -DestinationPath $TmpDir -Force
$BinaryPath = Join-Path $TmpDir $Binary
if (-not (Test-Path $BinaryPath)) {
Fail "binary '$Binary' not found in archive"
}
# Create install directory
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$DestPath = Join-Path $InstallDir $InstalledName
Move-Item -Path $BinaryPath -Destination $DestPath -Force
Write-Info "Installed to $DestPath"
# Add to user PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
$env:Path = "$env:Path;$InstallDir"
Write-Info "Added $InstallDir to user PATH (restart your terminal for it to take effect)"
}
Write-Info "Run 'flashduty version' to verify"
} finally {
Remove-Item -Path $TmpDir -Recurse -Force -ErrorAction SilentlyContinue
}