Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ Continue? [yes]:
2025/08/03 00:11:19 rebooting system
```

## Non-interactive installation

You can run `boot-to-talos` in fully automated mode by passing the required flags.
To skip all interactive prompts, use the `-yes` flag:

```console
boot-to-talos -yes
```

You can also specify all parameters explicitly:

```console
boot-to-talos -yes -disk /dev/sda -image ghcr.io/cozystack/cozystack/talos:v1.10.5 -image-size-gib 4 -extra-kernel-arg "console=ttyS0"
```

## Available command-line flags

| Flag | Description | Example |
|-----------------------|--------------------------------------------------------------------|-------------------------------------------------|
| `-yes` | Run non-interactively, do not ask for confirmation | `-yes` |
| `-disk string` | Target disk (will be wiped) | `-disk /dev/sda` |
| `-image string` | Talos installer image (default: `ghcr.io/cozystack/cozystack/talos:v1.10.5`) | `-image ghcr.io/cozystack/cozystack/talos:v1.10.5` |
| `-image-size-gib uint`| Size of image.raw in GiB (default: 2) | `-image-size-gib 4` |
| `-extra-kernel-arg value` | Extra kernel argument (can be repeated) | `-extra-kernel-arg "console=ttyS0"` |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other flags in this table, the type for -extra-kernel-arg should be string instead of value. This makes the documentation clearer for users.

Suggested change
| `-extra-kernel-arg value` | Extra kernel argument (can be repeated) | `-extra-kernel-arg "console=ttyS0"` |
| `-extra-kernel-arg string` | Extra kernel argument (can be repeated) | `-extra-kernel-arg "console=ttyS0"` |


**Tip:** All flags can be combined. If a flag is not provided, the installer will prompt for input (unless `-yes` is used).

---

Created for the Cozystack project. 🚀
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ func (m *multiFlag) Set(v string) error { *m = append(*m, v); return nil }
var (
imageFlag string
diskFlag string
yesFlag bool
)

func init() {
flag.StringVar(&imageFlag, "image",
"ghcr.io/cozystack/cozystack/talos:v1.10.5", "Talos installer image")
flag.StringVar(&diskFlag, "disk", "", "target disk (will be wiped)")
flag.BoolVar(&yesFlag, "yes", false, "automatic yes to prompts")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The help text for the -yes flag could be more descriptive to better align with its function and the documentation in README.md. A more explicit description would clarify that it accepts defaults and skips all interactive prompts.

Suggested change
flag.BoolVar(&yesFlag, "yes", false, "automatic yes to prompts")
flag.BoolVar(&yesFlag, "yes", false, "Run non-interactively, accepting defaults and skipping confirmations")

}

/* ------------------------------ helpers ----------------------------------- */
Expand Down Expand Up @@ -96,6 +98,10 @@ func fakeCert() string {
var reader = bufio.NewReader(os.Stdin)

func ask(msg, def string) string {
if yesFlag {
fmt.Printf("%s [%s]: %s\n", msg, def, def)
return def
}
fmt.Printf("%s [%s]: ", msg, def)
t, _ := reader.ReadString('\n')
t = strings.TrimSpace(t)
Expand All @@ -106,6 +112,9 @@ func ask(msg, def string) string {
}

func askRequired(msg string) string {
if yesFlag {
log.Fatalf("missing required input for: %s (cannot auto-fill)", msg)
}
for {
fmt.Printf("%s: ", msg)
t, _ := reader.ReadString('\n')
Expand All @@ -117,6 +126,10 @@ func askRequired(msg string) string {
}

func askYesNo(msg string, def bool) bool {
if yesFlag {
fmt.Printf("%s [%s]: %v\n", msg, map[bool]string{true: "yes", false: "no"}[def], def)
return def
}
Comment on lines +129 to +132

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation creates a new map on every function call, which is inefficient. Using an if/else block would be more readable and performant.

Additionally, printing the string "yes" or "no" instead of the boolean true or false makes the non-interactive output more consistent with the ask function's behavior and the user-facing prompt.

Suggested change
if yesFlag {
fmt.Printf("%s [%s]: %v\n", msg, map[bool]string{true: "yes", false: "no"}[def], def)
return def
}
if yesFlag {
defStr := "no"
if def {
defStr = "yes"
}
fmt.Printf("%s [%s]: %s\n", msg, defStr, defStr)
return def
}

defStr := "yes"
if !def {
defStr = "no"
Expand Down