param( [string]$Server = 'wss://ttstd.com/ads', [string]$ConnectAddress = '175.178.213.60:443', [string]$Device = 'home-phone', [string]$Target = '192.168.100.141:5555', [string]$AdbServer, [string]$AdbSerial ) $ErrorActionPreference = 'Stop' $projectRoot = Split-Path $PSScriptRoot -Parent $tokenFile = Join-Path $projectRoot 'config/private/agent.env' if (-not $env:ADS_AGENT_TOKEN -and (Test-Path -LiteralPath $tokenFile)) { foreach ($line in Get-Content -LiteralPath $tokenFile) { if ($line.StartsWith('ADS_AGENT_TOKEN=')) { $env:ADS_AGENT_TOKEN = $line.Substring(16) } } } if (-not $env:ADS_AGENT_TOKEN) { throw 'Set ADS_AGENT_TOKEN or provide config/private/agent.env' } $arguments = @('--server', $Server, '--device', $Device) if ($ConnectAddress) { $arguments += @('--connect-address', $ConnectAddress) } if ($AdbSerial) { if (-not $AdbServer) { $AdbServer = '127.0.0.1:5037' } $arguments += @('--adb-server', $AdbServer, '--adb-serial', $AdbSerial) } else { $arguments += @('--target', $Target) } & (Join-Path $projectRoot 'bin/ads-agent.exe') @arguments exit $LASTEXITCODE