mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-02 01:26:43 +00:00
Also install fonts when installing grub (#144)
This commit is contained in:
@@ -134,7 +134,7 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
|
||||
// as they were before. We now use the bundled grub.efi provided by the shim package
|
||||
g.config.Logger.Infof("Generating grub files for efi on %s", target)
|
||||
var foundModules bool
|
||||
for _, m := range []string{"loopback.mod", "squash4.mod", "xzio.mod", "gzio.mod"} {
|
||||
for _, m := range constants.GetGrubModules() {
|
||||
err = fsutils.WalkDirFs(g.config.Fs, rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -160,6 +160,8 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
|
||||
}
|
||||
}
|
||||
|
||||
copyGrubFonts(g.config, rootDir, grubdir, systemgrub)
|
||||
|
||||
err = fsutils.MkdirAll(g.config.Fs, filepath.Join(cnst.EfiDir, "EFI/boot/"), cnst.DirPerm)
|
||||
if err != nil {
|
||||
g.config.Logger.Errorf("Error creating dirs: %s", err)
|
||||
@@ -225,3 +227,36 @@ func (g Grub) SetPersistentVariables(grubEnvFile string, vars map[string]string)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// copyGrubFonts will try to finds and copy the needed grub fonts into the system
|
||||
// rootdir is the dir where to search for the fonts
|
||||
// bootdir is the base dir where they will be copied
|
||||
func copyGrubFonts(cfg *agentConfig.Config, rootDir, bootDir, systemgrub string) {
|
||||
for _, m := range constants.GetGrubFonts() {
|
||||
var foundFont bool
|
||||
_ = fsutils.WalkDirFs(cfg.Fs, rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.Name() == m && strings.Contains(path, cfg.Arch) {
|
||||
fileWriteName := filepath.Join(bootDir, fmt.Sprintf("%s/%s-efi/fonts/%s", systemgrub, cfg.Arch, m))
|
||||
cfg.Logger.Debugf("Copying %s to %s", path, fileWriteName)
|
||||
fileContent, err := cfg.Fs.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading %s: %s", path, err)
|
||||
}
|
||||
err = cfg.Fs.WriteFile(fileWriteName, fileContent, cnst.FilePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing %s: %s", fileWriteName, err)
|
||||
}
|
||||
foundFont = true
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
})
|
||||
if !foundFont {
|
||||
// Not a real error as to fail install but a big warning
|
||||
cfg.Logger.Warnf("did not find grub font %s under %s", m, rootDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user