2023-05-18 11:08:23 +00:00
|
|
|
package oraclelinux
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-18 11:28:06 +00:00
|
|
|
"strings"
|
2023-05-18 11:08:23 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2023-05-18 11:28:06 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/container"
|
2023-05-18 21:37:07 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro"
|
2023-05-18 11:08:23 +00:00
|
|
|
)
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func init() {
|
|
|
|
releases := []string{"6", "7", "8", "9"}
|
2023-05-18 11:08:23 +00:00
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
for _, release := range releases {
|
2023-05-23 16:54:34 +00:00
|
|
|
distro.Register(OracleLinux{release: release})
|
2023-05-18 11:08:23 +00:00
|
|
|
}
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
2023-05-18 11:08:23 +00:00
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
type OracleLinux struct {
|
2023-05-23 16:54:34 +00:00
|
|
|
release string
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
2023-05-18 11:08:23 +00:00
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func (ol OracleLinux) Equal(d distro.Distro) bool {
|
|
|
|
return ol.release == d.Release && distro.OracleLinux == d.ID
|
2023-05-18 11:08:23 +00:00
|
|
|
}
|
2023-05-18 11:28:06 +00:00
|
|
|
|
2023-05-23 16:24:01 +00:00
|
|
|
func (ol OracleLinux) Distro() distro.Distro {
|
|
|
|
return distro.Distro{ID: distro.OracleLinux, Release: ol.release}
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func (ol OracleLinux) Packages() (pkgs []string, err error) {
|
2023-05-23 16:54:34 +00:00
|
|
|
c, err := container.New(ol.Distro())
|
2023-05-18 11:28:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
err = c.Build("oraclelinux:"+ol.release, ol.envs(), ol.runs())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-27 16:56:15 +00:00
|
|
|
if ol.release == "8" {
|
|
|
|
// Image for ol9 is required for some kernels
|
|
|
|
// See notes in OracleLinux.Kernels()
|
|
|
|
_, err = OracleLinux{release: "9"}.Packages()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 06:01:40 +00:00
|
|
|
cmd := "yum search kernel --showduplicates 2>/dev/null " +
|
2023-05-18 11:28:06 +00:00
|
|
|
"| grep '^kernel-[0-9]\\|^kernel-uek-[0-9]' " +
|
|
|
|
"| grep -v src " +
|
|
|
|
"| cut -d ' ' -f 1"
|
|
|
|
|
2023-05-23 20:46:09 +00:00
|
|
|
output, err := c.Run(config.Dir("tmp"), []string{cmd})
|
2023-05-18 11:28:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
for _, pkg := range strings.Fields(output) {
|
|
|
|
pkgs = append(pkgs, pkg)
|
2023-05-18 11:28:06 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:00:20 +00:00
|
|
|
func (ol OracleLinux) Kernels() (kernels []distro.KernelInfo, err error) {
|
|
|
|
c, err := container.New(ol.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-27 16:56:15 +00:00
|
|
|
kernels, err = c.Kernels()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, k := range kernels {
|
|
|
|
// The latest uek kernels require gcc-11, which is
|
|
|
|
// only present in el8 with scl load, so not so
|
|
|
|
// convinient. It is possible to just build from
|
|
|
|
// the next release container.
|
|
|
|
if strings.Contains(k.KernelVersion, "5.15.0") {
|
|
|
|
cnt := strings.Replace(k.ContainerName, "8", "9", -1)
|
|
|
|
kernels[i].ContainerName = cnt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2023-05-23 22:00:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
func (ol OracleLinux) envs() (envs []string) {
|
2023-05-18 21:37:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
func (ol OracleLinux) runs() (commands []string) {
|
2023-05-18 21:37:07 +00:00
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
2023-05-18 11:28:06 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
if ol.release < "6" {
|
2023-05-18 21:37:07 +00:00
|
|
|
log.Fatal().Msgf("no support for pre-EL6")
|
2023-05-18 11:28:06 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
cmdf("sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/*")
|
|
|
|
cmdf("sed -i 's;installonly_limit=;installonly_limit=100500;' /etc/yum.conf /etc/dnf/dnf.conf || true")
|
|
|
|
cmdf("yum -y update")
|
|
|
|
cmdf("yum -y groupinstall 'Development Tools'")
|
|
|
|
|
|
|
|
packages := "linux-firmware grubby"
|
2023-05-23 13:20:48 +00:00
|
|
|
if ol.release <= "7" {
|
2023-05-18 21:37:07 +00:00
|
|
|
packages += " libdtrace-ctf"
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("yum -y install %s", packages)
|
|
|
|
|
2023-05-18 11:28:06 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 11:42:25 +00:00
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
func (ol OracleLinux) Install(pkgname string, headers bool) (err error) {
|
2023-05-18 11:42:25 +00:00
|
|
|
var headerspkg string
|
|
|
|
if headers {
|
|
|
|
if strings.Contains(pkgname, "uek") {
|
|
|
|
headerspkg = strings.Replace(pkgname,
|
|
|
|
"kernel-uek", "kernel-uek-devel", -1)
|
|
|
|
} else {
|
|
|
|
headerspkg = strings.Replace(pkgname,
|
|
|
|
"kernel", "kernel-devel", -1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
var commands []string
|
2023-05-18 11:42:25 +00:00
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("yum -y install %s %s", pkgname, headerspkg)
|
|
|
|
|
|
|
|
var version string
|
|
|
|
if strings.Contains(pkgname, "uek") {
|
|
|
|
version = strings.Replace(pkgname, "kernel-uek-", "", -1)
|
|
|
|
} else {
|
|
|
|
version = strings.Replace(pkgname, "kernel-", "", -1)
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
if ol.release <= "7" {
|
2023-05-18 11:42:25 +00:00
|
|
|
cmdf("dracut -v --add-drivers 'e1000 ext4' -f "+
|
|
|
|
"/boot/initramfs-%s.img %s", version, version)
|
|
|
|
} else {
|
|
|
|
cmdf("dracut -v --add-drivers 'ata_piix libata' "+
|
|
|
|
"--force-drivers 'e1000 ext4 sd_mod' -f "+
|
|
|
|
"/boot/initramfs-%s.img %s", version, version)
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
cmdf("cp -r /boot /target/")
|
|
|
|
cmdf("cp -r /lib/modules /target/lib/")
|
|
|
|
cmdf("cp -r /usr/src /target/usr/")
|
|
|
|
|
|
|
|
c, err := container.New(ol.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range c.Volumes {
|
|
|
|
c.Volumes[i].Dest = "/target" + c.Volumes[i].Dest
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.Run("", commands)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-05-18 11:42:25 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|