Harden generic installation and startup, preserve station settings and coalesce mail reads
This commit is contained in:
1 parent
3f6d35690b
commit
5358cad695
14 files changed
+398
-146
No files matched your search
+44
-19
@@ -1,28 +1,53 @@
|
||||
param([string]$BpqRoot,[int]$Port=8090,[int]$HttpPort,[int]$RadioPort,[string]$SysopUser,[string]$ForwardPeer,[switch]$CheckOnly,[switch]$AutoStart,[switch]$EnableLAN)
|
||||
param([string]$BpqRoot,[int]$Port,[int]$HttpPort,[int]$RadioPort,[string]$SysopUser,[string]$ForwardPeer,[string]$CmsPeer,[string]$VaraLogPath,[string]$NodeExe,[switch]$EnableRadioCAT,[switch]$DisableRadioCAT,[switch]$CheckOnly,[switch]$AutoStart,[switch]$EnableLAN,[switch]$Restart)
|
||||
$ErrorActionPreference='Stop'
|
||||
$nodeExe=(Get-Command node.exe -ErrorAction Stop).Source
|
||||
$major=[int]((& $nodeExe --version).TrimStart('v').Split('.')[0])
|
||||
if($major -lt 20){throw 'Serve Node.js 20 o successivo nel PATH.'}
|
||||
if($EnableRadioCAT -and $DisableRadioCAT){throw 'Scegliere una sola opzione CAT.'}
|
||||
if($AutoStart -and !$CheckOnly -and ($env:BPQ_CONSOLE_CONFIG -or $env:BPQ_ROOT -or $env:BPQ_CONSOLE_PORT)){throw 'Per -AutoStart usare console.config.json nella cartella del progetto, senza override BPQ_* temporanei.'}
|
||||
$configPath=if($env:BPQ_CONSOLE_CONFIG){$env:BPQ_CONSOLE_CONFIG}else{Join-Path $PSScriptRoot 'console.config.json'}
|
||||
$saved=$null
|
||||
if(Test-Path -LiteralPath $configPath){try{$saved=Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json}catch{throw 'Configurazione locale non leggibile: correggere il JSON prima di reinstallare.'}}
|
||||
if(!$NodeExe){$NodeExe=if($saved.nodeExe -and (Test-Path -LiteralPath $saved.nodeExe)){$saved.nodeExe}else{(Get-Command node.exe -ErrorAction SilentlyContinue).Source}}
|
||||
if(!$NodeExe -or !(Test-Path -LiteralPath $NodeExe)){throw 'Installare Node.js 20 o successivo, oppure specificare -NodeExe con il percorso di node.exe.'}
|
||||
$version=& $NodeExe --version
|
||||
if($LASTEXITCODE -ne 0 -or $version -notmatch '^v(\d+)\.' -or [int]$Matches[1] -lt 20){throw 'Serve Node.js 20 o successivo.'}
|
||||
if(!$BpqRoot){
|
||||
$candidates=@((Join-Path $env:APPDATA 'BPQ32'))
|
||||
$running=Get-CimInstance Win32_Process | Where-Object {$_.Name -match '^(BPQTerminal|BPQMail|BPQChat|bpq32)\.exe$'}
|
||||
foreach($proc in $running){if($proc.ExecutablePath){$candidates+=Split-Path $proc.ExecutablePath}}
|
||||
$BpqRoot=$candidates | Where-Object {Test-Path -LiteralPath (Join-Path $_ 'BPQ32.cfg')} | Select-Object -First 1
|
||||
if($env:BPQ_ROOT){$BpqRoot=$env:BPQ_ROOT}
|
||||
elseif($saved.bpqRoot){$BpqRoot=$saved.bpqRoot}
|
||||
else{
|
||||
$candidates=@((Join-Path $env:APPDATA 'BPQ32'))
|
||||
$running=Get-CimInstance Win32_Process | Where-Object {$_.Name -match '^(BPQTerminal|BPQMail|BPQChat|bpq32)\.exe$'}
|
||||
foreach($proc in $running){if($proc.ExecutablePath){$candidates+=Split-Path $proc.ExecutablePath}}
|
||||
$BpqRoot=$candidates | Where-Object {Test-Path -LiteralPath (Join-Path $_ 'BPQ32.cfg')} | Select-Object -First 1
|
||||
}
|
||||
if(!$BpqRoot){throw 'BPQ32.cfg non trovato. Usare -BpqRoot con la cartella dati BPQ.'}
|
||||
}
|
||||
$arguments=@((Join-Path $PSScriptRoot 'install.mjs'),'--bpq-root',$BpqRoot,'--port',"$Port")
|
||||
foreach($option in @(@('http-port',$HttpPort),@('radio-port',$RadioPort),@('sysop-user',$SysopUser),@('forward-peer',$ForwardPeer))){if($option[1]){$arguments+=@('--'+$option[0],"$($option[1])")}}
|
||||
$vara=Get-Process -Name VARA -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if($vara.Path){$varaLog=Join-Path (Split-Path $vara.Path) 'VARAHF.log';if(Test-Path -LiteralPath $varaLog){$arguments+=@('--vara-log',$varaLog)}}
|
||||
if($CheckOnly){$arguments+='--check-only'}
|
||||
& $nodeExe @arguments
|
||||
if(!$CheckOnly -and $Restart){
|
||||
$pending=Join-Path $PSScriptRoot 'winlink-radio.session.json'
|
||||
if((Test-Path -LiteralPath $pending) -and (Get-Content -LiteralPath $pending -Raw | ConvertFrom-Json).restoring){throw 'Attendere il ripristino della sessione Winlink radio prima di reinstallare e riavviare.'}
|
||||
}
|
||||
$targetPort=if($PSBoundParameters.ContainsKey('Port')){$Port}elseif($env:BPQ_CONSOLE_PORT){[int]$env:BPQ_CONSOLE_PORT}elseif($saved.port){[int]$saved.port}else{8090}
|
||||
if($targetPort -ge 1024 -and $targetPort -le 65535){
|
||||
$listener=Get-NetTCPConnection -LocalPort $targetPort -State Listen -ErrorAction SilentlyContinue
|
||||
if($listener){$owner=Get-CimInstance Win32_Process -Filter "ProcessId=$($listener[0].OwningProcess)";if($owner.Name -ne 'node.exe' -or !$owner.CommandLine -or $owner.CommandLine.IndexOf((Join-Path $PSScriptRoot 'server.mjs'),[StringComparison]::OrdinalIgnoreCase) -lt 0){throw "Porta $targetPort occupata da un altro processo. Specificare -Port con una porta libera."}}
|
||||
}
|
||||
$nodeArgs=@((Join-Path $PSScriptRoot 'install.mjs'),'--bpq-root',$BpqRoot,'--config-path',$configPath)
|
||||
$mapping=@{Port='port';HttpPort='http-port';RadioPort='radio-port';SysopUser='sysop-user';ForwardPeer='forward-peer';CmsPeer='cms-peer';VaraLogPath='vara-log'}
|
||||
foreach($name in $mapping.Keys){if($PSBoundParameters.ContainsKey($name)){$nodeArgs+=@('--'+$mapping[$name],[string](Get-Variable -Name $name -ValueOnly))}}
|
||||
if(!$VaraLogPath){$vara=Get-Process -Name VARA -ErrorAction SilentlyContinue | Select-Object -First 1;if($vara.Path){$varaLog=Join-Path (Split-Path $vara.Path) 'VARAHF.log';if(Test-Path -LiteralPath $varaLog){$nodeArgs+=@('--vara-log',$varaLog)}}}
|
||||
if($EnableRadioCAT){$nodeArgs+='--enable-radio-cat'}
|
||||
if($DisableRadioCAT){$nodeArgs+='--disable-radio-cat'}
|
||||
if($CheckOnly){$nodeArgs+='--check-only'}
|
||||
& $NodeExe @nodeArgs
|
||||
if($LASTEXITCODE -ne 0){throw 'Installazione interrotta: verifica BPQ fallita.'}
|
||||
if($CheckOnly){return}
|
||||
if($AutoStart){
|
||||
$action=New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ('-NoProfile -WindowStyle Hidden -File "'+(Join-Path $PSScriptRoot 'Start-Console.ps1')+'"') -WorkingDirectory $PSScriptRoot
|
||||
$trigger=New-ScheduledTaskTrigger -AtLogOn -User ([Security.Principal.WindowsIdentity]::GetCurrent().Name)
|
||||
Register-ScheduledTask -TaskName 'BPQ-WebConsole' -Action $action -Trigger $trigger -Description 'BPQ web console locale' -Force | Out-Null
|
||||
$identity=[Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||
$action=New-ScheduledTaskAction -Execute (Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe') -Argument ('-NoProfile -ExecutionPolicy RemoteSigned -WindowStyle Hidden -File "'+(Join-Path $PSScriptRoot 'Start-Console.ps1')+'"') -WorkingDirectory $PSScriptRoot
|
||||
$trigger=New-ScheduledTaskTrigger -AtLogOn -User $identity
|
||||
$principal=New-ScheduledTaskPrincipal -UserId $identity -LogonType Interactive -RunLevel Limited
|
||||
Register-ScheduledTask -TaskName 'BPQ-WebConsole' -Action $action -Trigger $trigger -Principal $principal -Description 'BPQ web console locale' -Force | Out-Null
|
||||
}
|
||||
& (Join-Path $PSScriptRoot 'Start-Console.ps1') -Restart:$Restart
|
||||
if($EnableLAN){& (Join-Path $PSScriptRoot 'Enable-LAN.ps1')}
|
||||
& (Join-Path $PSScriptRoot 'Start-Console.ps1')
|
||||
Write-Host "Pannello: http://127.0.0.1:$Port"
|
||||
$current=Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json
|
||||
$displayPort=if($env:BPQ_CONSOLE_PORT){$env:BPQ_CONSOLE_PORT}else{$current.port}
|
||||
Write-Host "Pannello: http://127.0.0.1:$displayPort"
|
||||
Reference in new issue
Block a user