refactor: move debian-related functions to debian module
This commit is contained in:
parent
e1ae427757
commit
4d950d7302
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"code.dumpstack.io/tools/out-of-tree/cache"
|
||||||
"code.dumpstack.io/tools/out-of-tree/config"
|
"code.dumpstack.io/tools/out-of-tree/config"
|
||||||
"code.dumpstack.io/tools/out-of-tree/container"
|
"code.dumpstack.io/tools/out-of-tree/container"
|
||||||
"code.dumpstack.io/tools/out-of-tree/fs"
|
"code.dumpstack.io/tools/out-of-tree/fs"
|
||||||
@ -307,3 +308,41 @@ func ContainerVolumes(km config.KernelMask, pkgname string) (volumes container.V
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InstallCommands(km config.KernelMask, pkgname string) (cmds []string, err error) {
|
||||||
|
dk, err := getCachedKernel(pkgname + ".deb")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pkg := range dk.Packages() {
|
||||||
|
found, newurl := cache.PackageURL(
|
||||||
|
km.DistroType,
|
||||||
|
pkg.Deb.URL,
|
||||||
|
)
|
||||||
|
if found {
|
||||||
|
log.Debug().Msgf("cached deb found %s", newurl)
|
||||||
|
pkg.Deb.URL = newurl
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO use faketime on old releases?
|
||||||
|
pkg.Deb.URL = strings.Replace(pkg.Deb.URL, "https", "http", -1)
|
||||||
|
|
||||||
|
cmds = append(cmds, "wget --no-check-certificate "+pkg.Deb.URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmds = append(cmds, "dpkg -i ./*.deb")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func CleanupFailed(km config.KernelMask, pkgname string) {
|
||||||
|
pkgdir := config.Dir(filepath.Join("volumes", km.DockerName(), pkgname))
|
||||||
|
|
||||||
|
log.Debug().Msgf("cleanup %s", pkgdir)
|
||||||
|
|
||||||
|
err := os.RemoveAll(pkgdir)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msg("cleanup")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -122,7 +122,7 @@ func getDebianKernel(version string) (dk DebianKernel, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCachedKernel by deb package name
|
// GetCachedKernel by deb package name
|
||||||
func GetCachedKernel(deb string) (dk DebianKernel, err error) {
|
func getCachedKernel(deb string) (dk DebianKernel, err error) {
|
||||||
c, err := NewCache(CachePath)
|
c, err := NewCache(CachePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("cache")
|
log.Error().Err(err).Msg("cache")
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"code.dumpstack.io/tools/out-of-tree/config"
|
"code.dumpstack.io/tools/out-of-tree/config"
|
||||||
"code.dumpstack.io/tools/out-of-tree/container"
|
"code.dumpstack.io/tools/out-of-tree/container"
|
||||||
"code.dumpstack.io/tools/out-of-tree/distro/debian"
|
"code.dumpstack.io/tools/out-of-tree/distro/debian"
|
||||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
|
||||||
"code.dumpstack.io/tools/out-of-tree/fs"
|
"code.dumpstack.io/tools/out-of-tree/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -406,35 +405,20 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
|
|||||||
"/boot/initramfs-%s.img %s", version, version)
|
"/boot/initramfs-%s.img %s", version, version)
|
||||||
}
|
}
|
||||||
case config.Debian:
|
case config.Debian:
|
||||||
// TODO move to distro/debian/
|
var commands []string
|
||||||
|
commands, err = debian.InstallCommands(sk, pkgname)
|
||||||
var dk debian.DebianKernel
|
|
||||||
dk, err = debian.GetCachedKernel(pkgname + ".deb")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
pkgs := []snapshot.Package{dk.Image}
|
if err != nil {
|
||||||
if headers {
|
debian.CleanupFailed(sk, pkgname)
|
||||||
pkgs = append(pkgs, dk.Headers...)
|
|
||||||
pkgs = append(pkgs, dk.Dependencies...)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, pkg := range pkgs {
|
|
||||||
found, newurl := cache.PackageURL(
|
|
||||||
sk.DistroType,
|
|
||||||
pkg.Deb.URL,
|
|
||||||
)
|
|
||||||
if found {
|
|
||||||
log.Debug().Msgf("cached deb found %s", newurl)
|
|
||||||
pkg.Deb.URL = newurl
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
cmd += fmt.Sprintf(" && wget --no-check-certificate %s",
|
for _, command := range commands {
|
||||||
strings.Replace(pkg.Deb.URL, "https", "http", -1))
|
cmd += fmt.Sprintf(" && %s", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd += fmt.Sprintf(" && dpkg -i ./*deb ; apt-get -fy install")
|
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("%s not yet supported", sk.DistroType.String())
|
err = fmt.Errorf("%s not yet supported", sk.DistroType.String())
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user