Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[close #256]: Better kernel version detection #257

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

mirkobrombin
Copy link
Member

No description provided.

@mirkobrombin mirkobrombin requested a review from matbme April 16, 2024 18:48
@axtloss
Copy link
Member

axtloss commented Apr 16, 2024

How does this handle kernel files that have more than the version in their file? something like initramfs-6.4.2-sched-ext vs initramfs-6.4.1

@mirkobrombin
Copy link
Member Author

How does this handle kernel files that have more than the version in their file? something like initramfs-6.4.2-sched-ext vs initramfs-6.4.1

For this purpose, I created a script to test the functionality:

package main

import (
	"fmt"

	"github.com/hashicorp/go-version"
)

func getLatestKernelVersion(files []string) string {
	var maxVer *version.Version
	for _, file := range files {
		verStr := file[8:]
		ver, err := version.NewVersion(verStr)
		if err != nil {
			fmt.Println("Error parsing version:", verStr, "Error:", err)
			continue
		}
		if maxVer == nil || ver.GreaterThan(maxVer) {
			maxVer = ver
		}
	}
	if maxVer != nil {
		return maxVer.String()
	}
	return "no valid kernel version found"
}

func main() {
	files := []string{
		"vmlinuz-6.4.1",
		"vmlinuz-6.4.2-sched-ext",
		"vmlinuz-6.3.1-debug",
	}

	fmt.Println("Latest Kernel Version:", getLatestKernelVersion(files))
}

here is the result: Latest Kernel Version: 6.4.2-sched-ext

Copy link

fab-sonarqube bot commented Apr 17, 2024

@mirkobrombin mirkobrombin merged commit 28f40b5 into main Apr 17, 2024
5 of 6 checks passed
@mirkobrombin mirkobrombin deleted the feat/better-kernel-version-detection branch April 17, 2024 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants