Skip to content

Commit

Permalink
new(pkg): support RC releases for vanilla target.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP authored and poiana committed May 12, 2023
1 parent 584e423 commit 829757e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/driverbuilder/builder/templates/vanilla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ bash /driverkit/fill-driver-config.sh {{ .DriverBuildDir }}
# Fetch the kernel
cd /tmp
mkdir /tmp/kernel-download
{{ if .IsTarGz}}
curl --silent -SL {{ .KernelDownloadURL }} | tar -zxf - -C /tmp/kernel-download
{{ else }}
curl --silent -SL {{ .KernelDownloadURL }} | tar -Jxf - -C /tmp/kernel-download
{{ end }}
rm -Rf /tmp/kernel
mkdir -p /tmp/kernel
mv /tmp/kernel-download/*/* /tmp/kernel
Expand Down
13 changes: 13 additions & 0 deletions pkg/driverbuilder/builder/vanilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
"github.com/falcosecurity/driverkit/pkg/kernelrelease"
"strings"
)

//go:embed templates/vanilla.sh
Expand All @@ -24,6 +25,7 @@ type vanillaTemplateData struct {
commonTemplateData
KernelDownloadURL string
KernelLocalVersion string
IsTarGz bool
}

func (v *vanilla) Name() string {
Expand All @@ -43,9 +45,20 @@ func (v *vanilla) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []
commonTemplateData: c.toTemplateData(v, kr),
KernelDownloadURL: urls[0],
KernelLocalVersion: kr.FullExtraversion,
IsTarGz: strings.HasSuffix(urls[0], ".tar.gz"), // Since RC have a tar.gz format, we need to inform the build script
}
}

func fetchVanillaKernelURLFromKernelVersion(kv kernelrelease.KernelRelease) string {
// Note: even non RC are available as tar.gz; but tar.xz are much smaller
// and thus much quicker to download. Let's keep tar.xz for non RC!
// Numbers: 110M (tar.gz) vs 75M (tar.xz)
if isRC(kv) {
return fmt.Sprintf("https://git.kernel.org/torvalds/t/linux-%s%s.tar.gz", kv.Fullversion, kv.FullExtraversion)
}
return fmt.Sprintf("https://cdn.kernel.org/pub/linux/kernel/v%d.x/linux-%s.tar.xz", kv.Major, kv.Fullversion)
}

func isRC(kv kernelrelease.KernelRelease) bool {
return strings.Contains(kv.Extraversion, "rc")
}
12 changes: 12 additions & 0 deletions pkg/kernelrelease/kernelrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ func TestFromString(t *testing.T) {
FullExtraversion: "-arch1-1",
},
},
"version RC": {
kernelVersionStr: "6.4-rc1",
want: KernelRelease{
Fullversion: "6.4",
Version: semver.Version{
Major: 6,
Minor: 4,
},
Extraversion: "rc1",
FullExtraversion: "-rc1",
},
},
"just kernel version": {
kernelVersionStr: "5.5.2",
want: KernelRelease{
Expand Down

0 comments on commit 829757e

Please sign in to comment.