You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.9 KiB
87 lines
3.9 KiB
$ErrorActionPreference = 'Stop'
|
|
$project = Split-Path -Parent $PSScriptRoot
|
|
Start-Transcript -Path (Join-Path $project 'runtime/close-all-tabs-transfer.log') -Force | Out-Null
|
|
$binary = Join-Path $project 'build/linux-arm64/tera-clone-demo-web'
|
|
$hash = (Get-FileHash -LiteralPath $binary -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
$script = @'
|
|
#!/bin/sh
|
|
set -eu
|
|
stage=/tmp/tera-close-all-tabs-20260908
|
|
mkdir -p "$stage"
|
|
wget -q -O "$stage/web" http://192.168.0.100:9001/web
|
|
echo '__HASH__ '"$stage/web" | sha256sum -c -
|
|
backup=/userdata/tera-backups/close-all-tabs-$(date +%Y%m%d-%H%M%S)
|
|
mkdir -p "$backup"
|
|
cp -p /usr/bin/tera-clone-demo-web "$backup/tera-clone-demo-web"
|
|
cp "$stage/web" /usr/bin/tera-clone-demo-web.next
|
|
chmod 0755 /usr/bin/tera-clone-demo-web.next
|
|
/etc/init.d/S61tera-clone-demo-web stop
|
|
mv /usr/bin/tera-clone-demo-web.next /usr/bin/tera-clone-demo-web
|
|
if ! /etc/init.d/S61tera-clone-demo-web start; then
|
|
cp "$backup/tera-clone-demo-web" /usr/bin/tera-clone-demo-web
|
|
/etc/init.d/S61tera-clone-demo-web start
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
if ! wget -q -O "$stage/status" http://127.0.0.1:8083/login/backend-status; then
|
|
/etc/init.d/S61tera-clone-demo-web stop
|
|
cp "$backup/tera-clone-demo-web" /usr/bin/tera-clone-demo-web
|
|
/etc/init.d/S61tera-clone-demo-web start
|
|
exit 1
|
|
fi
|
|
cat "$stage/status"
|
|
sha256sum /usr/bin/tera-clone-demo-web
|
|
echo "BACKUP=$backup"
|
|
echo CLOSE_ALL_TABS_DEPLOY_OK
|
|
'@
|
|
$script = $script.Replace('__HASH__', $hash).Replace("`r`n", "`n") + "`n"
|
|
$rule = 'TERA-close-all-tabs-' + [guid]::NewGuid().ToString('N')
|
|
$listener = New-Object System.Net.HttpListener
|
|
$listener.Prefixes.Add('http://192.168.0.100:9001/')
|
|
$serial = New-Object System.IO.Ports.SerialPort 'COM5',115200,'None',8,'One'
|
|
try {
|
|
New-NetFirewallRule -DisplayName $rule -Direction Inbound -Action Allow -Protocol TCP -LocalPort 9001 -RemoteAddress 192.168.0.223 | Out-Null
|
|
$listener.Start()
|
|
$serial.Open()
|
|
$serial.WriteLine('wget -q -O /tmp/deploy-close-all-tabs.sh http://192.168.0.100:9001/deploy.sh && sh /tmp/deploy-close-all-tabs.sh')
|
|
$deadline = [DateTime]::UtcNow.AddSeconds(90)
|
|
$output = ''
|
|
$pending = $listener.GetContextAsync()
|
|
while ([DateTime]::UtcNow -lt $deadline) {
|
|
if ($pending.IsCompleted) {
|
|
$context = $pending.GetAwaiter().GetResult()
|
|
if ($context.Request.RemoteEndPoint.Address.ToString() -ne '192.168.0.223') {
|
|
$context.Response.StatusCode = 403
|
|
$context.Response.Close()
|
|
} else {
|
|
$bytes = $null
|
|
switch ($context.Request.Url.AbsolutePath) {
|
|
'/deploy.sh' { $bytes = [Text.Encoding]::UTF8.GetBytes($script) }
|
|
'/web' { $bytes = [IO.File]::ReadAllBytes($binary) }
|
|
default { $context.Response.StatusCode = 404 }
|
|
}
|
|
if ($null -ne $bytes) {
|
|
$context.Response.ContentLength64 = $bytes.Length
|
|
$context.Response.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
}
|
|
$context.Response.Close()
|
|
}
|
|
$pending = $listener.GetContextAsync()
|
|
}
|
|
$chunk = $serial.ReadExisting()
|
|
if ($chunk) { $output += $chunk; Write-Host -NoNewline $chunk }
|
|
if ($output.Contains('CLOSE_ALL_TABS_DEPLOY_OK')) { break }
|
|
Start-Sleep -Milliseconds 100
|
|
}
|
|
if (-not $output.Contains('CLOSE_ALL_TABS_DEPLOY_OK')) { throw 'Deployment did not report success; inspect device console.' }
|
|
if (-not $output.Contains($hash)) { throw 'Deployed hash missing from console output.' }
|
|
$response = Invoke-WebRequest -UseBasicParsing 'http://192.168.0.223:8083/static/js/app.js?v=20260908-close-all-tabs-1'
|
|
if (-not $response.Content.Contains('function closeAllWorkspaceTabs()') -or -not $response.Content.Contains('event.altKey')) { throw 'Device is not serving the updated script.' }
|
|
Write-Output "VERIFIED deployed SHA256=$hash and Alt-click JavaScript"
|
|
} finally {
|
|
if ($serial.IsOpen) { $serial.Close() }
|
|
$serial.Dispose()
|
|
$listener.Close()
|
|
Remove-NetFirewallRule -DisplayName $rule -ErrorAction SilentlyContinue
|
|
Stop-Transcript | Out-Null
|
|
}
|
|
|