fix: support force kernel reinstallation
This commit is contained in:
parent
3271710653
commit
ee90bfaa72
@ -35,6 +35,10 @@ type Distro struct {
|
|||||||
Release string
|
Release string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Distro) String() string {
|
||||||
|
return d.ID.String() + " " + d.Release
|
||||||
|
}
|
||||||
|
|
||||||
func (d Distro) Packages() (packages []string, err error) {
|
func (d Distro) Packages() (packages []string, err error) {
|
||||||
for _, dd := range distros {
|
for _, dd := range distros {
|
||||||
if d.ID != None && d.ID != dd.Distro().ID {
|
if d.ID != None && d.ID != dd.Distro().ID {
|
||||||
|
43
kernel.go
43
kernel.go
@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/naoina/toml"
|
"github.com/naoina/toml"
|
||||||
@ -39,6 +40,7 @@ type KernelCmd struct {
|
|||||||
ConfigRegen KernelConfigRegenCmd `cmd:"" help:"regenerate config"`
|
ConfigRegen KernelConfigRegenCmd `cmd:"" help:"regenerate config"`
|
||||||
|
|
||||||
shutdown bool
|
shutdown bool
|
||||||
|
kcfg config.KernelConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd KernelCmd) UpdateConfig() (err error) {
|
func (cmd KernelCmd) UpdateConfig() (err error) {
|
||||||
@ -77,6 +79,29 @@ func (cmd KernelCmd) UpdateConfig() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *KernelCmd) GenKernel(km config.Target, pkg string, max *int) {
|
func (cmd *KernelCmd) GenKernel(km config.Target, pkg string, max *int) {
|
||||||
|
flog := log.With().
|
||||||
|
Str("kernel", pkg).
|
||||||
|
Str("distro", km.Distro.String()).
|
||||||
|
Logger()
|
||||||
|
|
||||||
|
reinstall := false
|
||||||
|
for _, kinfo := range cmd.kcfg.Kernels {
|
||||||
|
if strings.Contains(pkg, kinfo.KernelVersion) {
|
||||||
|
if !cmd.Force {
|
||||||
|
flog.Info().Msg("already installed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reinstall = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if reinstall {
|
||||||
|
flog.Info().Msg("reinstall")
|
||||||
|
} else {
|
||||||
|
flog.Info().Msg("install")
|
||||||
|
}
|
||||||
|
|
||||||
var attempt int
|
var attempt int
|
||||||
for {
|
for {
|
||||||
attempt++
|
attempt++
|
||||||
@ -85,31 +110,35 @@ func (cmd *KernelCmd) GenKernel(km config.Target, pkg string, max *int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO cmd.Force
|
|
||||||
err := km.Distro.Install(pkg, !cmd.NoHeaders)
|
err := km.Distro.Install(pkg, !cmd.NoHeaders)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
*max--
|
*max--
|
||||||
|
flog.Info().Msg("success")
|
||||||
break
|
break
|
||||||
} else if attempt >= cmd.Retries {
|
} else if attempt >= cmd.Retries {
|
||||||
log.Error().Err(err).Msg("install kernel")
|
flog.Error().Err(err).Msg("install kernel")
|
||||||
log.Debug().Msg("skip")
|
flog.Debug().Msg("skip")
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
log.Warn().Err(err).Msg("install kernel")
|
flog.Warn().Err(err).Msg("install kernel")
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
log.Info().Msg("retry")
|
flog.Info().Msg("retry")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *KernelCmd) Generate(g *Globals, km config.Target, max int) (err error) {
|
func (cmd *KernelCmd) Generate(g *Globals, km config.Target, max int) (err error) {
|
||||||
|
|
||||||
// TODO cmd.Update
|
// TODO cmd.Update
|
||||||
|
|
||||||
|
cmd.kcfg, err = config.ReadKernelConfig(g.Config.Kernels)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug().Err(err).Msg("read kernels config")
|
||||||
|
}
|
||||||
|
|
||||||
container.Commands = g.Config.Docker.Commands
|
container.Commands = g.Config.Docker.Commands
|
||||||
container.Registry = g.Config.Docker.Registry
|
container.Registry = g.Config.Docker.Registry
|
||||||
|
|
||||||
log.Info().Msgf("Generating for kernel mask %v", km)
|
log.Info().Msgf("Generating for target %v", km)
|
||||||
|
|
||||||
_, err = kernel.GenRootfsImage(container.Image{Name: km.DockerName()},
|
_, err = kernel.GenRootfsImage(container.Image{Name: km.DockerName()},
|
||||||
!cmd.NoDownload)
|
!cmd.NoDownload)
|
||||||
|
Loading…
Reference in New Issue
Block a user