| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "strings" |
| 7 | |
| 8 | "reasonix/internal/remote/bootstrap" |
| 9 | ) |
| 10 | |
| 11 | // CheckRemotePlatform verifies the connected host runs a supported OS |
| 12 | // (Linux/macOS). The connect wizard calls it before directory browsing, so |
| 13 | // unsupported hosts fail early with one message. |
| 14 | func (a *App) CheckRemotePlatform(hostID string) error { |
| 15 | rt, err := a.remoteRT() |
| 16 | if err != nil { |
| 17 | return err |
| 18 | } |
| 19 | return rt.CheckPlatform(a.bootContext(), hostID) |
| 20 | } |
| 21 | |
| 22 | // CheckPlatform applies the same ParseUname gate EnsureServe uses immediately |
| 23 | // after connection instead of failing later during serve bootstrap. |
| 24 | func (m *desktopRemoteManager) CheckPlatform(ctx context.Context, hostID string) error { |
| 25 | mh := m.managed(hostID) |
| 26 | if mh == nil || mh.client == nil { |
| 27 | return fmt.Errorf("host %q is not connected", hostID) |
| 28 | } |
| 29 | opCtx, cancel := managedOperationContext(ctx, mh) |
| 30 | defer cancel() |
| 31 | res, err := mh.client.Exec(opCtx, "uname -sm") |
| 32 | if err != nil || strings.TrimSpace(string(res.Stdout)) == "" { |
| 33 | return fmt.Errorf("remote host platform check failed: cannot detect OS (supported: Linux, macOS)") |
| 34 | } |
| 35 | if _, _, parseErr := bootstrap.ParseUname(string(res.Stdout)); parseErr != nil { |
| 36 | return fmt.Errorf("remote host platform check failed: %w", parseErr) |
| 37 | } |
| 38 | return nil |
| 39 | } |
| 40 |