| 1 | |
| 2 | package guestos |
| 3 | |
| 4 | import ( |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | ) |
| 8 | |
| 9 | |
| 10 | const ( |
| 11 | Debian13 = "debian-13" |
| 12 | MacOS = "macos" |
| 13 | Windows11 = "windows-11" |
| 14 | ) |
| 15 | |
| 16 | |
| 17 | type MacRestore struct { |
| 18 | Version string `json:"version"` |
| 19 | Build string `json:"build"` |
| 20 | URL string `json:"url"` |
| 21 | MinimumCPUs int `json:"minimumCPUs"` |
| 22 | MinimumMemoryBytes uint64 `json:"minimumMemoryBytes"` |
| 23 | } |
| 24 | |
| 25 | |
| 26 | type Inspection struct { |
| 27 | Guest string `json:"guest"` |
| 28 | HostCheckPassed bool `json:"hostCheckPassed"` |
| 29 | WorkbenchSupport string `json:"workbenchSupport"` |
| 30 | Detail string `json:"detail"` |
| 31 | Restore *MacRestore `json:"restore,omitempty"` |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | func HasNativeWorkbenchKit(executable, system string) bool { |
| 37 | var files []string |
| 38 | switch system { |
| 39 | case MacOS: |
| 40 | files = []string{"prepare-macos-media.sh", "provision-macos-workbench.sh", "project/cage-sshfs", "native-browser/macos-native-browser.mjs", "cage-finish-initial-setup"} |
| 41 | case Windows11: |
| 42 | files = []string{"new-windows-guest.ps1", "setup-windows-guest.ps1", "windows-host-image.ps1", "complete-windows-guest.ps1", "install-windows-host-manager.ps1", "payload/Cage.HyperVManager.exe", "payload/Cage.GuestClipboard.exe"} |
| 43 | default: |
| 44 | return false |
| 45 | } |
| 46 | for _, name := range files { |
| 47 | info, err := os.Stat(filepath.Join(filepath.Dir(executable), "guest-os", name)) |
| 48 | if err != nil || !info.Mode().IsRegular() { |
| 49 | return false |
| 50 | } |
| 51 | } |
| 52 | return true |
| 53 | } |
| 54 | |
| 55 | func nativeWorkbenchSupport(system string, hostReady bool) string { |
| 56 | if !hostReady { |
| 57 | return "host-not-ready" |
| 58 | } |
| 59 | exe, err := os.Executable() |
| 60 | if err != nil || !HasNativeWorkbenchKit(exe, system) { |
| 61 | return "installation-kit-missing" |
| 62 | } |
| 63 | return "desktop-installer" |
| 64 | } |