feat: match the gcc version to distinguish between Debian releases
This commit is contained in:
parent
ae00b57471
commit
48ba7b7c7b
@ -1,12 +1,10 @@
|
|||||||
package debian
|
package debian
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@ -70,7 +68,7 @@ func (d Debian) Packages() (packages []string, err error) {
|
|||||||
p := dk.Image.Deb.Name[:len(dk.Image.Deb.Name)-4] // w/o .deb
|
p := dk.Image.Deb.Name[:len(dk.Image.Deb.Name)-4] // w/o .deb
|
||||||
|
|
||||||
var kr Release
|
var kr Release
|
||||||
kr, err = kernelRelease(p)
|
kr, err = kernelRelease(dk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("")
|
log.Warn().Err(err).Msg("")
|
||||||
continue
|
continue
|
||||||
@ -139,44 +137,51 @@ func ReleaseFromString(s string) (r Release) {
|
|||||||
r = Buster
|
r = Buster
|
||||||
case "11", "bullseye":
|
case "11", "bullseye":
|
||||||
r = Bullseye
|
r = Bullseye
|
||||||
|
case "12", "bookworm":
|
||||||
|
r = Bookworm
|
||||||
default:
|
default:
|
||||||
r = None
|
r = None
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func kernelRelease(deb string) (r Release, err error) {
|
func kernelRelease(dk DebianKernel) (r Release, err error) {
|
||||||
// linux-image-4.17.0-2-amd64 -> 4.17
|
var gcc string
|
||||||
re := regexp.MustCompile(`([0-9]*\.[0-9]*)`)
|
for _, dep := range dk.Dependencies {
|
||||||
sver := re.FindString(deb)
|
if !strings.HasPrefix(dep.Name, "linux-compiler-gcc-") {
|
||||||
if sver == "" {
|
continue
|
||||||
err = errors.New("empty result")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
version := kver(sver)
|
|
||||||
|
|
||||||
if version.LessThan(kver("3.0-rc0")) {
|
|
||||||
err = errors.New("not supported")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.LessThan(kver("3.8-rc0")) {
|
gcc = strings.Replace(dep.Name, "linux-compiler-gcc-", "", -1)
|
||||||
// Wheezy 3.2
|
gcc = strings.Replace(gcc, "-x86", "", -1)
|
||||||
// >=3.8 breaks initramfs-tools << 0.110~
|
|
||||||
// Wheezy initramfs-tools version is 0.109.1
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
switch gcc {
|
||||||
|
case "", "4.4", "4.6", "4.7":
|
||||||
|
// Note that we are catching an empty string, which
|
||||||
|
// means there is no linux-compiler-gcc- package
|
||||||
|
// present, which is the case with old Debian
|
||||||
|
// kernels. As the MR API only returns kernels from
|
||||||
|
// Wheezy onwards, we can safely assume that this is
|
||||||
|
// the correct release.
|
||||||
r = Wheezy
|
r = Wheezy
|
||||||
} else if version.LessThan(kver("4.9-rc0")) {
|
case "4.8", "4.9":
|
||||||
// Jessie 3.16
|
|
||||||
r = Jessie
|
r = Jessie
|
||||||
} else if version.LessThan(kver("4.19-rc0")) {
|
case "5":
|
||||||
// Stretch 4.9
|
// No kernels compiled with gcc-5 have reached stable
|
||||||
|
r = None
|
||||||
|
case "6":
|
||||||
r = Stretch
|
r = Stretch
|
||||||
} else if version.LessThan(kver("5.10-rc0")) {
|
case "7", "8":
|
||||||
// Buster 4.19
|
|
||||||
r = Buster
|
r = Buster
|
||||||
} else {
|
case "9", "10":
|
||||||
// Bullseye 5.10
|
|
||||||
r = Bullseye
|
r = Bullseye
|
||||||
|
case "11", "12":
|
||||||
|
r = Bookworm
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unknown release with gcc-%s", gcc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -8,41 +8,6 @@ import (
|
|||||||
"code.dumpstack.io/tools/out-of-tree/distro"
|
"code.dumpstack.io/tools/out-of-tree/distro"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKernelRelease(t *testing.T) {
|
|
||||||
type testcase struct {
|
|
||||||
Deb string
|
|
||||||
Release Release
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range []testcase{
|
|
||||||
testcase{"linux-image-3.2.0-0.bpo.4-amd64_3.2.41-2+deb7u2~bpo60+1_amd64", Wheezy},
|
|
||||||
testcase{"linux-image-3.15-trunk-amd64_3.15.5-1~exp1_amd64", Jessie},
|
|
||||||
testcase{"linux-image-3.16-rc5-amd64_3.16~rc5-1~exp1_amd64", Jessie},
|
|
||||||
testcase{"linux-image-4.15.0-3-amd64_4.15.17-1_amd64", Stretch},
|
|
||||||
testcase{"linux-image-4.16.0-rc5-amd64_4.16~rc5-1~exp1_amd64", Stretch},
|
|
||||||
testcase{"linux-image-4.17.0-2-amd64", Stretch},
|
|
||||||
testcase{"linux-image-4.18.0-0.bpo.3-amd64_4.18.20-2~bpo9+1_amd64", Stretch},
|
|
||||||
testcase{"linux-image-4.19.0-rc2-amd64-unsigned_4.19~rc2-1~exp1_amd64", Buster},
|
|
||||||
testcase{"linux-image-4.20.0-trunk-amd64-unsigned_4.20-1~exp1_amd64", Buster},
|
|
||||||
testcase{"linux-image-4.8.0-2-amd64-unsigned_4.8.15-2_amd64", Jessie},
|
|
||||||
testcase{"linux-image-4.9.0-rc3-amd64-unsigned_4.9~rc3-1~exp1_amd64", Stretch},
|
|
||||||
testcase{"linux-image-5.0.0-trunk-amd64-unsigned_5.0.1-1~exp1_amd64", Buster},
|
|
||||||
testcase{"linux-image-5.9.0-rc4-amd64-unsigned_5.9~rc4-1~exp1_amd64", Buster},
|
|
||||||
testcase{"linux-image-5.10.0-rc4-amd64-unsigned_5.10~rc4-1~exp1_amd64", Bullseye},
|
|
||||||
testcase{"linux-image-5.16.0-rc5-amd64-unsigned_5.16~rc5-1~exp1_amd64", Bullseye},
|
|
||||||
testcase{"linux-image-6.1.0-0.deb11.7-amd64-unsigned", Bullseye},
|
|
||||||
testcase{"linux-image-6.1.0-8-amd64-unsigned", Bullseye},
|
|
||||||
} {
|
|
||||||
r, err := kernelRelease(tc.Deb)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if r != tc.Release {
|
|
||||||
t.Fatalf("%v -> %v != %v", tc.Deb, r, tc.Release)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDebian(t *testing.T) {
|
func TestDebian(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
@ -52,3 +17,33 @@ func TestDebian(t *testing.T) {
|
|||||||
|
|
||||||
assert.NotEmpty(u.Packages())
|
assert.NotEmpty(u.Packages())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKernelRelease(t *testing.T) {
|
||||||
|
kernels, err := GetKernels()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, k := range kernels {
|
||||||
|
r, err := kernelRelease(k)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(k.Version, r, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, k := range kernels {
|
||||||
|
r, err := kernelRelease(k)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if r == Wheezy {
|
||||||
|
t.Log("Wheezy", k.Version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if r == Jessie {
|
||||||
|
t.Log("Jessie", k.Version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user