summaryrefslogtreecommitdiffstats
path: root/lbu-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-22 14:34:18 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-22 14:34:18 +0000
commit3928babbc55caa5c8b3914fa0a4c26a916c0dbbb (patch)
tree68a15a0f87652886fbc504ceafd6c4ee728bea45 /lbu-model.lua
parent7cf8d1ac44d78983252fc0279b955463c6dd68e6 (diff)
downloadacf-alpine-conf-3928babbc55caa5c8b3914fa0a4c26a916c0dbbb.tar.bz2
acf-alpine-conf-3928babbc55caa5c8b3914fa0a4c26a916c0dbbb.tar.xz
Now you can modify the configurations.
Committing and SimulatingCommit also works (still work in progress) Needs checks when creating encrypted archives. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@626 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lbu-model.lua')
-rw-r--r--lbu-model.lua63
1 files changed, 50 insertions, 13 deletions
diff --git a/lbu-model.lua b/lbu-model.lua
index c3d20c4..e239496 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -1,6 +1,7 @@
module (..., package.seeall)
require("fs")
+require("format")
require("getopts")
local configfile = "/etc/lbu/lbu.conf"
@@ -17,7 +18,7 @@ end
local function getLbuStatus()
local ret = {}
- local f = io.popen("/sbin/lbu status -v", "r")
+ local f = io.popen("/sbin/lbu status -v 2>&1", "r")
if not (f) then return ret end
for line in f:lines() do
if (string.match(line, "^Include files")) then break end
@@ -31,6 +32,13 @@ local function getLbuStatus()
return ret
end
+local function getLbuCommit(flag)
+ local f = io.popen("/sbin/lbu commit " .. flag .. " 2>&1", "r")
+ local ret = f:read("*a")
+ f:close()
+ return ret
+end
+
local function getciphers()
local opensslciphers = {}
local watchdog = nil
@@ -61,6 +69,14 @@ local function getincexl(state)
return incexl
end
+local function checkexistens(file,variable)
+ local filecontent = fs.read_file_as_array(file)
+ for k,v in ipairs(filecontent) do
+ return v
+ end
+ return nil
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -93,6 +109,13 @@ function list(self)
return ret
end
+function getcommit()
+ return getLbuCommit("-v")
+end
+function getsimulate()
+ return getLbuCommit("-n")
+end
+
function getconfig ()
local path = configfile
local config = {}
@@ -111,7 +134,6 @@ end
function lbuincexcl(self,state,value,addremove)
local incexl = nil
--- local addremove
if (string.lower(addremove or "") == "add") then
addremove = ""
elseif (string.lower(addremove or "") == "remove") then
@@ -129,15 +151,30 @@ function lbuincexcl(self,state,value,addremove)
end
return incexl
end
--- ################################################################################
--- OLD FUNCTIONS
-
---[[
-function commit(self)
- local f = io.popen("/sbin/lbu commit", 'r')
- if not f then return false, "cannot run lbu" end
- local ret = f:read("*a")
- f:close()
- return true, ret
+
+function editconfig (self,variable,value,state)
+ local configfilecontent = nil
+ local path = configfile
+ local cmdoutput = {}
+ if (state == "change_value" ) then
+ configfilecontent = fs.read_file_as_array(configfile)
+ if not (value) or (value == "") then
+ cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, "#" .. variable)
+ else
+ cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable .. ".*$", variable .. "=" .. value)
+ end
+ fs.write_file(configfile,table.concat(cmdoutput,"\n"))
+ elseif (state == "change_state" ) then
+ configfilecontent = fs.read_file_as_array(configfile)
+ if not (value) or (value == "") then
+ cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, "#" .. variable)
+ else
+ cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, variable)
+ end
+ fs.write_file(configfile,table.concat(cmdoutput,"\n"))
+ else
+ return "Function ediconfig() - Wrong usage of this function! usage editconfig(variable,value,state)\nvariable=Name of the variable\nvalue=The new value (when adding)\nstate=change_value|change_state depending on if you want to add some value or remove some variable."
+ end
+ return cmdoutput
end
---]]
+