1
0
Fork 0

Implements fallback if rootfs image not found

timestamps
dump_stack() 2018-12-01 20:18:43 +00:00
parent b2f50efa2a
commit 1488d4b081
2 changed files with 42 additions and 0 deletions

View File

@ -150,6 +150,12 @@ func (dt DistroType) MarshalTOML() (data []byte, err error) {
return
}
type ByRootFS []KernelInfo
func (a ByRootFS) Len() int { return len(a) }
func (a ByRootFS) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByRootFS) Less(i, j int) bool { return a[i].RootFS < a[j].RootFS }
type KernelInfo struct {
DistroType DistroType
DistroRelease string // 18.04/7.4.1708/9.1

36
main.go
View File

@ -9,12 +9,46 @@ import (
"os"
"os/exec"
"os/user"
"sort"
kingpin "gopkg.in/alecthomas/kingpin.v2"
"github.com/jollheef/out-of-tree/config"
)
func findFallback(kcfg config.KernelConfig, ki config.KernelInfo) (rootfs string) {
for _, k := range kcfg.Kernels {
if !exists(k.RootFS) || k.DistroType != ki.DistroType {
continue
}
if k.RootFS < ki.RootFS {
rootfs = k.RootFS
return
}
}
return
}
func handleFallbacks(kcfg config.KernelConfig) {
sort.Sort(sort.Reverse(config.ByRootFS(kcfg.Kernels)))
for i, k := range kcfg.Kernels {
if !exists(k.RootFS) {
newRootFS := findFallback(kcfg, k)
s := k.RootFS + " does not exists "
if newRootFS != "" {
s += "(fallback to " + newRootFS + ")"
} else {
s += "(no fallback found)"
}
kcfg.Kernels[i].RootFS = newRootFS
log.Println(s)
}
}
}
func main() {
app := kingpin.New(
"out-of-tree",
@ -109,6 +143,8 @@ func main() {
}
}
handleFallbacks(kcfg)
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case pewCommand.FullCommand():
err = pewHandler(kcfg, *path, *pewKernel, *pewBinary,