|
| 1 | +namespace OpenClaw.SetupEngine; |
| 2 | + |
| 3 | +public sealed record SetupReviewSummary( |
| 4 | + string DistroTitle, |
| 5 | + string DistroDescription, |
| 6 | + string InstallerDescription, |
| 7 | + string InstallerBadge, |
| 8 | + string GatewayDescription, |
| 9 | + string GatewayEndpoint, |
| 10 | + string ExactCommands, |
| 11 | + string CompletionGatewaySummary); |
| 12 | + |
| 13 | +public static class SetupReviewSummaryBuilder |
| 14 | +{ |
| 15 | + public static SetupReviewSummary Build(SetupConfig config) |
| 16 | + { |
| 17 | + var distroName = Display(config.DistroName, "OpenClawGateway"); |
| 18 | + var baseDistro = Display(config.BaseDistro, "Ubuntu-24.04"); |
| 19 | + var gatewayBind = Display(config.Gateway.Bind, "loopback"); |
| 20 | + var gatewayPort = config.GatewayPort; |
| 21 | + var installPath = Path.Combine(SetupContext.ResolveLocalDataDir(), "wsl", distroName); |
| 22 | + var gatewayDataPath = Path.Combine(SetupContext.ResolveDataDir(), "gateways.json"); |
| 23 | + var installUrl = config.Gateway.InstallUrl ?? GatewayLkgVersion.DefaultInstallUrl; |
| 24 | + var installerHost = TryGetHttpsHost(installUrl); |
| 25 | + var installerDescription = installerHost is null |
| 26 | + ? "Installer URL is not HTTPS; setup will stop before downloading anything." |
| 27 | + : $"Fetched over HTTPS from {installerHost}; runs as a non-root {Display(config.Wsl.User, "openclaw")} user inside the instance."; |
| 28 | + var installerBadge = installerHost is null ? "Invalid URL" : "HTTPS"; |
| 29 | + var isLanBind = gatewayBind.Equals("lan", StringComparison.OrdinalIgnoreCase); |
| 30 | + var gatewayDescription = isLanBind |
| 31 | + ? "LAN bind enabled — reachable from this PC and your local network according to Windows firewall/routing." |
| 32 | + : "Loopback only — not reachable from your network or the internet."; |
| 33 | + var gatewayEndpoint = isLanBind ? $"LAN:{gatewayPort}" : $"127.0.0.1:{gatewayPort}"; |
| 34 | + var wslCommand = "wsl " + string.Join(' ', WslInstallSupport.BuildDirectInstallArgs(baseDistro, distroName, installPath)); |
| 35 | + var installCommand = string.IsNullOrWhiteSpace(config.Gateway.Version) |
| 36 | + ? "curl -fsSL --proto '=https' --tlsv1.2 <install-url> | bash" |
| 37 | + : $"curl -fsSL --proto '=https' --tlsv1.2 <install-url> | bash -s -- --version {config.Gateway.Version.Trim()}"; |
| 38 | + |
| 39 | + return new SetupReviewSummary( |
| 40 | + DistroTitle: $"Install an isolated {baseDistro} instance", |
| 41 | + DistroDescription: $"WSL distro \"{distroName}\" at {installPath}. Separate from any Linux distributions you already have.", |
| 42 | + InstallerDescription: installerDescription, |
| 43 | + InstallerBadge: installerBadge, |
| 44 | + GatewayDescription: gatewayDescription, |
| 45 | + GatewayEndpoint: gatewayEndpoint, |
| 46 | + ExactCommands: string.Join( |
| 47 | + Environment.NewLine, |
| 48 | + wslCommand, |
| 49 | + installCommand, |
| 50 | + $"openclaw config set gateway.bind {gatewayBind} · port {gatewayPort}", |
| 51 | + "openclaw gateway install --force (systemd --user service)", |
| 52 | + $"writes -> {installPath}", |
| 53 | + $"writes -> {gatewayDataPath} + identity"), |
| 54 | + CompletionGatewaySummary: $"{distroName} · {gatewayEndpoint}"); |
| 55 | + } |
| 56 | + |
| 57 | + private static string Display(string? value, string fallback) |
| 58 | + => string.IsNullOrWhiteSpace(value) ? fallback : value.Trim(); |
| 59 | + |
| 60 | + private static string? TryGetHttpsHost(string installUrl) |
| 61 | + => Uri.TryCreate(installUrl, UriKind.Absolute, out var uri) |
| 62 | + && uri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) |
| 63 | + ? uri.Host |
| 64 | + : null; |
| 65 | +} |
0 commit comments