-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
138 lines (119 loc) · 4.18 KB
/
install.ps1
File metadata and controls
138 lines (119 loc) · 4.18 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# install.ps1 — install noteui and noteui-sync from GitHub Releases
#
# Usage:
# irm https://raw.githubusercontent.com/atbuy/noteui/main/install.ps1 | iex
#
# Or with options (download first):
# .\install.ps1 -Version v0.9.1 -NoSync
param(
[string]$Version = "",
[switch]$System,
[switch]$NoSync,
[switch]$Help
)
$ErrorActionPreference = 'Stop'
if ($Help) {
Write-Host "Usage: install.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Install noteui from GitHub Releases."
Write-Host ""
Write-Host "Options:"
Write-Host " -Version <tag> Install a specific release (e.g. v0.9.1). Default: latest"
Write-Host " -System Install to Program Files instead of LocalAppData"
Write-Host " -NoSync Skip installing noteui-sync"
Write-Host " -Help Show this help message"
exit 0
}
$Repo = "atbuy/noteui"
$InstallDir = if ($System) {
Join-Path $env:ProgramFiles "noteui"
} else {
Join-Path $env:LOCALAPPDATA "noteui\bin"
}
# Detect architecture
$Arch = switch ($env:PROCESSOR_ARCHITECTURE) {
'ARM64' { 'arm64' }
'AMD64' { 'amd64' }
'x86' {
# Check if running in WOW64 (32-bit process on 64-bit OS)
if ($env:PROCESSOR_ARCHITEW6432 -eq 'AMD64') { 'amd64' }
else {
Write-Error "32-bit systems are not supported."
exit 1
}
}
default {
Write-Error "Unsupported architecture: $env:PROCESSOR_ARCHITECTURE"
exit 1
}
}
# Fetch latest version if not specified
if (-not $Version) {
Write-Host "Fetching latest release version..."
try {
$Response = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
$Version = $Response.tag_name
} catch {
Write-Error "Failed to fetch latest release version from GitHub API: $_"
exit 1
}
if (-not $Version) {
Write-Error "Failed to parse release version from GitHub API response."
exit 1
}
}
Write-Host "Installing noteui $Version (windows/$Arch)..."
Write-Host ""
$ArchiveBasename = "noteui-$Version-windows-$Arch"
$Archive = "$ArchiveBasename.zip"
$DownloadUrl = "https://github.com/$Repo/releases/download/$Version/$Archive"
# Create install directory
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
# Temp directory with cleanup
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $TmpDir | Out-Null
try {
# Download
Write-Host "Downloading $Archive..."
$ArchivePath = Join-Path $TmpDir $Archive
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ArchivePath -UseBasicParsing
} catch {
Write-Error "Download failed. Check that $Version exists at: https://github.com/$Repo/releases"
exit 1
}
# Extract
Write-Host "Extracting..."
Expand-Archive -Path $ArchivePath -DestinationPath $TmpDir -Force
# Install noteui
$NoteUIBin = Join-Path $TmpDir "noteui-$Version-windows-$Arch.exe"
if (-not (Test-Path $NoteUIBin)) {
Write-Error "Expected binary not found in archive: noteui-$Version-windows-$Arch.exe"
exit 1
}
Copy-Item $NoteUIBin (Join-Path $InstallDir "noteui.exe") -Force
# Install noteui-sync
if (-not $NoSync) {
$SyncBin = Join-Path $TmpDir "noteui-sync-$Version-windows-$Arch.exe"
if (Test-Path $SyncBin) {
Copy-Item $SyncBin (Join-Path $InstallDir "noteui-sync.exe") -Force
}
}
} finally {
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
}
Write-Host ""
Write-Host "Installed to $InstallDir"
# Add to user PATH if not already present
$CurrentPath = [System.Environment]::GetEnvironmentVariable('PATH', 'User')
if ($null -eq $CurrentPath) { $CurrentPath = "" }
if ($CurrentPath -notlike "*$InstallDir*") {
$NewPath = if ($CurrentPath) { "$CurrentPath;$InstallDir" } else { $InstallDir }
[System.Environment]::SetEnvironmentVariable('PATH', $NewPath, 'User')
Write-Host ""
Write-Host "Added $InstallDir to your user PATH."
Write-Host "Restart your terminal for the PATH change to take effect."
}
# Verify
Write-Host ""
& (Join-Path $InstallDir "noteui.exe") --version