resolve symlink for kernel version

This commit is contained in:
Christian
2022-12-14 16:44:19 +01:00
committed by Christian Goll
parent 29a6ed4115
commit 750358646d

View File

@@ -1,9 +1,11 @@
package container
import (
"os"
"path"
"path/filepath"
"sort"
"strings"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
@@ -15,11 +17,11 @@ var (
`vmlinuz`,
`vmlinux-*`,
`vmlinuz-*`,
`vmlinuz.gz` }
`vmlinuz.gz`}
kernelDirs = []string{
`/lib/modules/*/`,
`/boot/` }
`/boot/`}
)
func KernelFind(container string) string {
@@ -49,6 +51,16 @@ func KernelFind(container string) string {
for _, kernelPath := range kernelPaths {
wwlog.Debug("Checking for kernel path: %s", kernelPath)
if util.IsFile(kernelPath) {
// IsFile does not check if file is a softlink
stat, _ := os.Lstat(kernelPath)
if stat.Mode()&os.ModeSymlink == os.ModeSymlink {
wwlog.Verbose("%s is a softlink", kernelPath)
kernelPath, err = filepath.EvalSymlinks(kernelPath)
if err != nil {
wwlog.Warn("could evaluate symlink %s: %s", kernelPath, err)
}
wwlog.Debug("softlink is %s", kernelPath)
}
return kernelPath
}
}
@@ -65,5 +77,10 @@ func KernelVersion(container string) string {
return ""
}
return path.Base(path.Dir(kernel))
ret := path.Base(path.Dir(kernel))
if ret == "boot" {
ret = path.Base(kernel)
}
return strings.TrimPrefix(ret, "vmlinuz-")
}