diff options
author | Aki <please@ignore.pl> | 2024-01-02 01:50:08 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-01-02 01:50:08 +0100 |
commit | bda360e2af4b9d0da0f5957e0c737ea39863719a (patch) | |
tree | 8758dea02904d11528fa33219fee319c2a3c33b4 | |
parent | 91e85f9809ed406d2120e424aaa2f249ee18e2c2 (diff) | |
download | ensure-master.zip ensure-master.tar.gz ensure-master.tar.bz2 |
-rw-r--r-- | ensure.lua | 7 | ||||
-rw-r--r-- | ensure/engine.lua | 37 | ||||
-rw-r--r-- | ensure/engines/apt.lua | 15 | ||||
-rw-r--r-- | ensure/engines/pacman.lua | 15 |
4 files changed, 70 insertions, 4 deletions
@@ -1,10 +1,9 @@ #!/usr/bin/env lua local l = require "ensure.list" +local e = require "ensure.engine" local loud = { identifier = l.default.identifier, invalid = function (_, name) io.stderr:write(string.format("invalid package name: %q\n", name)) end, } -local p = l.all(arg[1] or os.getenv("ENSURE") or "/etc/ensure.d", loud) -for _, name in pairs(p) do - print(name) -end +local path = arg[1] or os.getenv("ENSURE") or "/etc/ensure.d" +e.install(e.check(l.all(path, loud))) diff --git a/ensure/engine.lua b/ensure/engine.lua new file mode 100644 index 0000000..ccaa18b --- /dev/null +++ b/ensure/engine.lua @@ -0,0 +1,37 @@ +local path = require "pl.path" +local engine = {} + + +function engine.detect () + local function detect (pathnames) + for name, pathname in pairs(pathnames) do + if path.isfile(pathname) then + return name + end + end + end + + local name = detect { + pacman="/usr/bin/pacman", -- TODO: Use which/PATH? + apt="/usr/bin/apt", + } + engine.loaded = require("ensure.engines." .. name) + return engine.loaded +end + + +local function loaded (target, name) + target[name] = function (...) + if not engine.loaded then + engine.detect() + end + return engine.loaded[name](...) + end +end + + +loaded(engine, "check") +loaded(engine, "install") + + +return engine diff --git a/ensure/engines/apt.lua b/ensure/engines/apt.lua new file mode 100644 index 0000000..82f7188 --- /dev/null +++ b/ensure/engines/apt.lua @@ -0,0 +1,15 @@ +local apt = {} +local unpack = table.unpack or unpack + + +function apt.check (packages) + return packages +end + + +function apt.install (packages) + print("apt", "install", unpack(packages)) +end + + +return apt diff --git a/ensure/engines/pacman.lua b/ensure/engines/pacman.lua new file mode 100644 index 0000000..21674f8 --- /dev/null +++ b/ensure/engines/pacman.lua @@ -0,0 +1,15 @@ +local pacman = {} +local unpack = table.unpack or unpack + + +function pacman.check (packages) + return packages +end + + +function pacman.install (packages) + print("pacman", "-S", unpack(packages)) +end + + +return pacman |