param( [string]$Root='C:\ProgramData\VibeCodingRemoteCompilation', [string]$Address='192.168.5.222', [string]$AllowedSubnet='192.168.5.0/24', [int]$Port=8765 ) $ErrorActionPreference='Stop' $configPath=Join-Path $Root 'bin\RemoteCompileService.xml' [xml]$config=Get-Content -LiteralPath $configPath -Raw $active=@(Get-ChildItem -LiteralPath "$Root\data\projects" -Filter active-build -Recurse -File -ErrorAction SilentlyContinue) if($active.Count){throw 'A build is active; wait for completion before upgrading.'} $exe=Join-Path $PSScriptRoot 'remotecompile-windows-amd64.exe' if(-not(Test-Path -LiteralPath $exe)){throw 'Upload the new server executable next to this script.'} $tlsDir=Join-Path $Root 'bin\tls' & $exe -init-tls-host $Address -tls-dir $tlsDir if($LASTEXITCODE -ne 0){throw 'Certificate generation failed'} $backup="$configPath.before-lan.xml" if(-not(Test-Path -LiteralPath $backup)){Copy-Item -LiteralPath $configPath -Destination $backup} Stop-Service RemoteCompile (Get-Service RemoteCompile).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(45)) Copy-Item -LiteralPath $exe -Destination "$Root\bin\remotecompile.exe" -Force $config.service.arguments="-listen $($Address):$Port -data `"$Root\data`" -tasks :app:assembleDebug -tls-cert `"$tlsDir\server.crt`" -tls-key `"$tlsDir\server.key`"" [IO.File]::WriteAllText($configPath,$config.OuterXml,(New-Object Text.UTF8Encoding($false))) if(Get-NetFirewallRule -Name 'RemoteCompile-LAN-HTTPS' -ErrorAction SilentlyContinue){Remove-NetFirewallRule -Name 'RemoteCompile-LAN-HTTPS'} New-NetFirewallRule -Name 'RemoteCompile-LAN-HTTPS' -DisplayName 'Remote Compilation LAN HTTPS' -Direction Inbound -Action Allow -Protocol TCP -LocalAddress $Address -LocalPort $Port -RemoteAddress $AllowedSubnet -Profile Any -Program "$Root\bin\remotecompile.exe" | Out-Null Start-Service RemoteCompile Copy-Item -LiteralPath "$tlsDir\server.crt" -Destination (Join-Path $env:USERPROFILE '.remotecompile-server.crt') -Force Get-Service RemoteCompile | Select-Object Name,Status Write-Output "LAN endpoint: https://$($Address):$Port" Write-Output 'Copy .remotecompile-server.crt to the client and configure it in the plugin. Never copy server.key.'