diff --git a/engine/resources/virt_builder.go b/engine/resources/virt_builder.go index 46648720..be67b21a 100644 --- a/engine/resources/virt_builder.go +++ b/engine/resources/virt_builder.go @@ -199,19 +199,20 @@ func (obj *VirtBuilderRes) getBinaryPath() (string, error) { // getGuestfs returns the package to install for our os so that we can run // virt-builder. -func (obj *VirtBuilderRes) getGuestfs() (string, error) { +func (obj *VirtBuilderRes) getGuestfs() ([]string, error) { // TODO: Improve this function as things evolve. - - if _, err := os.Stat("/etc/redhat-release"); err == nil { // fedora - return "guestfs-tools", nil + distro, err := distroUtil.Distro(context.TODO()) // what is this resource running in? + if err != nil { + return nil, nil } - if _, err := os.Stat("/etc/debian_version"); err == nil { // debian - return "guestfs-tools", nil + packages, exists := distroUtil.DistroToGuestfsPackages(distro) + if !exists { + // TODO: patches welcome! + return nil, fmt.Errorf("os/version is not supported") } - // TODO: patches welcome! - return "", fmt.Errorf("os/version is not supported") + return packages, nil } // getDeps returns a list of packages to install for the specific os-version so @@ -307,7 +308,7 @@ func (obj *VirtBuilderRes) Init(init *engine.Init) error { return nil } - // Try to get the package of the binary... + // Try to get the packages for the binary... p, err := obj.getGuestfs() if err != nil { return err @@ -317,9 +318,11 @@ func (obj *VirtBuilderRes) Init(init *engine.Init) error { defer virtBuilderMutex.Unlock() // Try to install the binary... - obj.init.Logf("installing: %s", p) - if err := InstallOnePackage(context.TODO(), p); err != nil { - return err + for _, x := range p { + obj.init.Logf("installing: %s", x) + if err := InstallOnePackage(context.TODO(), x); err != nil { + return err + } } return nil diff --git a/util/distro/distro.go b/util/distro/distro.go index 3031d95f..24203de6 100644 --- a/util/distro/distro.go +++ b/util/distro/distro.go @@ -71,6 +71,18 @@ var ( "PackageKit", }, } + + // MapDistroToGuestfsPackages is a map of distro to packages needed to + // run the virt-builder software and guestfs suite. + MapDistroToGuestfsPackages = map[string][]string{ + // TODO: add more values + DistroDebian: { + "guestfs-tools", + }, + DistroFedora: { + "guestfs-tools", + }, + } ) // DistroToBootstrapPackages returns the list of packages corresponding to the @@ -80,6 +92,14 @@ func DistroToBootstrapPackages(distro string) ([]string, bool) { return l, exists } +// DistroToGuestfsPackages returns the list of packages corresponding to the +// distro for running the virt-builder software and guestfs suite. This returns +// false if the value doesn't exist. +func DistroToGuestfsPackages(distro string) ([]string, bool) { + l, exists := MapDistroToGuestfsPackages[distro] + return l, exists +} + // Family returns the distro family. func Family(ctx context.Context) (string, error) { if b, err := IsFamilyRedHat(ctx); err != nil {