summaryrefslogtreecommitdiff
path: root/internal/resource/pkg/pkg.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/pkg.go
parent5600bedb927e291e2e78e6140de256e1a1d4475c (diff)
initial package management
Diffstat (limited to 'internal/resource/pkg/pkg.go')
-rw-r--r--internal/resource/pkg/pkg.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/resource/pkg/pkg.go b/internal/resource/pkg/pkg.go
new file mode 100644
index 0000000..72f098c
--- /dev/null
+++ b/internal/resource/pkg/pkg.go
@@ -0,0 +1,47 @@
+package pkg
+
+import (
+ "errors"
+ "os"
+)
+
+type Ensure int
+
+const (
+ PkgPresent Ensure = iota
+ PkgAbsent
+ PkgLatest
+)
+
+type applyFunc func(name string, ensure Ensure) error
+
+func Present(name string, ensure Ensure) error {
+ bin, err := detect()
+ if err != nil {
+ return err
+ }
+
+ var applyFunc applyFunc
+
+ switch bin {
+ case "dnf":
+ applyFunc = applyDNF
+ }
+
+ return applyFunc(name, ensure)
+}
+
+func detect() (string, error) {
+ switch {
+ case exists("/etc/fedora-release"):
+ fallthrough
+ case exists("/etc/rocky-release"):
+ return "dnf", nil
+ }
+ return "", errors.New("unable to detect package manager!")
+}
+
+func exists(path string) bool {
+ _, err := os.Stat(path)
+ return err == nil
+}