summaryrefslogtreecommitdiffstats
path: root/apk.lua
blob: d6b1fd6185657bdd5d11af9c351f4c5bd96fcc4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- apk library
local mymodule = {}

mymodule.subprocess = require("subprocess")

mymodule.delete = function(package)
	local success = false
	local code, cmdresult = subprocess.call_capture({"apk", "del", package, stderr=subprocess.STDOUT})
	if string.find(cmdresult, "^OK") then
		cmdresult = "ERROR: Package not found\n"..cmdresult
	elseif not string.find(cmdresult, "ERROR") then
		success = true
	end
	return success, cmdresult
end

mymodule.install = function(package)
	local success = true
	local code, cmdresult = subprocess.call_capture({"apk", "add", package, stderr=subprocess.STDOUT})
	if string.find(cmdresult, "^ERROR") then
		success = false
	end
	return success, cmdresult
end

mymodule.version = function(package)
	local code, cmdresult = subprocess.call_capture({"apk", "info", "-ve", package, stderr=subprocess.STDOUT})
	if string.find(cmdresult, "^%s*$") then
		cmdresult = nil
	end
	return cmdresult
end

return mymodule