[lxc-devel] [distrobuilder/master] Add repo handler for dnf and yum
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Fri Oct 25 06:35:38 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191024/4f32425c/attachment.bin>
-------------- next part --------------
From 3732bd4b33a531fdd39e1e74889897813908c113 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 25 Oct 2019 08:32:24 +0200
Subject: [PATCH 1/2] managers/yum: Add repo handler
This allows defining custom repositories.
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
managers/yum.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/managers/yum.go b/managers/yum.go
index 767fd32..f18f6a5 100644
--- a/managers/yum.go
+++ b/managers/yum.go
@@ -1,5 +1,16 @@
package managers
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+
+ lxd "github.com/lxc/lxd/shared"
+
+ "github.com/lxc/distrobuilder/shared"
+)
+
// NewYum creates a new Manager instance.
func NewYum() *Manager {
return &Manager{
@@ -30,5 +41,42 @@ func NewYum() *Manager {
"update",
},
},
+ RepoHandler: yumRepoHandler,
+ }
+}
+
+func yumRepoHandler(repoAction shared.DefinitionPackagesRepository) error {
+ targetFile := filepath.Join("/etc/yum.repos.d", repoAction.Name)
+
+ if !strings.HasSuffix(targetFile, ".repo") {
+ targetFile = fmt.Sprintf("%s.repo", targetFile)
+ }
+
+ if !lxd.PathExists(filepath.Dir(targetFile)) {
+ err := os.MkdirAll(filepath.Dir(targetFile), 0755)
+ if err != nil {
+ return err
+ }
+ }
+
+ f, err := os.Create(targetFile)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ _, err = f.WriteString(repoAction.URL)
+ if err != nil {
+ return err
+ }
+
+ // Append final new line if missing
+ if !strings.HasSuffix(repoAction.URL, "\n") {
+ _, err = f.WriteString("\n")
+ if err != nil {
+ return err
+ }
}
+
+ return nil
}
From cb1dd6bbcea93913a80de6c06d4323907b1b33e1 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 25 Oct 2019 08:34:31 +0200
Subject: [PATCH 2/2] managers/dnf: Add repo handler
This allows defining custom repositories. It uses the yum repo handler
as they have the same repo structure.
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
managers/dnf.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/managers/dnf.go b/managers/dnf.go
index 83d4e0a..b1331c5 100644
--- a/managers/dnf.go
+++ b/managers/dnf.go
@@ -30,5 +30,6 @@ func NewDnf() *Manager {
"clean", "all",
},
},
+ RepoHandler: yumRepoHandler,
}
}
More information about the lxc-devel
mailing list