| 1 | package guestos |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/sha256" |
| 6 | "fmt" |
| 7 | "os" |
| 8 | |
| 9 | "os/exec" |
| 10 | "path/filepath" |
| 11 | |
| 12 | "github.com/sylvinus/agent-vm/internal/cage" |
| 13 | "golang.org/x/sys/windows" |
| 14 | ) |
| 15 | |
| 16 | func WindowsInstallCommand(ctx context.Context, profile, kit string, install Installation) (*exec.Cmd, error) { |
| 17 | system, err := windows.GetSystemDirectory() |
| 18 | if err != nil { |
| 19 | return nil, err |
| 20 | } |
| 21 | state, err := cage.StoragePhysicalPath(filepath.Join(profile, "state")) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | manifest, err := RequiredNativeComponents(kit, Windows11) |
| 26 | if err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | manifestPath := filepath.Join(profile, "windows-components-required.json") |
| 30 | if err = WriteNativeComponentManifest(manifestPath, manifest); err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | data, err := os.ReadFile(manifestPath) |
| 34 | if err != nil { |
| 35 | return nil, err |
| 36 | } |
| 37 | digest := fmt.Sprintf("%x", sha256.Sum256(data)) |
| 38 | cmd := exec.CommandContext(ctx, filepath.Join(system, "WindowsPowerShell", "v1.0", "powershell.exe"), "-NoLogo", "-NoProfile", "-ExecutionPolicy", "RemoteSigned", "-File", filepath.Join(kit, "setup-windows-guest.ps1"), "-Profile", profile, "-State", state, "-InstallationID", install.ID.String(), "-IsoPath", install.Media, "-ExpectedIsoSha256", install.SHA256, "-ManifestPath", manifestPath, "-ManifestSHA256", digest) |
| 39 | return cmd, nil |
| 40 | } |