-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
219 lines (188 loc) · 7.78 KB
/
install.ps1
File metadata and controls
219 lines (188 loc) · 7.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# CockpitOS Installer
# Usage: powershell -c "irm https://bojotex.github.io/CockpitOS/install.ps1 | iex"
#
# First-time install only. If CockpitOS is already installed, this script
# will notify the user and launch the existing Setup tool instead.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# ── Branding ────────────────────────────────────────────────────────────
function Write-Banner {
Write-Host ""
Write-Host " +--------------------------------------------+" -ForegroundColor Cyan
Write-Host " | CockpitOS Installer |" -ForegroundColor Cyan
Write-Host " | Firmware platform for DCS cockpits |" -ForegroundColor Cyan
Write-Host " +--------------------------------------------+" -ForegroundColor Cyan
Write-Host ""
}
function Write-Step($msg) {
Write-Host " [*] $msg" -ForegroundColor Yellow
}
function Write-Ok($msg) {
Write-Host " [+] $msg" -ForegroundColor Green
}
function Write-Err($msg) {
Write-Host " [!] $msg" -ForegroundColor Red
}
# ── Resolve install path ────────────────────────────────────────────────
# Uses the Windows known-folder API so OneDrive-redirected Documents works.
$Documents = [Environment]::GetFolderPath('MyDocuments')
$ArduinoDir = Join-Path $Documents "Arduino"
$InstallDir = Join-Path $ArduinoDir "CockpitOS"
# ── Already installed? ──────────────────────────────────────────────────
function Test-ExistingInstall {
if (Test-Path (Join-Path $InstallDir "CockpitOS.ino")) {
return $true
}
return $false
}
# ── Python check ────────────────────────────────────────────────────────
function Test-Python {
try {
$ver = & python --version 2>&1
if ($ver -match 'Python (\d+)\.(\d+)') {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -ge 3 -and $minor -ge 10) {
return $true
}
}
} catch { }
return $false
}
function Install-Python {
Write-Step "Python >= 3.10 not found. Installing Python via winget..."
try {
& winget install --id Python.Python.3.12 --accept-source-agreements --accept-package-agreements 2>&1 | Out-Null
# Refresh PATH so python is available in this session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
if (Test-Python) {
Write-Ok "Python installed successfully."
return $true
}
} catch { }
return $false
}
# ── Download helpers ────────────────────────────────────────────────────
function Get-LatestVersion {
$api = "https://api.github.com/repos/BojoteX/CockpitOS/releases/latest"
$headers = @{ 'User-Agent' = 'CockpitOS-Installer' }
$release = Invoke-RestMethod -Uri $api -Headers $headers -TimeoutSec 10
return $release.tag_name # e.g. "v1.3.0"
}
function Get-CockpitOS($tag) {
$url = "https://github.com/BojoteX/CockpitOS/releases/download/$tag/CockpitOS.zip"
$tmp = Join-Path $env:TEMP "CockpitOS_install.zip"
Write-Step "Downloading CockpitOS $tag ..."
$progressPref = $ProgressPreference
$ProgressPreference = 'SilentlyContinue' # drastically speeds up Invoke-WebRequest
try {
Invoke-WebRequest -Uri $url -OutFile $tmp -UseBasicParsing -TimeoutSec 300
} finally {
$ProgressPreference = $progressPref
}
if (!(Test-Path $tmp)) {
throw "Download failed."
}
return $tmp
}
# ── Extract ─────────────────────────────────────────────────────────────
function Expand-CockpitOS($zipPath) {
Write-Step "Extracting to $InstallDir ..."
# Ensure parent directories exist
if (!(Test-Path $ArduinoDir)) {
New-Item -ItemType Directory -Path $ArduinoDir -Force | Out-Null
}
if (!(Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
Expand-Archive -Path $zipPath -DestinationPath $InstallDir -Force
# Validate sentinel
if (!(Test-Path (Join-Path $InstallDir "CockpitOS.ino"))) {
throw "Extraction failed — CockpitOS.ino not found in $InstallDir"
}
# Cleanup
Remove-Item $zipPath -Force -ErrorAction SilentlyContinue
Write-Ok "Files extracted successfully."
}
# ── Launch setup ────────────────────────────────────────────────────────
function Start-Setup {
$setup = Join-Path $InstallDir "Setup-START.py"
if (Test-Path $setup) {
Write-Step "Launching CockpitOS Setup..."
Write-Host ""
& python $setup
} else {
Write-Err "Setup-START.py not found at $setup"
Write-Host " Please run it manually from: $InstallDir" -ForegroundColor Gray
}
}
# ════════════════════════════════════════════════════════════════════════
# MAIN
# ════════════════════════════════════════════════════════════════════════
Write-Banner
# 1. Check for existing install
if (Test-ExistingInstall) {
Write-Ok "CockpitOS is already installed at:"
Write-Host " $InstallDir" -ForegroundColor Gray
Write-Host ""
# Ensure Python is still available before launching Setup
Write-Step "Checking Python..."
if (Test-Python) {
$pyVer = & python --version 2>&1
Write-Ok "Found $pyVer"
} else {
if (!(Install-Python)) {
Write-Err "Could not install Python. Please install Python 3.10+ manually:"
Write-Host " https://www.python.org/downloads/" -ForegroundColor Gray
exit 1
}
}
Write-Host " To update, use the built-in updater from the CockpitOS menu." -ForegroundColor Yellow
Write-Host " Launching Setup now..." -ForegroundColor Yellow
Write-Host ""
Start-Setup
exit 0
}
# 2. Check Python
Write-Step "Checking Python..."
if (Test-Python) {
$pyVer = & python --version 2>&1
Write-Ok "Found $pyVer"
} else {
if (!(Install-Python)) {
Write-Err "Could not install Python. Please install Python 3.10+ manually:"
Write-Host " https://www.python.org/downloads/" -ForegroundColor Gray
exit 1
}
}
# 3. Get latest release
Write-Step "Checking latest CockpitOS release..."
try {
$tag = Get-LatestVersion
Write-Ok "Latest release: $tag"
} catch {
Write-Err "Could not reach GitHub. Check your internet connection."
Write-Host " Error: $_" -ForegroundColor Gray
exit 1
}
# 4. Download
try {
$zip = Get-CockpitOS $tag
} catch {
Write-Err "Download failed."
Write-Host " Error: $_" -ForegroundColor Gray
exit 1
}
# 5. Extract
try {
Expand-CockpitOS $zip
} catch {
Write-Err "Extraction failed."
Write-Host " Error: $_" -ForegroundColor Gray
exit 1
}
# 6. Launch setup
Write-Ok "CockpitOS $tag installed to:"
Write-Host " $InstallDir" -ForegroundColor Gray
Write-Host ""
Start-Setup