refactor: move ubutu install/cleanup to module
This commit is contained in:
parent
407c1a7975
commit
6a338fc6ad
@ -82,3 +82,23 @@ func Match(km config.KernelMask) (pkgs []string, err error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -229,12 +229,20 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
||||
// TODO install/cleanup kernel interface
|
||||
switch sk.DistroType {
|
||||
case config.Ubuntu:
|
||||
var headerspkg string
|
||||
if headers {
|
||||
headerspkg = strings.Replace(pkgname, "image", "headers", -1)
|
||||
var commands []string
|
||||
commands, err = oraclelinux.Install(sk, pkgname, headers)
|
||||
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:
|
||||
var commands []string
|
||||
commands, err = oraclelinux.Install(sk, pkgname, headers)
|
||||
|
Loading…
Reference in New Issue
Block a user