mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-07-01 17:31:52 +00:00
48 lines
959 B
Go
48 lines
959 B
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/kairos-io/kairos/pkg/machine"
|
||
|
"github.com/kairos-io/kairos/pkg/utils"
|
||
|
"github.com/kairos-io/kairos/sdk/mounts"
|
||
|
"github.com/kairos-io/kairos/sdk/state"
|
||
|
)
|
||
|
|
||
|
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 {
|
||
|
runtime, err := state.NewRuntime()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
oem := runtime.OEM
|
||
|
if runtime.OEM.Name == "" {
|
||
|
oem = runtime.Persistent
|
||
|
}
|
||
|
|
||
|
if err := mounts.PrepareWrite(oem, "/tmp/oem"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
machine.Umount("/tmp/oem") //nolint:errcheck
|
||
|
}()
|
||
|
|
||
|
for k, v := range opts {
|
||
|
out, err := utils.SH(fmt.Sprintf(`grub2-editenv /tmp/oem/grubenv set "%s=%s"`, k, v))
|
||
|
if err != nil {
|
||
|
fmt.Printf("could not set boot option: %s\n", out+err.Error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|