$ErrorActionPreference = "Stop" $Hub = if ($env:TEMP_REMOTE_TOOL_HUB) { $env:TEMP_REMOTE_TOOL_HUB } else { "https://down.luckyfound.info" } $Token = $env:TEMP_REMOTE_TOOL_AGENT_TOKEN if (-not $Token) { throw "TEMP_REMOTE_TOOL_AGENT_TOKEN required" } $Work = if ($env:TEMP_REMOTE_TOOL_HOME) { $env:TEMP_REMOTE_TOOL_HOME } else { Join-Path $HOME ".temporary_remote_tool\go" } New-Item -ItemType Directory -Force -Path $Work | Out-Null $env:TEMP_REMOTE_TOOL_HUB = $Hub $env:TEMP_REMOTE_TOOL_AGENT_TOKEN = $Token $Bin = Join-Path $Work "temporary-remote-tool.exe" $Url = $Hub.TrimEnd("/") + "/install/bin/go/windows/amd64" try { Invoke-WebRequest -Uri $Url -OutFile $Bin & $Bin agent exit $LASTEXITCODE } catch { if (-not (Get-Command go -ErrorAction SilentlyContinue)) { throw "no prebuilt binary and go not installed" } $Zip = Join-Path $Work "go.zip" $Src = Join-Path $Work "src" Invoke-WebRequest -Uri ($Hub.TrimEnd("/") + "/install/archive/go.zip") -OutFile $Zip if (Test-Path $Src) { Remove-Item -Recurse -Force $Src } New-Item -ItemType Directory -Force -Path $Src | Out-Null Expand-Archive -Path $Zip -DestinationPath $Src -Force Push-Location (Join-Path $Src "go_client") go build -o $Bin . Pop-Location & $Bin agent }