feat!: introduce new distribution structure
BREAKING CHANGE: distro definition in the configuration files has switched from [[supported_kernels]] distro_type = "Ubuntu" distro_release = "16.04" ... to [[supported_kernels]] distro = { id = "Ubuntu", release = "16.04" } ...
This commit is contained in:
@ -20,7 +20,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
var repos []string
|
||||
|
||||
// TODO refactor
|
||||
switch km.DistroRelease {
|
||||
switch km.Distro.Release {
|
||||
case "6":
|
||||
repofmt := "[6.%d-%s]\\nbaseurl=https://vault.centos.org/6.%d/%s/$basearch/\\ngpgcheck=0"
|
||||
for i := 0; i <= 10; i++ {
|
||||
@ -54,7 +54,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
repos = append(repos, fmt.Sprintf(repofmt, ver, "appstream", ver, "AppStream"))
|
||||
}
|
||||
default:
|
||||
log.Fatal().Msgf("no support for %s %s", km.DistroType, km.DistroRelease)
|
||||
log.Fatal().Msgf("no support for %s %s", km.Distro.ID, km.Distro.Release)
|
||||
return
|
||||
}
|
||||
|
||||
@ -71,14 +71,14 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
|
||||
cmdf("yum -y groupinstall 'Development Tools'")
|
||||
|
||||
if km.DistroRelease < "8" {
|
||||
if km.Distro.Release < "8" {
|
||||
cmdf("yum -y install deltarpm")
|
||||
} else {
|
||||
cmdf("yum -y install grub2-tools-minimal elfutils-libelf-devel")
|
||||
}
|
||||
|
||||
var flags string
|
||||
if km.DistroRelease >= "8" {
|
||||
if km.Distro.Release >= "8" {
|
||||
flags = "--noautoremove"
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ func Match(km config.KernelMask) (pkgs []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
release := releaseFromString(km.DistroRelease)
|
||||
release := releaseFromString(km.Distro.Release)
|
||||
|
||||
r := regexp.MustCompile(km.ReleaseMask)
|
||||
|
||||
@ -151,7 +151,7 @@ func Envs(km config.KernelMask) (envs []string) {
|
||||
func ContainerImage(km config.KernelMask) (image string) {
|
||||
image += "debian:"
|
||||
|
||||
switch releaseFromString(km.DistroRelease) {
|
||||
switch releaseFromString(km.Distro.Release) {
|
||||
case Wheezy:
|
||||
image += "wheezy-20190228"
|
||||
case Jessie:
|
||||
@ -159,7 +159,7 @@ func ContainerImage(km config.KernelMask) (image string) {
|
||||
case Stretch:
|
||||
image += "stretch-20220622"
|
||||
default:
|
||||
image += km.DistroRelease
|
||||
image += km.Distro.Release
|
||||
}
|
||||
|
||||
return
|
||||
@ -197,7 +197,7 @@ func repositories(release Release) (repos []string) {
|
||||
}
|
||||
|
||||
func Runs(km config.KernelMask) (commands []string) {
|
||||
release := releaseFromString(km.DistroRelease)
|
||||
release := releaseFromString(km.Distro.Release)
|
||||
|
||||
cmdf := func(f string, s ...interface{}) {
|
||||
commands = append(commands, fmt.Sprintf(f, s...))
|
||||
@ -288,8 +288,7 @@ func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error)
|
||||
release := strings.Replace(pkgname, "linux-image-", "", -1)
|
||||
|
||||
ki := config.KernelInfo{
|
||||
DistroType: d.DistroType,
|
||||
DistroRelease: d.DistroRelease,
|
||||
Distro: d.Distro,
|
||||
KernelVersion: path.Base(modules),
|
||||
KernelRelease: release,
|
||||
ContainerName: d.Name,
|
||||
@ -332,7 +331,7 @@ func Install(km config.KernelMask, pkgname string, headers bool) (cmds []string,
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
found, newurl := cache.PackageURL(
|
||||
km.DistroType,
|
||||
km.Distro.ID,
|
||||
pkg.Deb.URL,
|
||||
)
|
||||
if found {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
"code.dumpstack.io/tools/out-of-tree/distro"
|
||||
"code.dumpstack.io/tools/out-of-tree/fs"
|
||||
)
|
||||
|
||||
@ -24,8 +25,8 @@ func TestMatch(t *testing.T) {
|
||||
config.Directory = tmp
|
||||
|
||||
km := config.KernelMask{
|
||||
ReleaseMask: "3.2.0-4",
|
||||
DistroRelease: "7",
|
||||
ReleaseMask: "3.2.0-4",
|
||||
Distro: distro.Distro{Release: "7"},
|
||||
}
|
||||
|
||||
pkgs, err := Match(km)
|
||||
|
68
distro/distro.go
Normal file
68
distro/distro.go
Normal file
@ -0,0 +1,68 @@
|
||||
package distro
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ID of the distro
|
||||
type ID int
|
||||
|
||||
const (
|
||||
// Ubuntu https://ubuntu.com/
|
||||
Ubuntu ID = iota
|
||||
// CentOS https://www.centos.org/
|
||||
CentOS
|
||||
// Debian https://www.debian.org/
|
||||
Debian
|
||||
// OracleLinux https://www.oracle.com/linux/
|
||||
OracleLinux
|
||||
)
|
||||
|
||||
var IDs = []ID{
|
||||
Ubuntu, CentOS, Debian, OracleLinux,
|
||||
}
|
||||
|
||||
var nameStrings = [...]string{
|
||||
"Ubuntu",
|
||||
"CentOS",
|
||||
"Debian",
|
||||
"OracleLinux",
|
||||
}
|
||||
|
||||
func NewID(name string) (id ID, err error) {
|
||||
err = id.UnmarshalTOML([]byte(name))
|
||||
return
|
||||
}
|
||||
|
||||
func (id ID) String() string {
|
||||
return nameStrings[id]
|
||||
}
|
||||
|
||||
// UnmarshalTOML is for support github.com/naoina/toml
|
||||
func (id *ID) UnmarshalTOML(data []byte) (err error) {
|
||||
name := strings.Trim(string(data), `"`)
|
||||
if strings.EqualFold(name, "Ubuntu") {
|
||||
*id = Ubuntu
|
||||
} else if strings.EqualFold(name, "CentOS") {
|
||||
*id = CentOS
|
||||
} else if strings.EqualFold(name, "Debian") {
|
||||
*id = Debian
|
||||
} else if strings.EqualFold(name, "OracleLinux") {
|
||||
*id = OracleLinux
|
||||
} else {
|
||||
err = fmt.Errorf("distro %s is unsupported", name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MarshalTOML is for support github.com/naoina/toml
|
||||
func (id ID) MarshalTOML() (data []byte, err error) {
|
||||
data = []byte(`"` + id.String() + `"`)
|
||||
return
|
||||
}
|
||||
|
||||
type Distro struct {
|
||||
ID ID
|
||||
Release string
|
||||
}
|
@ -21,7 +21,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
commands = append(commands, fmt.Sprintf(f, s...))
|
||||
}
|
||||
|
||||
if km.DistroRelease < "6" {
|
||||
if km.Distro.Release < "6" {
|
||||
log.Fatal().Msgf("no support for pre-EL6")
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
cmdf("yum -y groupinstall 'Development Tools'")
|
||||
|
||||
packages := "linux-firmware grubby"
|
||||
if km.DistroRelease <= "7" {
|
||||
if km.Distro.Release <= "7" {
|
||||
packages += " libdtrace-ctf"
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ func Install(km config.KernelMask, pkgname string, headers bool) (commands []str
|
||||
version = strings.Replace(pkgname, "kernel-", "", -1)
|
||||
}
|
||||
|
||||
if km.DistroRelease <= "7" {
|
||||
if km.Distro.Release <= "7" {
|
||||
cmdf("dracut -v --add-drivers 'e1000 ext4' -f "+
|
||||
"/boot/initramfs-%s.img %s", version, version)
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
commands = append(commands, fmt.Sprintf(f, s...))
|
||||
}
|
||||
|
||||
if km.DistroRelease < "14.04" {
|
||||
if km.Distro.Release < "14.04" {
|
||||
cmdf("sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/' " +
|
||||
"/etc/apt/sources.list")
|
||||
}
|
||||
@ -29,7 +29,7 @@ func Runs(km config.KernelMask) (commands []string) {
|
||||
cmdf("apt-get install -y build-essential libelf-dev")
|
||||
cmdf("apt-get install -y wget git")
|
||||
|
||||
if km.DistroRelease < "14.04" {
|
||||
if km.Distro.Release < "14.04" {
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user