diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 8a61c52..7a1b573 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -63,14 +63,14 @@ func Run(opts ...Option) error { if !machine.SentinelExist("bundles") { opts := c.Bundles.Options() err := bundles.RunBundles(opts...) - if !c.IgnoreBundleErrors && err != nil { + if c.FailOnBundleErrors && err != nil { return err } // Re-load providers bus.Reload() err = machine.CreateSentinel("bundles") - if !c.IgnoreBundleErrors && err != nil { + if c.FailOnBundleErrors && err != nil { return err } } diff --git a/internal/agent/hooks/bundles.go b/internal/agent/hooks/bundles.go new file mode 100644 index 0000000..fe132a9 --- /dev/null +++ b/internal/agent/hooks/bundles.go @@ -0,0 +1,30 @@ +package hook + +import ( + config "github.com/kairos-io/kairos/pkg/config" + "github.com/kairos-io/kairos/pkg/machine" + "github.com/kairos-io/kairos/sdk/bundles" +) + +type BundleOption struct{} + +func (b BundleOption) Run(c config.Config) error { + + machine.Mount("COS_PERSISTENT", "/usr/local") //nolint:errcheck + defer func() { + machine.Umount("/usr/local") + }() + + machine.Mount("COS_OEM", "/oem") //nolint:errcheck + defer func() { + machine.Umount("/oem") + }() + + opts := c.Install.Bundles.Options() + err := bundles.RunBundles(opts...) + if c.FailOnBundleErrors && err != nil { + return err + } + + return nil +} diff --git a/internal/agent/hooks/gruboptions.go b/internal/agent/hooks/gruboptions.go index d3df2f0..6ee29bd 100644 --- a/internal/agent/hooks/gruboptions.go +++ b/internal/agent/hooks/gruboptions.go @@ -2,29 +2,20 @@ package hook import ( "fmt" - "strings" config "github.com/kairos-io/kairos/pkg/config" + "github.com/kairos-io/kairos/pkg/machine" "github.com/kairos-io/kairos/pkg/utils" ) type GrubOptions struct{} func (b GrubOptions) Run(c config.Config) error { - oem, _ := utils.SH("blkid -L COS_OEM") - if oem == "" { - fmt.Println("OEM partition not found") - return nil // do not error out - } - - oem = strings.TrimSuffix(oem, "\n") - - oemMount, err := utils.SH(fmt.Sprintf("mkdir /tmp/oem && mount %s /tmp/oem", oem)) - if err != nil { - fmt.Printf("could not mount oem: %s\n", oemMount+err.Error()) - return nil // do not error out - } + machine.Mount("COS_OEM", "/tmp/oem") //nolint:errcheck + defer func() { + machine.Umount("/tmp/oem") + }() for k, v := range c.Install.GrubOptions { out, err := utils.SH(fmt.Sprintf("grub2-editenv /tmp/oem/grubenv set %s=%s", k, v)) if err != nil { @@ -33,6 +24,5 @@ func (b GrubOptions) Run(c config.Config) error { } } - utils.SH("umount /tmp/oem") //nolint:errcheck return nil } diff --git a/internal/agent/hooks/hook.go b/internal/agent/hooks/hook.go index 3be002a..8baa4d1 100644 --- a/internal/agent/hooks/hook.go +++ b/internal/agent/hooks/hook.go @@ -11,7 +11,8 @@ type Interface interface { var All = []Interface{ &RunStage{}, // Shells out to stages defined from the container image &GrubOptions{}, // Set custom GRUB options - &Lifecycle{}, // Handles poweroff/reboot by config options + &BundleOption{}, + &Lifecycle{}, // Handles poweroff/reboot by config options } func Run(c config.Config, hooks ...Interface) error {