Skip to content

Commit 30179b9

Browse files
committed
feat: add PowerShell installer for Windows, improve shell installer
- install.ps1: native Windows installer via PowerShell irm .../install.ps1 | iex Installs to ~/.flashduty/bin and auto-adds to user PATH - install.sh: add PATH warning when install dir is not in PATH
1 parent a3b5815 commit 30179b9

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

install.ps1

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Flashduty CLI installer for Windows
2+
# Usage: irm https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.ps1 | iex
3+
#
4+
# Environment variables:
5+
# FLASHDUTY_VERSION - specific version to install (e.g. "v0.1.2")
6+
# FLASHDUTY_INSTALL_DIR - install directory (default: $HOME\.flashduty\bin)
7+
8+
$ErrorActionPreference = "Stop"
9+
10+
$Repo = "flashcatcloud/flashduty-cli"
11+
$Binary = "flashduty-cli.exe"
12+
$InstalledName = "flashduty.exe"
13+
14+
function Write-Info($msg) {
15+
Write-Host "[flashduty] $msg"
16+
}
17+
18+
function Fail($msg) {
19+
Write-Error "[flashduty] $msg"
20+
exit 1
21+
}
22+
23+
# --- detect architecture ---
24+
25+
function Get-Arch {
26+
switch ($env:PROCESSOR_ARCHITECTURE) {
27+
"AMD64" { return "x86_64" }
28+
"ARM64" { return "arm64" }
29+
default { Fail "unsupported architecture: $env:PROCESSOR_ARCHITECTURE" }
30+
}
31+
}
32+
33+
# --- resolve version ---
34+
35+
function Get-Version {
36+
if ($env:FLASHDUTY_VERSION) {
37+
return $env:FLASHDUTY_VERSION
38+
}
39+
try {
40+
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -UseBasicParsing
41+
return $release.tag_name
42+
} catch {
43+
Fail "could not determine latest version. Set FLASHDUTY_VERSION to install a specific version."
44+
}
45+
}
46+
47+
# --- main ---
48+
49+
$Arch = Get-Arch
50+
$Version = Get-Version
51+
52+
$InstallDir = if ($env:FLASHDUTY_INSTALL_DIR) {
53+
$env:FLASHDUTY_INSTALL_DIR
54+
} else {
55+
Join-Path $HOME ".flashduty\bin"
56+
}
57+
58+
$Archive = "flashduty-cli_Windows_${Arch}.zip"
59+
$Url = "https://github.com/$Repo/releases/download/$Version/$Archive"
60+
61+
Write-Info "Installing Flashduty CLI $Version (Windows/$Arch)"
62+
Write-Info "Downloading $Url"
63+
64+
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "flashduty-install-$([System.Guid]::NewGuid().ToString('N'))"
65+
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
66+
67+
try {
68+
$ArchivePath = Join-Path $TmpDir $Archive
69+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
70+
Invoke-WebRequest -Uri $Url -OutFile $ArchivePath -UseBasicParsing
71+
72+
Expand-Archive -Path $ArchivePath -DestinationPath $TmpDir -Force
73+
74+
$BinaryPath = Join-Path $TmpDir $Binary
75+
if (-not (Test-Path $BinaryPath)) {
76+
Fail "binary '$Binary' not found in archive"
77+
}
78+
79+
# Create install directory
80+
if (-not (Test-Path $InstallDir)) {
81+
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
82+
}
83+
84+
$DestPath = Join-Path $InstallDir $InstalledName
85+
Move-Item -Path $BinaryPath -Destination $DestPath -Force
86+
87+
Write-Info "Installed to $DestPath"
88+
89+
# Add to user PATH if not already there
90+
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
91+
if ($UserPath -notlike "*$InstallDir*") {
92+
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
93+
$env:Path = "$env:Path;$InstallDir"
94+
Write-Info "Added $InstallDir to user PATH (restart your terminal for it to take effect)"
95+
}
96+
97+
Write-Info "Run 'flashduty version' to verify"
98+
} finally {
99+
Remove-Item -Path $TmpDir -Recurse -Force -ErrorAction SilentlyContinue
100+
}

install.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ main() {
114114
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
115115

116116
info "Installed to ${INSTALL_DIR}/${INSTALLED_NAME}"
117+
118+
# Warn if install dir is not in PATH
119+
case ":${PATH}:" in
120+
*":${INSTALL_DIR}:"*) ;;
121+
*) info "WARNING: ${INSTALL_DIR} is not in your PATH. Add it with:"
122+
info " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;;
123+
esac
124+
117125
info "Run 'flashduty version' to verify"
118126
}
119127

0 commit comments

Comments
 (0)