summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-05-26 16:00:59 +0000
committerTed Trask <ttrask01@yahoo.com>2009-05-26 16:00:59 +0000
commit9b934599d84f0b3dd32cda657790dc2c34bd95d8 (patch)
tree29b6dd6a11c40d799add39074d1e40128d4da9dc
parenta82f5d48a729e17382790588efc251bdea5a23f1 (diff)
downloadacf-core-9b934599d84f0b3dd32cda657790dc2c34bd95d8.tar.bz2
acf-core-9b934599d84f0b3dd32cda657790dc2c34bd95d8.tar.xz
Updates for alpine 1.9 apk tools and openrc. Bug fix for format.lua string_to_table.
-rw-r--r--app/status-html.lsp2
-rw-r--r--lib/apk.lua17
-rw-r--r--lib/format.lua8
-rw-r--r--lib/modelfunctions.lua6
-rw-r--r--lib/processinfo.lua116
5 files changed, 78 insertions, 71 deletions
diff --git a/app/status-html.lsp b/app/status-html.lsp
index 8bd53db..eb63527 100644
--- a/app/status-html.lsp
+++ b/app/status-html.lsp
@@ -19,6 +19,6 @@ end
displayitem(data.value.autostart)
if not (data.value.version and data.value.version.errtxt) and data.value.autostart and data.value.autostart.errtxt and session.permissions.rc and session.permissions.rc.edit then
%>
- <a href="<%= html.html_escape(page_info.script .. "/alpine-baselayout/rc/edit?servicename="..data.value.autostart.name.."&redir=".. page_info.orig_action) %>">Schedule autostart</a>
+ <a href="<%= html.html_escape(page_info.script .. "/alpine-baselayout/rc/edit?servicename="..data.value.autostart.name.."&redir=".. page_info.orig_action) %>">Enable autostart</a>
<% end %>
</DL>
diff --git a/lib/apk.lua b/lib/apk.lua
index 774b7f0..7ac1bef 100644
--- a/lib/apk.lua
+++ b/lib/apk.lua
@@ -15,7 +15,7 @@ local reload_installed = function()
end
end
-- read in which are installed
- local f = io.popen(path.."/sbin/apk_info 2>/dev/null")
+ 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+(.*)")
@@ -34,7 +34,7 @@ end
repository = function()
if not repo then
-- read in all of the packages
- local f = io.popen(path.."/sbin/apk_fetch -lvq 2>/dev/null")
+ local f = io.popen(path.."/sbin/apk search 2>/dev/null")
repo = {}
install_cache = false
for line in f:lines() do
@@ -107,7 +107,7 @@ delete = function(package)
local cmdresult = "Delete failed - Invalid package"
if package and repo[package] then
success = true
- local cmd = path .. "apk_delete " .. package .. " 2>&1"
+ local cmd = path .. "apk del " .. package .. " 2>&1"
local f = io.popen( cmd )
cmdresult = f:read("*a") or ""
f:close()
@@ -122,7 +122,7 @@ install = function(package)
local cmdresult = "Install failed - Invalid package"
if package and repo[package] then
success = true
- local cmd = path .. "apk_add " .. package .. " 2>&1"
+ local cmd = path .. "apk add " .. package .. " 2>&1"
local f = io.popen( cmd )
cmdresult = f:read("*a")
f:close()
@@ -135,3 +135,12 @@ 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
+end
diff --git a/lib/format.lua b/lib/format.lua
index 63b8fec..9492eca 100644
--- a/lib/format.lua
+++ b/lib/format.lua
@@ -175,10 +175,14 @@ function string_to_table ( text, delimiter)
while 1 do
local first, last = string.find(text, delimiter, pos)
if first then -- found?
- table.insert(list, string.sub(text, pos, first-1))
+ if first > pos then
+ table.insert(list, string.sub(text, pos, first-1))
+ end
pos = last+1
else
- table.insert(list, string.sub(text, pos))
+ if pos < string.len(text) then
+ table.insert(list, string.sub(text, pos))
+ end
break
end
end
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index c27965d..1314b42 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -40,10 +40,10 @@ function getstatus(processname, packagename, label, servicename)
status.status = getenabled(processname)
- local autostart_sequence, autostart_errtxt = processinfo.process_startupsequence(servicename or processname)
+ local autostart_value, autostart_errtxt = processinfo.process_autostart(servicename or processname)
status.autostart = cfe({
- label="Autostart sequence",
- value=autostart_sequence,
+ label="Autostart status",
+ value=autostart_value,
errtxt=autostart_errtxt,
name=servicename or processname
})
diff --git a/lib/processinfo.lua b/lib/processinfo.lua
index 35ea42f..edf5ab6 100644
--- a/lib/processinfo.lua
+++ b/lib/processinfo.lua
@@ -4,109 +4,103 @@ module(..., package.seeall)
require("posix")
require("fs")
require("format")
+require("apk")
local path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin "
function package_version(packagename)
- local result
- local errtxt = "Program not installed"
- local f = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_version -vs " .. format.escapespecialcharacters(packagename) )
- local cmdresult = f:read("*a") or ""
- f:close()
- for line in string.gmatch(cmdresult, "[^\n]+") do
- if string.match(line, "^"..format.escapemagiccharacters(packagename).."-") then
- result = string.match(line, "%S+")
- errtxt = nil
- break
- end
+ local result = apk.version(packagename)
+ local errtxt
+ if result then
+ result = packagename.."-"..result
+ else
+ errtxt = "Program not installed"
end
return result,errtxt
end
-function process_startupsequence(servicename)
+function process_autostart(servicename)
local result
local errtxt = "Not programmed to autostart"
- local f = io.popen( "/sbin/rc_status" )
+ local f = io.popen( "/sbin/rc-update show" )
local cmdresult = f:read("*a") or ""
f:close()
for line in string.gmatch(cmdresult, "[^\n]+") do
- if string.match(line, "^%a%d%d"..format.escapemagiccharacters(servicename).."$") then
- result = "Service will autostart at next boot (at sequence '" .. string.match(line,"^%a(%d%d)") .. "')"
- errtxt = nil
+ if string.match(line, "^%s*"..format.escapemagiccharacters(servicename).."%s+|") then
+ local runlevels = string.match(line, "|(.*)")
+ -- ignore the shutdown runlevel
+ runlevels = string.gsub(runlevels, "%sshutdown%s", " ")
+ runlevels = string.gsub(runlevels, "^%s+", "")
+ runlevels = string.gsub(runlevels, "%s+$", "")
+ if runlevels ~= "" then
+ result = "Service will autostart at next boot (at runlevel '" .. runlevels .. "')"
+ errtxt = nil
+ end
break
end
end
return result,errtxt
end
-function read_startupsequence()
+function read_initrunlevels()
local config = {}
- local f = io.popen( "/sbin/rc_status" )
+ local f = io.popen( "/sbin/rc-update show -v" )
local cmdresult = f:read("*a") or ""
f:close()
- local section = 0
for line in string.gmatch(cmdresult, "([^\n]*)\n?") do
- local sequence, service = string.match(line, "(%d%d)(%S+)")
+ local service, runlevels = string.match(line, "^%s*(%w+) |(.*)")
if service then
- if section == 3 then -- kill section
- for i,cfg in ipairs(config) do
- if cfg.servicename == service then
- cfg.kill = true
- break
- end
- end
- else
- config[#config+1] = {servicename=service, sequence=sequence, kill=false, system=(section == 1)}
- end
- elseif string.match(line, "^rc.%.d:") then
- section = section + 1
+ local runlevel = format.string_to_table(runlevels, "%s+") or {}
+ config[#config+1] = {servicename=service, runlevels=runlevel}
end
end
- -- Add in any missing init.d scripts
- local reverseservices = {} for i,cfg in ipairs(config) do reverseservices[cfg.servicename] = i end
- local temp = {}
- for name in posix.files("/etc/init.d") do
- if not reverseservices[name] and not string.find(name, "^rc[KLS]$") and not string.find(name, "^..?$") then
- temp[#temp+1] = {servicename=name, sequence="", kill=false, system=false}
- end
- end
- table.sort(temp, function(a,b) return a.servicename < b.servicename end)
- for i,val in ipairs(temp) do
- config[#config+1] = val
- end
+ table.sort(config, function(a,b) return a.servicename < b.servicename end)
return config
end
-function add_startupsequence(servicename, sequence, kill, system)
+function add_runlevels(servicename, runlevels)
local cmdresult,cmderrors
if not servicename then
cmderrors = "Invalid service name"
else
- local cmd = {path, "rc_add"}
- if kill then cmd[#cmd+1] = "-k" end
- if system then cmd[#cmd+1] = "-S" end
- if sequence and tonumber(sequence) then cmd[#cmd+1] = "-s "..sequence end
- cmd[#cmd+1] = format.escapespecialcharacters(servicename)
- cmd[#cmd+1] = "2>&1"
- delete_startupsequence(servicename)
- local f = io.popen(table.concat(cmd, " "))
- cmdresult = f:read("*a")
- f:close()
- if cmdresult == "" then cmdresult = "Added sequence" end
+ if runlevels and #runlevels > 0 then
+ local cmd = {path, "rc-update add"}
+ cmd[#cmd+1] = format.escapespecialcharacters(servicename)
+ for i,lev in ipairs(runlevels) do
+ cmd[#cmd+1] = lev
+ end
+ cmd[#cmd+1] = "2>&1"
+ local f = io.popen(table.concat(cmd, " "))
+ cmdresult = f:read("*a")
+ f:close()
+ cmdresult = string.gsub(cmdresult, "\n+$", "")
+ else
+ cmdresult = "No runlevels added"
+ end
end
return cmdresult,cmderrors
end
-function delete_startupsequence(servicename)
+function delete_runlevels(servicename, runlevels)
local cmdresult,cmderrors
if not servicename then
cmderrors = "Invalid service name"
else
- local f = io.popen(path.."rc_delete "..format.escapespecialcharacters(servicename))
- cmdresult = f:read("*a")
- f:close()
- if cmdresult == "" then cmderrors = "Failed to delete sequence" end
+ if runlevels and #runlevels > 0 then
+ local cmd = {path, "rc-update del"}
+ cmd[#cmd+1] = format.escapespecialcharacters(servicename)
+ for i,lev in ipairs(runlevels) do
+ cmd[#cmd+1] = lev
+ end
+ cmd[#cmd+1] = "2>&1"
+ local f = io.popen(table.concat(cmd, " "))
+ cmdresult = f:read("*a")
+ f:close()
+ cmdresult = string.gsub(cmdresult, "\n+$", "")
+ else
+ cmdresult = "No runlevels deleted"
+ end
end
return cmdresult,cmderrors