2023-03-18 21:30:07 +00:00
|
|
|
// Copyright 2023 Mikhail Klementev. All rights reserved.
|
2019-08-31 07:50:29 +00:00
|
|
|
// Use of this source code is governed by a AGPLv3 license
|
|
|
|
// (or later) that can be found in the LICENSE file.
|
|
|
|
|
2023-03-18 21:30:07 +00:00
|
|
|
//go:build linux
|
2019-08-31 07:50:29 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
2023-03-18 21:30:07 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2019-08-31 07:50:29 +00:00
|
|
|
"github.com/zcalusic/sysinfo"
|
2023-03-18 21:30:07 +00:00
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2019-08-31 07:50:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func genHostKernels(download bool) (kcfg config.KernelConfig, err error) {
|
|
|
|
si := sysinfo.SysInfo{}
|
|
|
|
si.GetSysInfo()
|
|
|
|
|
|
|
|
distroType, err := config.NewDistroType(si.OS.Vendor)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command("ls", "/lib/modules")
|
2023-03-19 13:14:14 +00:00
|
|
|
log.Debug().Msgf("%v", cmd)
|
|
|
|
|
2019-08-31 07:50:29 +00:00
|
|
|
rawOutput, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
2023-03-18 21:30:07 +00:00
|
|
|
log.Print(string(rawOutput), err)
|
2019-08-31 07:50:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
kernelsBase := "/boot/"
|
|
|
|
files, err := ioutil.ReadDir(kernelsBase)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// only for compatibility, docker is not really used
|
2023-04-06 19:05:21 +00:00
|
|
|
dii := containerImageInfo{
|
|
|
|
Name: config.KernelMask{
|
2019-08-31 07:50:29 +00:00
|
|
|
DistroType: distroType,
|
|
|
|
DistroRelease: si.OS.Version,
|
|
|
|
}.DockerName(),
|
|
|
|
}
|
|
|
|
|
|
|
|
rootfs, err := genRootfsImage(dii, download)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, k := range strings.Fields(string(rawOutput)) {
|
|
|
|
ki := config.KernelInfo{
|
|
|
|
DistroType: distroType,
|
|
|
|
DistroRelease: si.OS.Version,
|
|
|
|
KernelRelease: k,
|
|
|
|
|
|
|
|
KernelSource: "/lib/modules/" + k + "/build",
|
|
|
|
|
|
|
|
KernelPath: kernelsBase + genKernelPath(files, k),
|
|
|
|
InitrdPath: kernelsBase + genInitrdPath(files, k),
|
|
|
|
RootFS: rootfs,
|
|
|
|
}
|
|
|
|
|
|
|
|
vmlinux := "/usr/lib/debug/boot/vmlinux-" + k
|
2023-03-18 21:30:07 +00:00
|
|
|
log.Print("vmlinux", vmlinux)
|
2019-08-31 07:50:29 +00:00
|
|
|
if exists(vmlinux) {
|
|
|
|
ki.VmlinuxPath = vmlinux
|
|
|
|
}
|
|
|
|
|
|
|
|
kcfg.Kernels = append(kcfg.Kernels, ki)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|