1
0

Install kernels to tmp directory first

This commit is contained in:
dump_stack() 2023-04-05 16:14:30 +00:00
parent 604d21e4a2
commit 29af467bee
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

@ -382,11 +382,32 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
return
}
func copyDirContent(source, target string) (err error) {
files, err := ioutil.ReadDir(source)
if err != nil {
return
}
if len(files) != 0 {
_, err = sh(source, "cp -r * "+target+"/")
if err != nil {
return
}
}
return
}
func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (err error) {
tmpdir, err := os.MkdirTemp("", "out-of-tree-"+pkgname+"-")
if err != nil {
log.Fatal().Err(err).Msg("make tmp directory")
}
defer os.RemoveAll(tmpdir)
slog := log.With().
Str("distro_type", sk.DistroType.String()).
Str("distro_release", sk.DistroRelease).
Str("pkg", pkgname).
Str("tmpdir", tmpdir).
Logger()
c, err := NewContainer(sk.DockerName(), time.Hour) // TODO conf
@ -410,6 +431,17 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
}
}
volumes := c.Volumes
c.Volumes.LibModules = fmt.Sprintf("%s/libmodules", tmpdir)
os.MkdirAll(c.Volumes.LibModules, 0777)
c.Volumes.UsrSrc = fmt.Sprintf("%s/usrsrc", tmpdir)
os.MkdirAll(c.Volumes.UsrSrc, 0777)
c.Volumes.Boot = fmt.Sprintf("%s/boot", tmpdir)
os.MkdirAll(c.Volumes.Boot, 0777)
slog.Debug().Msgf("Installing kernel")
switch sk.DistroType {
@ -451,6 +483,19 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
return
}
err = copyDirContent(c.Volumes.LibModules, volumes.LibModules)
if err != nil {
return
}
err = copyDirContent(c.Volumes.UsrSrc, volumes.UsrSrc)
if err != nil {
return
}
err = copyDirContent(c.Volumes.Boot, volumes.Boot)
if err != nil {
return
}
slog.Debug().Msgf("Success")
return
}