feat: support multiple headers packages
This commit is contained in:
parent
6b8d97be39
commit
6bb0da5082
4
.github/workflows/debian-cache.yml
vendored
4
.github/workflows/debian-cache.yml
vendored
@ -7,7 +7,9 @@ on:
|
|||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.github/workflows/debian-cache.yml'
|
- '.github/workflows/debian-cache.yml'
|
||||||
- 'distro/debian/**'
|
- 'distro/debian/snapshot/**'
|
||||||
|
- 'distro/debian/cache.go'
|
||||||
|
- 'distro/debian/kernel.go'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
debian-cache:
|
debian-cache:
|
||||||
|
@ -2,7 +2,6 @@ package debian
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ type DebianKernelVersion struct {
|
|||||||
type DebianKernel struct {
|
type DebianKernel struct {
|
||||||
Version DebianKernelVersion
|
Version DebianKernelVersion
|
||||||
Image snapshot.Package
|
Image snapshot.Package
|
||||||
Headers snapshot.Package
|
Headers []snapshot.Package
|
||||||
Dependencies []snapshot.Package
|
Dependencies []snapshot.Package
|
||||||
|
|
||||||
// FIXME There is a better way
|
// FIXME There is a better way
|
||||||
@ -44,7 +43,7 @@ var (
|
|||||||
func GetDebianKernel(version string) (dk DebianKernel, err error) {
|
func GetDebianKernel(version string) (dk DebianKernel, err error) {
|
||||||
dk.Version.Package = version
|
dk.Version.Package = version
|
||||||
|
|
||||||
regex := `^linux-(image|headers)-[a-z+~0-9\.\-]*-(amd64|amd64-unsigned)$`
|
regex := `^linux-(image|headers)-[a-z+~0-9\.\-]*-(common|amd64|amd64-unsigned)$`
|
||||||
|
|
||||||
filter := []string{
|
filter := []string{
|
||||||
"rt-amd64",
|
"rt-amd64",
|
||||||
@ -61,20 +60,6 @@ func GetDebianKernel(version string) (dk DebianKernel, err error) {
|
|||||||
if len(packages) == 0 {
|
if len(packages) == 0 {
|
||||||
err = ErrNoBinaryPackages
|
err = ErrNoBinaryPackages
|
||||||
return
|
return
|
||||||
} else if len(packages) == 1 {
|
|
||||||
if strings.Contains(packages[0].Name, "image") {
|
|
||||||
err = ErrNoHeadersPackage
|
|
||||||
return
|
|
||||||
} else if strings.Contains(packages[0].Name, "headers") {
|
|
||||||
err = ErrNoImagePackage
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("wtf? %v", packages[0].Name)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else if len(packages) > 2 {
|
|
||||||
err = errors.New("more than two binary packages found")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageFound, headersFound bool
|
var imageFound, headersFound bool
|
||||||
@ -84,21 +69,23 @@ func GetDebianKernel(version string) (dk DebianKernel, err error) {
|
|||||||
dk.Image = p
|
dk.Image = p
|
||||||
} else if strings.Contains(p.Name, "headers") {
|
} else if strings.Contains(p.Name, "headers") {
|
||||||
headersFound = true
|
headersFound = true
|
||||||
dk.Headers = p
|
dk.Headers = append(dk.Headers, p)
|
||||||
|
} else {
|
||||||
|
dk.Dependencies = append(dk.Dependencies, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !imageFound {
|
if !imageFound {
|
||||||
err = errors.New("image not found")
|
err = ErrNoImagePackage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !headersFound {
|
if !headersFound {
|
||||||
err = errors.New("headers not found")
|
err = ErrNoHeadersPackage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strings.Replace(dk.Headers.Name, "linux-headers-", "", -1)
|
s := strings.Replace(dk.Image.Name, "linux-image-", "", -1)
|
||||||
dk.Version.ABI = strings.Replace(s, "-amd64", "", -1)
|
dk.Version.ABI = strings.Replace(s, "-amd64", "", -1)
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -126,10 +113,15 @@ func GetCachedKernel(deb string) (dk DebianKernel, err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
switch deb {
|
if deb == tmpdk.Image.Deb.Name {
|
||||||
case tmpdk.Image.Deb.Name, tmpdk.Headers.Deb.Name:
|
|
||||||
dk = tmpdk
|
dk = tmpdk
|
||||||
return
|
}
|
||||||
|
|
||||||
|
for _, h := range tmpdk.Headers {
|
||||||
|
if deb == h.Deb.Name {
|
||||||
|
dk = tmpdk
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func TestSourcePackageVersions(t *testing.T) {
|
|||||||
|
|
||||||
func TestPackages(t *testing.T) {
|
func TestPackages(t *testing.T) {
|
||||||
packages, err := Packages("linux", "3.16.5-1", "amd64",
|
packages, err := Packages("linux", "3.16.5-1", "amd64",
|
||||||
`^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`,
|
`^linux-(image|headers)-[0-9\.\-]*-(common|amd64|amd64-unsigned)$`,
|
||||||
[]string{})
|
[]string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -30,5 +30,7 @@ func TestPackages(t *testing.T) {
|
|||||||
t.Fatal(errors.New("empty response"))
|
t.Fatal(errors.New("empty response"))
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log(packages)
|
for _, pkg := range packages {
|
||||||
|
t.Logf("%#v", pkg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,6 +393,8 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
"/boot/initramfs-%s.img %s", version, version)
|
"/boot/initramfs-%s.img %s", version, version)
|
||||||
}
|
}
|
||||||
case config.Debian:
|
case config.Debian:
|
||||||
|
// TODO move to distro/debian/
|
||||||
|
|
||||||
var dk debian.DebianKernel
|
var dk debian.DebianKernel
|
||||||
dk, err = debian.GetCachedKernel(pkgname + ".deb")
|
dk, err = debian.GetCachedKernel(pkgname + ".deb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -411,7 +413,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
|
|
||||||
pkgs := []snapshot.Package{dk.Image}
|
pkgs := []snapshot.Package{dk.Image}
|
||||||
if headers {
|
if headers {
|
||||||
pkgs = append(pkgs, dk.Headers)
|
pkgs = append(pkgs, dk.Headers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
|
Loading…
Reference in New Issue
Block a user