Implements command for generate all kernels for distro/version
This commit is contained in:
parent
3fdb2736c8
commit
825d69b770
@ -66,13 +66,9 @@ Use custom kernels config
|
||||
|
||||
$ out-of-tree --kernels /path/to/kernels.toml pew
|
||||
|
||||
## Generate all kernels
|
||||
Generate all kernels
|
||||
|
||||
Does not required if you dont need to use `--guess`.
|
||||
|
||||
$ cd $GOPATH/src/github.com/jollheef/out-of-tree/tools/kernel-factory
|
||||
$ ./bootstrap.sh # more than 6-8 hours for all kernels
|
||||
$ export OUT_OF_TREE_KCFG=$GOPATH/src/github.com/jollheef/out-of-tree/tools/kernel-factory/output/kernels.toml
|
||||
$ out-of-tree kernel genall --distro Ubuntu --ver 16.04
|
||||
|
||||
## Development
|
||||
|
||||
|
96
kernel.go
96
kernel.go
@ -29,17 +29,17 @@ func kernelListHandler(kcfg config.KernelConfig) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func matchDebianKernelPkg(container, mask string, generic bool) (pkgs []string,
|
||||
err error) {
|
||||
func matchDebianHeadersPkg(container, mask string, generic bool) (
|
||||
pkgs []string, err error) {
|
||||
|
||||
cmd := "apt-cache search linux-image | cut -d ' ' -f 1"
|
||||
cmd := "apt-cache search linux-headers | cut -d ' ' -f 1"
|
||||
c := dockerCommand(container, "/tmp", "1m", cmd)
|
||||
rawOutput, err := c.CombinedOutput()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := regexp.Compile("linux-image-" + mask)
|
||||
r, err := regexp.Compile("linux-headers-" + mask)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -51,6 +51,9 @@ func matchDebianKernelPkg(container, mask string, generic bool) (pkgs []string,
|
||||
if generic && !strings.HasSuffix(pkg, "generic") {
|
||||
continue
|
||||
}
|
||||
if pkg == "linux-headers-generic" {
|
||||
continue
|
||||
}
|
||||
pkgs = append(pkgs, pkg)
|
||||
}
|
||||
|
||||
@ -144,11 +147,12 @@ func dockerImageAppend(sk config.KernelMask, pkgname string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Start adding kernel %s for %s:%s",
|
||||
pkgname, sk.DistroType.String(), sk.DistroRelease)
|
||||
imagepkg := strings.Replace(pkgname, "headers", "image", -1)
|
||||
|
||||
s := fmt.Sprintf("RUN apt-get install -y %s %s\n", pkgname,
|
||||
strings.Replace(pkgname, "image", "headers", -1))
|
||||
log.Printf("Start adding kernel %s for %s:%s",
|
||||
imagepkg, sk.DistroType.String(), sk.DistroRelease)
|
||||
|
||||
s := fmt.Sprintf("RUN apt-get install -y %s %s\n", imagepkg, pkgname)
|
||||
|
||||
err = ioutil.WriteFile(imagePath+"/Dockerfile",
|
||||
append(raw, []byte(s)...), 0644)
|
||||
@ -389,6 +393,38 @@ func hasKernel(ki config.KernelInfo, kcfg config.KernelConfig) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func generateKernels(km config.KernelMask) (err error) {
|
||||
err = generateBaseDockerImage(km)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var pkgs []string
|
||||
pkgs, err = matchDebianHeadersPkg(km.DockerName(),
|
||||
km.ReleaseMask, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i, pkg := range pkgs {
|
||||
log.Println(i, "/", len(pkgs))
|
||||
dockerImageAppend(km, pkg)
|
||||
}
|
||||
|
||||
err = kickImage(km.DockerName())
|
||||
if err != nil {
|
||||
log.Println("kick image", km.DockerName(), ":", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = copyKernels(km.DockerName())
|
||||
if err != nil {
|
||||
log.Println("copy kernels", km.DockerName(), ":", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func kernelAutogenHandler(workPath string) (err error) {
|
||||
ka, err := config.ReadArtifactConfig(workPath + "/.out-of-tree.toml")
|
||||
if err != nil {
|
||||
@ -401,33 +437,10 @@ func kernelAutogenHandler(workPath string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
err = generateBaseDockerImage(sk)
|
||||
err = generateKernels(sk)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var pkgs []string
|
||||
pkgs, err = matchDebianKernelPkg(sk.DockerName(),
|
||||
sk.ReleaseMask, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
dockerImageAppend(sk, pkg)
|
||||
}
|
||||
|
||||
err = kickImage(sk.DockerName())
|
||||
if err != nil {
|
||||
log.Println("kick image", sk.DockerName(), ":", err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = copyKernels(sk.DockerName())
|
||||
if err != nil {
|
||||
log.Println("copy kernels", sk.DockerName(), ":", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
err = updateKernelsCfg()
|
||||
@ -474,3 +487,22 @@ func kernelDockerRegenHandler() (err error) {
|
||||
|
||||
return updateKernelsCfg()
|
||||
}
|
||||
|
||||
func kernelGenallHandler(distro, version string) (err error) {
|
||||
distroType, err := config.NewDistroType(distro)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
km := config.KernelMask{
|
||||
DistroType: distroType,
|
||||
DistroRelease: version,
|
||||
ReleaseMask: ".*",
|
||||
}
|
||||
err = generateKernels(km)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return updateKernelsCfg()
|
||||
}
|
||||
|
10
main.go
10
main.go
@ -99,6 +99,14 @@ func main() {
|
||||
"Generate kernels based on a current config")
|
||||
kernelDockerRegenCommand := kernelCommand.Command("docker-regen",
|
||||
"Regenerate kernels config from out_of_tree_* docker images")
|
||||
kernelGenallCommand := kernelCommand.Command("genall",
|
||||
"Generate all kernels for distro")
|
||||
|
||||
genallDistroFlag := kernelGenallCommand.Flag("distro", "Distributive")
|
||||
distro := genallDistroFlag.Required().String()
|
||||
|
||||
genallVerFlag := kernelGenallCommand.Flag("ver", "Distro version")
|
||||
version := genallVerFlag.Required().String()
|
||||
|
||||
genCommand := app.Command("gen", "Generate .out-of-tree.toml skeleton")
|
||||
genModuleCommand := genCommand.Command("module",
|
||||
@ -169,6 +177,8 @@ func main() {
|
||||
err = kernelAutogenHandler(*path)
|
||||
case kernelDockerRegenCommand.FullCommand():
|
||||
err = kernelDockerRegenHandler()
|
||||
case kernelGenallCommand.FullCommand():
|
||||
err = kernelGenallHandler(*distro, *version)
|
||||
case genModuleCommand.FullCommand():
|
||||
err = genConfig(config.KernelModule)
|
||||
case genExploitCommand.FullCommand():
|
||||
|
Loading…
Reference in New Issue
Block a user