From 79480eb5c903d9f90e66b4c7ccfbb9babd7b50af Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 12 Sep 2023 22:45:29 +0200 Subject: [PATCH 1/4] Also install fonts when installing grub Signed-off-by: Itxaka --- pkg/utils/grub.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/utils/grub.go b/pkg/utils/grub.go index b35aac54..5d420360 100644 --- a/pkg/utils/grub.go +++ b/pkg/utils/grub.go @@ -160,6 +160,34 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool, } } + var foundFonts bool + for _, m := range []string{"ascii.pf2", "euro.pf2", "unicode.pf2"} { + err = fsutils.WalkDirFs(g.config.Fs, rootDir, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + if d.Name() == m && strings.Contains(path, g.config.Arch) { + fileWriteName := filepath.Join(bootDir, fmt.Sprintf("%s/%s-efi/fonts/%s", systemgrub, g.config.Arch, m)) + g.config.Logger.Debugf("Copying %s to %s", path, fileWriteName) + fileContent, err := g.config.Fs.ReadFile(path) + if err != nil { + return fmt.Errorf("error reading %s: %s", path, err) + } + err = g.config.Fs.WriteFile(fileWriteName, fileContent, cnst.FilePerm) + if err != nil { + return fmt.Errorf("error writing %s: %s", fileWriteName, err) + } + foundFonts = true + return nil + } + return err + }) + if !foundFonts { + // Not a real error as to fail install but a big warning + g.config.Logger.Warnf("did not find grub font %s under %s", m, rootDir) + } + } + 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) From a10ea1e5c21b954268fda9a7e434af4ca900cdc2 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 13 Sep 2023 09:31:00 +0200 Subject: [PATCH 2/4] Fix user-agent for http client Otherwise github returns 403, probably to prevent abuse from bots and crawlers Signed-off-by: Itxaka --- pkg/http/client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/http/client.go b/pkg/http/client.go index 4cd78fbd..771458ac 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -31,6 +31,7 @@ type Client struct { func NewClient() *Client { client := grab.NewClient() + client.UserAgent = "Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/117.0" client.HTTPClient = &http.Client{Timeout: time.Second * constants.HTTPTimeout} return &Client{client: client} } From 2883763802bcf871d62d9d71621b1b97b2d4c62d Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 13 Sep 2023 09:53:47 +0200 Subject: [PATCH 3/4] Extract copyGrubFonts to a function Signed-off-by: Itxaka --- pkg/constants/constants.go | 10 ++++++ pkg/utils/grub.go | 63 +++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index bb0fc21e..bf9a6246 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -163,3 +163,13 @@ func GetFallBackEfi(arch string) string { return "bootx64.efi" } } + +// GetGrubFonts returns the default font files for grub +func GetGrubFonts() []string { + return []string{"ascii.pf2", "euro.pf2", "unicode.pf2"} +} + +// GetGrubModules returns the default module files for grub +func GetGrubModules() []string { + return []string{"loopback.mod", "squash4.mod", "xzio.mod", "gzio.mod"} +} diff --git a/pkg/utils/grub.go b/pkg/utils/grub.go index 5d420360..08c45c2d 100644 --- a/pkg/utils/grub.go +++ b/pkg/utils/grub.go @@ -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,33 +160,7 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool, } } - var foundFonts bool - for _, m := range []string{"ascii.pf2", "euro.pf2", "unicode.pf2"} { - err = fsutils.WalkDirFs(g.config.Fs, rootDir, func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if d.Name() == m && strings.Contains(path, g.config.Arch) { - fileWriteName := filepath.Join(bootDir, fmt.Sprintf("%s/%s-efi/fonts/%s", systemgrub, g.config.Arch, m)) - g.config.Logger.Debugf("Copying %s to %s", path, fileWriteName) - fileContent, err := g.config.Fs.ReadFile(path) - if err != nil { - return fmt.Errorf("error reading %s: %s", path, err) - } - err = g.config.Fs.WriteFile(fileWriteName, fileContent, cnst.FilePerm) - if err != nil { - return fmt.Errorf("error writing %s: %s", fileWriteName, err) - } - foundFonts = true - return nil - } - return err - }) - if !foundFonts { - // Not a real error as to fail install but a big warning - g.config.Logger.Warnf("did not find grub font %s under %s", m, rootDir) - } - } + copyGrubFonts(g.config, rootDir, grubdir, systemgrub) err = fsutils.MkdirAll(g.config.Fs, filepath.Join(cnst.EfiDir, "EFI/boot/"), cnst.DirPerm) if err != nil { @@ -253,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) + } + } +} From 3bb0fc188e6182da644a7e4c69ada2dc1a5d865b Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 13 Sep 2023 09:54:36 +0200 Subject: [PATCH 4/4] Clean unused constants Signed-off-by: Itxaka --- pkg/constants/constants.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index bf9a6246..058c9c6a 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -41,7 +41,6 @@ const ( PersistentPartName = "persistent" OEMLabel = "COS_OEM" OEMPartName = "oem" - ISOLabel = "COS_LIVE" MountBinary = "/usr/bin/mount" EfiDevice = "/sys/firmware/efi" LinuxFs = "ext4" @@ -50,8 +49,6 @@ const ( EfiFs = "vfat" EfiSize = uint(64) OEMSize = uint(64) - StateSize = uint(15360) - RecoverySize = uint(8192) PersistentSize = uint(0) BiosSize = uint(1) ImgSize = uint(3072) @@ -66,7 +63,6 @@ const ( EfiDir = "/run/cos/efi" RecoverySquashFile = "recovery.squashfs" IsoRootFile = "rootfs.squashfs" - IsoEFIPath = "/boot/uefi.img" ActiveImgFile = "active.img" PassiveImgFile = "passive.img" RecoveryImgFile = "recovery.img" @@ -80,8 +76,6 @@ const ( AfterUpgradeChrootHook = "after-upgrade-chroot" AfterUpgradeHook = "after-upgrade" BeforeUpgradeHook = "before-upgrade" - LuetDefaultRepoURI = "quay.io/costoolkit/releases-green" - LuetDefaultRepoPrio = 90 TransitionImgFile = "transition.img" RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit @@ -89,7 +83,6 @@ const ( PassiveImgName = "passive" RecoveryImgName = "recovery" GPT = "gpt" - BuildImgName = "elemental" UsrLocalPath = "/usr/local" OEMPath = "/oem" @@ -98,10 +91,6 @@ const ( SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts" SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy" - // These paths are arbitrary but coupled to grub.cfg - IsoKernelPath = "/boot/kernel" - IsoInitrdPath = "/boot/initrd" - // Default directory and file fileModes DirPerm = os.ModeDir | os.ModePerm FilePerm = 0666 @@ -132,15 +121,6 @@ func GetDefaultSquashfsCompressionOptions() []string { return []string{"-comp", "gzip"} } -func GetBuildDiskDefaultPackages() map[string]string { - return map[string]string{ - "channel:system/grub2-efi-image": "efi", - "channel:system/grub2-config": "root", - "channel:system/grub2-artifacts": "root/grub2", - "channel:recovery/cos-img": "root/cOS", - } -} - func GetGrubFilePaths(arch string) []string { var archPath string switch arch {