feat: integrate N7Cockpit remote mode control
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ConfigPath = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
if (-not $ConfigPath) { $ConfigPath = Join-Path $projectRoot 'config\migration.psd1' }
|
||||
if (-not [System.IO.Path]::IsPathRooted($ConfigPath)) {
|
||||
$ConfigPath = Join-Path $projectRoot $ConfigPath
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath $ConfigPath)) {
|
||||
throw 'Run scripts\initialize-migration.ps1 and edit config\migration.psd1 first.'
|
||||
}
|
||||
$config = Import-PowerShellDataFile -LiteralPath $ConfigPath
|
||||
|
||||
$javaCandidates = @(
|
||||
[string]$config.JavaHome,
|
||||
$env:JAVA_HOME,
|
||||
'C:\Program Files\Android\Android Studio\jbr'
|
||||
) | Where-Object { $_ -and (Test-Path -LiteralPath $_) }
|
||||
$javaHome = $javaCandidates | Select-Object -First 1
|
||||
$javaOk = $false
|
||||
$javaSummary = 'not found'
|
||||
if ($javaHome) {
|
||||
$javaExe = Join-Path $javaHome 'bin\java.exe'
|
||||
if (Test-Path -LiteralPath $javaExe) {
|
||||
$savedErrorAction = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
$javaOutput = (& $javaExe -version 2>&1 | Out-String)
|
||||
$ErrorActionPreference = $savedErrorAction
|
||||
$javaSummary = ($javaOutput -split "`r?`n" | Select-Object -First 1).Trim()
|
||||
$javaMajor = if ($javaOutput -match 'version "(?<major>\d+)') {
|
||||
[int]$Matches.major
|
||||
} else {
|
||||
0
|
||||
}
|
||||
$javaOk = $javaMajor -ge 17
|
||||
}
|
||||
}
|
||||
|
||||
$sdkCandidates = @(
|
||||
[string]$config.AndroidSdk,
|
||||
$env:ANDROID_SDK_ROOT,
|
||||
$env:ANDROID_HOME,
|
||||
(Join-Path $env:LOCALAPPDATA 'Android\Sdk')
|
||||
) | Where-Object { $_ -and (Test-Path -LiteralPath $_) }
|
||||
$androidSdk = $sdkCandidates | Select-Object -First 1
|
||||
$platform35 = $androidSdk -and (
|
||||
Test-Path -LiteralPath (Join-Path $androidSdk 'platforms\android-35')
|
||||
)
|
||||
$adb = if ($androidSdk) { Join-Path $androidSdk 'platform-tools\adb.exe' } else { '' }
|
||||
$adbOk = $adb -and (Test-Path -LiteralPath $adb)
|
||||
|
||||
$tokenPath = [string]$config.TokenFile
|
||||
if (-not [System.IO.Path]::IsPathRooted($tokenPath)) {
|
||||
$tokenPath = Join-Path $projectRoot $tokenPath
|
||||
}
|
||||
$tokenOk = (Test-Path -LiteralPath $tokenPath) -and (
|
||||
(Get-Content -LiteralPath $tokenPath -Raw).Trim().Length -ge 32
|
||||
)
|
||||
|
||||
$serverOk = $false
|
||||
$presetCount = 0
|
||||
if ($tokenOk) {
|
||||
try {
|
||||
$token = (Get-Content -LiteralPath $tokenPath -Raw).Trim()
|
||||
$baseUrl = ([string]$config.ServerAUrl).TrimEnd('/')
|
||||
$catalog = Invoke-RestMethod `
|
||||
-Uri "$baseUrl/api/v1/vehicles/$($config.VehicleId)/modes" `
|
||||
-Headers @{ Authorization = "Bearer $token" } -TimeoutSec 10
|
||||
$presetCount = @($catalog.modes | Where-Object { $_.origin -eq 'preset' }).Count
|
||||
$serverOk = $presetCount -gt 0
|
||||
} catch {
|
||||
$serverOk = $false
|
||||
} finally {
|
||||
$token = $null
|
||||
}
|
||||
}
|
||||
|
||||
$result = [pscustomobject]@{
|
||||
Passed = [bool]($javaOk -and $platform35 -and $adbOk -and $tokenOk -and $serverOk)
|
||||
Java17OrNewer = $javaOk
|
||||
Java = $javaSummary
|
||||
AndroidSdk = $androidSdk
|
||||
AndroidPlatform35 = [bool]$platform35
|
||||
Adb = [bool]$adbOk
|
||||
DeviceToken = [bool]$tokenOk
|
||||
ServerA = [bool]$serverOk
|
||||
PresetModes = $presetCount
|
||||
}
|
||||
$result
|
||||
if (-not $result.Passed) { exit 2 }
|
||||
Reference in New Issue
Block a user