diff --git a/pkg/utils/grub.go b/pkg/utils/grub.go index 3fcb03a..762eacf 100644 --- a/pkg/utils/grub.go +++ b/pkg/utils/grub.go @@ -501,7 +501,7 @@ func ReadPersistentVariables(grubEnvFile string, c *agentConfig.Config) (map[str if err != nil { return vars, err } - for _, a := range strings.Split(string(f), "\n") { + for a := range strings.SplitSeq(string(f), "\n") { // comment or fillup, so skip if strings.HasPrefix(a, "#") { continue @@ -510,8 +510,8 @@ func ReadPersistentVariables(grubEnvFile string, c *agentConfig.Config) (map[str continue } splitted := strings.Split(a, "=") - if len(splitted) == 2 { - vars[splitted[0]] = splitted[1] + if len(splitted) >= 2 { + vars[splitted[0]] = strings.Join(splitted[1:], "=") } else { return vars, fmt.Errorf("invalid format for %s", a) } diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index de31419..b2b8750 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -866,6 +866,22 @@ var _ = Describe("Utils", Label("utils"), func() { Expect(readVars["key2"]).To(Equal("value2")) Expect(readVars["key3"]).To(Equal("value4")) }) + It("Should work with multiple extra cmdline", func() { + temp, err := os.CreateTemp("", "grub-*") + Expect(err).ShouldNot(HaveOccurred()) + defer os.Remove(temp.Name()) + data := `# GRUB Environment Block +extra_cmdline=fips=1 selinux=0 +########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################` + Expect(fs.WriteFile(temp.Name(), []byte(data), constants.FilePerm)).To(BeNil()) + Expect(utils.SetPersistentVariables( + temp.Name(), map[string]string{"next_entry": "statereset"}, config, + )).To(BeNil()) + readVars, err := utils.ReadPersistentVariables(temp.Name(), config) + Expect(err).To(BeNil()) + Expect(readVars["next_entry"]).To(Equal("statereset")) + Expect(readVars["extra_cmdline"]).To(Equal("fips=1 selinux=0")) + }) }) }) Describe("CreateSquashFS", Label("CreateSquashFS"), func() {