Implement debian package
This commit is contained in:
parent
d04a9de932
commit
77be74797b
@ -2,8 +2,6 @@ package debian
|
||||
|
||||
import (
|
||||
"github.com/rapidloop/skv"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
@ -16,11 +14,11 @@ func NewCache(path string) (c *Cache, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c Cache) Put(p snapshot.Package) error {
|
||||
return c.store.Put(p.Version, p)
|
||||
func (c Cache) Put(p DebianKernel) error {
|
||||
return c.store.Put(p.Version.Package, p)
|
||||
}
|
||||
|
||||
func (c Cache) Get(version string) (p snapshot.Package, err error) {
|
||||
func (c Cache) Get(version string) (p DebianKernel, err error) {
|
||||
err = c.store.Get(version, &p)
|
||||
return
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/rapidloop/skv"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
@ -24,23 +22,24 @@ func TestCache(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
packages, err := snapshot.Packages("linux", "4.17.14-1", "amd64",
|
||||
`^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`)
|
||||
version := "4.17.14-1"
|
||||
|
||||
dk, err := GetDebianKernel(version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.Put(packages[0])
|
||||
err = c.Put(dk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p, err := c.Get(packages[0].Version)
|
||||
dk2, err := c.Get(version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if p.Deb.Hash != packages[0].Deb.Hash {
|
||||
if dk.Image.Deb.Hash != dk2.Image.Deb.Hash {
|
||||
t.Fatalf("mismatch")
|
||||
}
|
||||
|
||||
@ -52,16 +51,16 @@ func TestCache(t *testing.T) {
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
p, err = c.Get(packages[0].Version)
|
||||
dk3, err := c.Get(version)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if p.Deb.Hash != packages[0].Deb.Hash {
|
||||
if dk.Image.Deb.Hash != dk3.Image.Deb.Hash {
|
||||
t.Fatalf("mismatch")
|
||||
}
|
||||
|
||||
p, err = c.Get("key not exist")
|
||||
_, err = c.Get("key not exist")
|
||||
if err == nil || err != skv.ErrNotFound {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
63
distro/debian/kernel.go
Normal file
63
distro/debian/kernel.go
Normal file
@ -0,0 +1,63 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
||||
)
|
||||
|
||||
type DebianKernelVersion struct {
|
||||
// linux-headers-4.17.0-2-amd64_4.17.14-1_amd64.deb
|
||||
|
||||
// Package version, e.g. "4.17.14-1"
|
||||
// See tags in https://salsa.debian.org/kernel-team/linux
|
||||
Package string
|
||||
|
||||
// ABI version, e.g. "4.17.0-2"
|
||||
ABI string
|
||||
}
|
||||
|
||||
type DebianKernel struct {
|
||||
Version DebianKernelVersion
|
||||
Image snapshot.Package
|
||||
Headers snapshot.Package
|
||||
}
|
||||
|
||||
func GetDebianKernel(version string) (dk DebianKernel, err error) {
|
||||
dk.Version.Package = version
|
||||
|
||||
regex := `^linux-(image|headers)-[0-9\.\-]*-(amd64|amd64-unsigned)$`
|
||||
|
||||
packages, err := snapshot.Packages("linux", version, "amd64", regex)
|
||||
if len(packages) != 2 {
|
||||
err = errors.New("len(packages) != 2")
|
||||
return
|
||||
}
|
||||
|
||||
var imageFound, headersFound bool
|
||||
for _, p := range packages {
|
||||
if strings.Contains(p.Name, "image") {
|
||||
imageFound = true
|
||||
dk.Image = p
|
||||
} else if strings.Contains(p.Name, "headers") {
|
||||
headersFound = true
|
||||
dk.Headers = p
|
||||
}
|
||||
}
|
||||
|
||||
if !imageFound {
|
||||
err = errors.New("image not found")
|
||||
return
|
||||
}
|
||||
|
||||
if !headersFound {
|
||||
err = errors.New("headers not found")
|
||||
return
|
||||
}
|
||||
|
||||
s := strings.Replace(dk.Headers.Name, "linux-headers-", "", -1)
|
||||
dk.Version.ABI = strings.Replace(s, "-amd64", "", -1)
|
||||
|
||||
return
|
||||
}
|
16
distro/debian/kernel_test.go
Normal file
16
distro/debian/kernel_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetDebianKernel(t *testing.T) {
|
||||
dk, err := GetDebianKernel("4.17.14-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dk.Version.ABI != "4.17.0-2" {
|
||||
t.Fatalf("wrong abi")
|
||||
}
|
||||
}
|
2
go.mod
2
go.mod
@ -19,6 +19,7 @@ require (
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/otiai10/copy v1.11.0
|
||||
github.com/povsister/scp v0.0.0-20210427074412-33febfd9f13e
|
||||
github.com/rapidloop/skv v0.0.0-20180909015525-9def2caac4cc
|
||||
github.com/remeh/sizedwaitgroup v1.0.0
|
||||
github.com/rs/zerolog v1.29.1
|
||||
github.com/ulikunitz/xz v0.5.11
|
||||
@ -34,6 +35,7 @@ require (
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
|
||||
github.com/acomagu/bufpipe v1.0.4 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.1 // indirect
|
||||
github.com/boltdb/bolt v1.3.1 // indirect
|
||||
github.com/cloudflare/circl v1.1.0 // indirect
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/go-git/gcfg v1.5.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -20,6 +20,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cloudflare/circl v1.1.0 h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY=
|
||||
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||
@ -96,6 +98,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/povsister/scp v0.0.0-20210427074412-33febfd9f13e h1:VtsDti2SgX7M7jy0QAyGgb162PeHLrOaNxmcYOtaGsY=
|
||||
github.com/povsister/scp v0.0.0-20210427074412-33febfd9f13e/go.mod h1:i1Au86ZXK0ZalQNyBp2njCcyhSCR/QP/AMfILip+zNI=
|
||||
github.com/rapidloop/skv v0.0.0-20180909015525-9def2caac4cc h1:eXQoy66wUI9meNnIdKYJ+EV/Tq3LvXeUe95AB2dPk8g=
|
||||
github.com/rapidloop/skv v0.0.0-20180909015525-9def2caac4cc/go.mod h1:V5hvlcTzUJ3MOo0fEolWR25CZBBsb7q3wWVAmBYwr54=
|
||||
github.com/remeh/sizedwaitgroup v1.0.0 h1:VNGGFwNo/R5+MJBf6yrsr110p0m4/OX4S3DCy7Kyl5E=
|
||||
github.com/remeh/sizedwaitgroup v1.0.0/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo=
|
||||
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
|
Loading…
Reference in New Issue
Block a user