summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-07-16 16:04:46 +0000
committerTed Trask <ttrask01@yahoo.com>2009-07-16 16:04:46 +0000
commit6babfc62e7e096ef0dc7e4e359e3508442d8ff9b (patch)
treea93b55272c86c54ad4bfe5c1222ab7aeb0343282
parent9c3dd2d3f8781e8503e7420db54fde7e819c9ba4 (diff)
downloadacf-core-6babfc62e7e096ef0dc7e4e359e3508442d8ff9b.tar.bz2
acf-core-6babfc62e7e096ef0dc7e4e359e3508442d8ff9b.tar.xz
Simplified apk.lua by moving functions to acf-apk-tools version 0.3.0v0.8.0
Bumped version to 0.8.0
-rw-r--r--Makefile2
-rw-r--r--lib/apk.lua152
-rw-r--r--lib/processinfo.lua4
3 files changed, 27 insertions, 131 deletions
diff --git a/Makefile b/Makefile
index 0759085..fa8a2e7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
APP_NAME=core
PACKAGE=acf-$(APP_NAME)
-VERSION=0.7.0
+VERSION=0.8.0
P=$(PACKAGE)-$(VERSION)
DISTDIR:=$(shell pwd)/$(P)
diff --git a/lib/apk.lua b/lib/apk.lua
index 7ac1bef..b4cb6ff 100644
--- a/lib/apk.lua
+++ b/lib/apk.lua
@@ -1,146 +1,44 @@
-- apk library
module (..., package.seeall)
-local repo = nil
local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
-local install_cache = false
-
-local reload_installed = function()
- if repo then
- -- clear out installed info
- for name,value in pairs(repo) do
- if value then
- value.installed = nil
- value.comment = nil
- end
- end
- -- read in which are installed
- local f = io.popen(path.."/sbin/apk info -vv 2>/dev/null")
- local line
- for line in f:lines() do
- local name, ver, comment = string.match(line, "(%S+)%-(%d+%S*)%s+(.*)")
- if not repo[name] then
- repo[name] = {}
- end
- repo[name].installed = ver
- repo[name].comment = comment
- end
- install_cache = true
- end
- return repo
-end
-
-
-repository = function()
- if not repo then
- -- read in all of the packages
- local f = io.popen(path.."/sbin/apk search 2>/dev/null")
- repo = {}
- install_cache = false
- for line in f:lines() do
- local name, ver = string.match(line, "(.*)%-(%d+.*)")
- if name then
- repo[name] = {}
- repo[name].version = ver
- end
- end
- f:close()
- end
- if not install_cache then
- reload_installed()
- end
- return repo
-end
-
-get_all = function()
- repo = repository()
- -- read in all of the available packages
- local all = {}
- for name,value in pairs(repo) do
- if value.version then
- local temp = {}
- temp.name = name
- temp.version = value.version
- all[#all + 1] = temp
- end
- end
- table.sort(all, function(a,b) return (a.name < b.name) end)
- return all
-end
-
-get_loaded = function()
- repo = repository()
- -- read in the loaded packages
- local loaded = {}
- for name,value in pairs(repo) do
- if value.installed then
- local temp = {}
- temp.name = name
- temp.version = value.installed
- temp.description = value.comment
- loaded[#loaded+1] = temp
- end
- end
- table.sort(loaded, function(a,b) return (a.name < b.name) end)
- return loaded
-end
-
-get_available = function()
- repo = repository()
- -- available are all except same version installed
- local available = {}
- for name,value in pairs(repo) do
- if value.version ~= value.installed then
- local temp = {}
- temp.name = name
- temp.version = value.version
- available[#available + 1] = temp
- end
- end
- table.sort(available, function(a,b) return (a.name < b.name) end)
- return available
-end
delete = function(package)
- repo = repository()
local success = false
- local cmdresult = "Delete failed - Invalid package"
- if package and repo[package] then
+ local cmdresult
+ local cmd = path .. "apk del " .. package .. " 2>&1"
+ local f = io.popen( cmd )
+ cmdresult = f:read("*a") or ""
+ f:close()
+ if string.find(cmdresult, "^OK") then
+ cmdresult = "ERROR: Package not found\n"..cmdresult
+ elseif not string.find(cmdresult, "ERROR") then
success = true
- local cmd = path .. "apk del " .. package .. " 2>&1"
- local f = io.popen( cmd )
- cmdresult = f:read("*a") or ""
- f:close()
- install_cache = false
end
return success, cmdresult
end
install = function(package)
- repo = repository()
- local success = false
- local cmdresult = "Install failed - Invalid package"
- if package and repo[package] then
- success = true
- local cmd = path .. "apk add " .. package .. " 2>&1"
- local f = io.popen( cmd )
- cmdresult = f:read("*a")
- f:close()
- install_cache = false
+ local success = true
+ local cmdresult
+ local cmd = path .. "apk add " .. package .. " 2>&1"
+ local f = io.popen( cmd )
+ cmdresult = f:read("*a")
+ f:close()
+ if string.find(cmdresult, "^ERROR") then
+ success = false
end
return success, cmdresult
end
-is_installed = function(package)
- repo = repository()
- return package and repo[package] and repo[package].installed
-end
-
version = function(package)
- repo = repository()
- if package and repo[package] then
- return repo[package].installed
- else
- return nil
- end
+ local cmdresult
+ local cmd = path .. "apk info -ve " .. package .. " 2>&1"
+ local f = io.popen( cmd )
+ cmdresult = f:read("*a")
+ f:close()
+ if string.find(cmdresult, "^%s*$") then
+ cmdresult = nil
+ end
+ return cmdresult
end
diff --git a/lib/processinfo.lua b/lib/processinfo.lua
index a39efc4..77dee5b 100644
--- a/lib/processinfo.lua
+++ b/lib/processinfo.lua
@@ -11,9 +11,7 @@ local path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin "
function package_version(packagename)
local result = apk.version(packagename)
local errtxt
- if result then
- result = packagename.."-"..result
- else
+ if not result then
errtxt = "Program not installed"
end
return result,errtxt