blob: 38c15011408083e988aaad9a5016c4e9fa3fde00 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Tim Windelschmidt7006caf2024-02-27 16:49:39 +01004package main
5
6import (
7 _ "embed"
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +02008 "fmt"
Tim Windelschmidt7006caf2024-02-27 16:49:39 +01009 "log"
10
11 "github.com/spf13/cobra"
12
13 "source.monogon.dev/metropolis/cli/metroctl/core"
14)
15
16var genusbCmd = &cobra.Command{
17 Use: "genusb target",
18 Short: "Generates a Metropolis installer disk or image.",
19 Example: "metroctl install --bundle=metropolis-v0.1.zip genusb /dev/sdx",
Tim Windelschmidtfc6e1cf2024-09-18 17:34:07 +020020 Args: PrintUsageOnWrongArgs(cobra.ExactArgs(1)), // One positional argument: the target
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +020021 RunE: func(cmd *cobra.Command, args []string) error {
22 params, err := makeNodeParams()
23 if err != nil {
24 return err
25 }
Tim Windelschmidt7006caf2024-02-27 16:49:39 +010026
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +020027 installerPath, err := cmd.Flags().GetString("installer")
28 if err != nil {
29 return err
30 }
Tim Windelschmidt7006caf2024-02-27 16:49:39 +010031
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +020032 installer, err := external("installer", "_main/metropolis/installer/kernel.efi", &installerPath)
33 if err != nil {
34 return err
35 }
36 bundle, err := external("bundle", "_main/metropolis/node/bundle.zip", bundlePath)
37 if err != nil {
38 return err
39 }
Tim Windelschmidt7006caf2024-02-27 16:49:39 +010040
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +020041 installerImageArgs := core.MakeInstallerImageArgs{
42 TargetPath: args[0],
43 Installer: installer,
44 NodeParams: params,
45 Bundle: bundle,
46 }
Tim Windelschmidt7006caf2024-02-27 16:49:39 +010047
Tim Windelschmidt0b4fb8c2024-09-18 17:34:23 +020048 log.Printf("Generating installer image (this can take a while, see issues/92).")
49 if err := core.MakeInstallerImage(installerImageArgs); err != nil {
50 return fmt.Errorf("failed to create installer: %w", err)
51 }
52 return nil
53 },
Tim Windelschmidt7006caf2024-02-27 16:49:39 +010054}
55
56func init() {
57 genusbCmd.Flags().StringP("installer", "i", "", "Path to the Metropolis installer to use when installing")
58 installCmd.AddCommand(genusbCmd)
59}