Files
warewulf/internal/pkg/container/shim.go
Christian Goll a36cb23319 added shim/grub find to provision process
Signed-off-by: Christian Goll <cgoll@suse.com>
2024-01-17 18:02:04 -07:00

58 lines
1.2 KiB
Go

package container
import (
"path"
"path/filepath"
"sort"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
func shimDirs() []string {
return []string{
`/usr/share/efi/x86_64/`,
`/usr/lib64/`,
``}
}
func shimNames() []string {
return []string{
`shim.efi`,
`shim-sles.efi`,
}
}
func ShimFind(container string) string {
wwlog.Debug("Finding shim")
container_path := RootFsDir(container)
if container_path == "" {
return ""
}
for _, shimdir := range shimDirs() {
wwlog.Debug("Checking shim directory: %s", shimdir)
for _, shimname := range shimNames() {
wwlog.Debug("Checking for shim name: %s", shimname)
shimPaths, err := filepath.Glob(path.Join(container_path, shimdir, shimname))
if err != nil {
return ""
}
if len(shimPaths) == 0 {
continue
}
sort.Slice(shimPaths, func(i, j int) bool {
return shimPaths[i] > shimPaths[j]
})
for _, shimPath := range shimPaths {
wwlog.Debug("Checking for shim path: %s", shimPath)
// Only succeeds if shimPath exists and, if a
// symlink, links to a path that also exists
shimPath, err = filepath.EvalSymlinks(shimPath)
if err == nil {
wwlog.Debug("found shim: %s", shimPath)
return shimPath
}
}
}
}
return ""
}