Implements fallback if rootfs image not found
This commit is contained in:
parent
b2f50efa2a
commit
1488d4b081
@ -150,6 +150,12 @@ func (dt DistroType) MarshalTOML() (data []byte, err error) {
|
|||||||
return
|
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 {
|
type KernelInfo struct {
|
||||||
DistroType DistroType
|
DistroType DistroType
|
||||||
DistroRelease string // 18.04/7.4.1708/9.1
|
DistroRelease string // 18.04/7.4.1708/9.1
|
||||||
|
36
main.go
36
main.go
@ -9,12 +9,46 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"sort"
|
||||||
|
|
||||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
|
||||||
"github.com/jollheef/out-of-tree/config"
|
"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() {
|
func main() {
|
||||||
app := kingpin.New(
|
app := kingpin.New(
|
||||||
"out-of-tree",
|
"out-of-tree",
|
||||||
@ -109,6 +143,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleFallbacks(kcfg)
|
||||||
|
|
||||||
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
||||||
case pewCommand.FullCommand():
|
case pewCommand.FullCommand():
|
||||||
err = pewHandler(kcfg, *path, *pewKernel, *pewBinary,
|
err = pewHandler(kcfg, *path, *pewKernel, *pewBinary,
|
||||||
|
Loading…
Reference in New Issue
Block a user