diff --git a/internal/agent/hooks/lifecycle.go b/internal/agent/hooks/lifecycle.go index c3f7284e..ef8f05b8 100644 --- a/internal/agent/hooks/lifecycle.go +++ b/internal/agent/hooks/lifecycle.go @@ -9,13 +9,13 @@ import ( type Lifecycle struct{} -func (s Lifecycle) Run(c config.Config, spec v1.Spec) error { - if spec.ShouldReboot() || c.Install.Reboot { +func (s Lifecycle) Run(_ config.Config, spec v1.Spec) error { + if spec.ShouldReboot() { time.Sleep(5) utils.Reboot() } - if spec.ShouldShutdown() || c.Install.Poweroff { + if spec.ShouldShutdown() { time.Sleep(5) utils.PowerOFF() } diff --git a/internal/agent/install.go b/internal/agent/install.go index 0420a236..aa5d4f90 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -63,28 +63,16 @@ func ManualInstall(c, sourceImgURL, device string, reboot, poweroff, strictValid } cliConf := generateInstallConfForCLIArgs(sourceImgURL) + cliConfManualArgs := generateInstallConfForManualCLIArgs(device, reboot, poweroff) cc, err := config.Scan(collector.Directories(configSource), - collector.Readers(strings.NewReader(cliConf)), + collector.Readers(strings.NewReader(cliConf), strings.NewReader(cliConfManualArgs)), collector.MergeBootLine, collector.StrictValidation(strictValidations), collector.NoLogs) if err != nil { return err } - - if reboot { - // Override from flags! - cc.Install.Reboot = true - } - - if poweroff { - // Override from flags! - cc.Install.Poweroff = true - } - if device != "" { - // Override from flags! - cc.Install.Device = device - } + return RunInstall(cc) } @@ -350,3 +338,18 @@ func generateInstallConfForCLIArgs(sourceImageURL string) string { uri: %s `, sourceImageURL) } + +// generateInstallConfForManualCLIArgs creates a kairos configuration for flags passed via manual install +func generateInstallConfForManualCLIArgs(device string, reboot, poweroff bool) string { + cfg := fmt.Sprintf(`install: + reboot: %t + poweroff: %t +`, reboot, poweroff) + + if device != "" { + cfg += fmt.Sprintf(` + device: %s +`, device) + } + return cfg +}