Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rpmbootstrap source #771

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions managers/yum.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func (m *yum) load() error {
}

func (m *yum) manageRepository(repoAction shared.DefinitionPackagesRepository) error {
// Run rpmdb --rebuilddb
err := shared.RunCommand(m.ctx, nil, nil, "rpmdb", "--rebuilddb")
if err != nil {
return fmt.Errorf("failed to run rpmdb --rebuilddb: %w", err)
}

return yumManageRepository(repoAction)
}

Expand Down
1 change: 1 addition & 0 deletions shared/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func (d *Definition) Validate() error {
"centos-http",
"springdalelinux-http",
"debootstrap",
"rpmbootstrap",
"fedora-http",
"gentoo-http",
"ubuntu-http",
Expand Down
85 changes: 85 additions & 0 deletions sources/rpmbootstrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package sources

import (
"fmt"
"os"
"path"

"github.com/lxc/distrobuilder/shared"
)

type rpmbootstrap struct {
common
}

func (s *rpmbootstrap) repodirs() (dir string, err error) {
// check whether yum command exists
if err = shared.RunCommand(s.ctx, nil, nil, "yum", "--version"); err != nil {
err = fmt.Errorf("yum command not found, sudo apt-get install yum to install it and try again: %w", err)
return
}

reposdir := path.Join(s.sourcesDir, "etc", "yum.repos.d")
err = os.MkdirAll(reposdir, 0755)
if err != nil {
return "", err
}

distribution := s.definition.Image.Distribution
content := s.definition.Source.URL
if distribution == "" || content == "" {
err = fmt.Errorf("No valid distribution and source url specified")
return "", err
}

err = os.WriteFile(path.Join(reposdir, distribution+".repo"), []byte(content), 0644)
if err != nil {
return "", err
}

return reposdir, nil
}

// Run runs yum --installroot.
func (s *rpmbootstrap) Run() error {
repodir, err := s.repodirs()
if err != nil {
return err
}

release := s.definition.Image.Release
args := []string{fmt.Sprintf("--installroot=%s", s.rootfsDir),
fmt.Sprintf("--releasever=%s", release),
fmt.Sprintf("--setopt=reposdir=%s", repodir),
"install", "-y"}

os.RemoveAll(s.rootfsDir)
earlyPackagesRemove := s.definition.GetEarlyPackages("remove")

for _, pkg := range earlyPackagesRemove {
args = append(args, fmt.Sprintf("--exclude=%s", pkg))
}

pkgs := []string{"yum", "dnf"}
components := s.definition.Source.Components

for _, pkg := range components {
pkg, err = shared.RenderTemplate(pkg, s.definition)
if err != nil {
return err
}

pkgs = append(pkgs, pkg)
}

earlyPackagesInstall := s.definition.GetEarlyPackages("install")
pkgs = append(pkgs, earlyPackagesInstall...)
args = append(args, pkgs...)

// Install
if err = shared.RunCommand(s.ctx, nil, nil, "yum", args...); err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions sources/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var downloaders = map[string]func() downloader{
"plamolinux-http": func() downloader { return &plamolinux{} },
"rockylinux-http": func() downloader { return &rockylinux{} },
"rootfs-http": func() downloader { return &rootfs{} },
"rpmbootstrap": func() downloader { return &rpmbootstrap{} },
"springdalelinux-http": func() downloader { return &springdalelinux{} },
"ubuntu-http": func() downloader { return &ubuntu{} },
"voidlinux-http": func() downloader { return &voidlinux{} },
Expand Down
Loading