1
0

refactor: move ubutu install/cleanup to module

This commit is contained in:
dump_stack() 2023-05-18 11:46:12 +00:00
parent 407c1a7975
commit 6a338fc6ad
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 32 additions and 4 deletions

View File

@ -82,3 +82,23 @@ func Match(km config.KernelMask) (pkgs []string, err error) {
return return
} }
func Install(km config.KernelMask, pkgname string, headers bool) (commands []string, err error) {
var headerspkg string
if headers {
headerspkg = strings.Replace(pkgname, "image", "headers", -1)
}
cmdf := func(f string, s ...interface{}) {
commands = append(commands, fmt.Sprintf(f, s...))
}
cmdf("apt-get install -y %s %s", pkgname, headerspkg)
return
}
func Cleanup(km config.KernelMask, pkgname string) {
return
}

View File

@ -229,12 +229,20 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
// TODO install/cleanup kernel interface // TODO install/cleanup kernel interface
switch sk.DistroType { switch sk.DistroType {
case config.Ubuntu: case config.Ubuntu:
var headerspkg string var commands []string
if headers { commands, err = oraclelinux.Install(sk, pkgname, headers)
headerspkg = strings.Replace(pkgname, "image", "headers", -1) if err != nil {
return
} }
defer func() {
if err != nil {
oraclelinux.Cleanup(sk, pkgname)
}
}()
cmd += fmt.Sprintf(" && apt-get install -y %s %s", pkgname, headerspkg) for _, command := range commands {
cmd += fmt.Sprintf(" && %s", command)
}
case config.OracleLinux, config.CentOS: case config.OracleLinux, config.CentOS:
var commands []string var commands []string
commands, err = oraclelinux.Install(sk, pkgname, headers) commands, err = oraclelinux.Install(sk, pkgname, headers)