summaryrefslogtreecommitdiff
path: root/internal/resource/pkg/dnf.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-06 23:56:32 +0300
committerPaul Buetow <paul@buetow.org>2026-07-06 23:56:32 +0300
commit62ff4e782bc057d277a7c41fa35a665e2aeca045 (patch)
tree5ca14104e68a9815f20ae6802c78341c6dc94371 /internal/resource/pkg/dnf.go
parent5600bedb927e291e2e78e6140de256e1a1d4475c (diff)
initial package management
Diffstat (limited to 'internal/resource/pkg/dnf.go')
-rw-r--r--internal/resource/pkg/dnf.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/resource/pkg/dnf.go b/internal/resource/pkg/dnf.go
new file mode 100644
index 0000000..ad03da2
--- /dev/null
+++ b/internal/resource/pkg/dnf.go
@@ -0,0 +1,34 @@
+package pkg
+
+import (
+ "fmt"
+ "log"
+
+ "codeberg.org/snonux/gonf/internal/exec"
+)
+
+func applyDNF(name string, ensure Ensure) error {
+ var args []string
+
+ switch ensure {
+ case PkgPresent:
+ args = []string{"install", "-y", name}
+ case PkgAbsent:
+ args = []string{"remove", "-y", name}
+ case PkgLatest:
+ args = []string{"install", "-y", name}
+ default:
+ log.Fatalf("unsupported ensure state: %v", ensure)
+ }
+
+ stdout, stderr, exitCode, err := exec.Run("dnf", args...)
+ if err != nil {
+ return fmt.Errorf("failed to execute dnf: %w", err)
+ }
+
+ if exitCode != 0 {
+ return fmt.Errorf("dnf failed with exit code %d: %s\n%s", exitCode, stdout, stderr)
+ }
+
+ return nil
+}