kairos-sdk/system/grub.go
Itxaka 3163cfbac0 Extract sdk into its own lib
This had some side effects:

 - Have to add some utils from the kairos/machine modules, which IMHO
   should not be there, they should be here if the are generic enough
 - Dropping the sdk dir, just have the modules in the root dir

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
2023-03-15 10:56:11 +01:00

49 lines
1.0 KiB
Go

package system
import (
"fmt"
"github.com/kairos-io/kairos-sdk/mounts"
"github.com/kairos-io/kairos-sdk/state"
"github.com/kairos-io/kairos-sdk/utils"
)
func SetGRUBOptions(opts map[string]string) Option {
return func(c *Changeset) error {
if len(opts) > 0 {
c.Add(func() error { return setGRUBOptions(opts) })
}
return nil
}
}
func setGRUBOptions(opts map[string]string) error {
mountPath := "/tmp/oem"
runtime, err := state.NewRuntime()
if err != nil {
return err
}
oem := runtime.OEM
if runtime.OEM.Name == "" {
oem = runtime.Persistent
}
if err := mounts.PrepareWrite(oem, mountPath); err != nil {
return err
}
defer func() {
oem.MountPoint = mountPath
mounts.Umount(oem) //nolint:errcheck
}()
for k, v := range opts {
out, err := utils.SH(fmt.Sprintf(`%s /tmp/oem/grubenv set "%s=%s"`, utils.FindCommand("grub2-editenv", []string{"grub2-editenv", "grub-editenv"}), k, v))
if err != nil {
fmt.Printf("could not set boot option: %s\n", out+err.Error())
}
}
return nil
}