summaryrefslogtreecommitdiffstats
path: root/lbu-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-06-23 19:31:14 +0000
committerTed Trask <ttrask01@yahoo.com>2008-06-23 19:31:14 +0000
commitd296fec1d9bbdee3a212e4d0ac6e6a2cca21e70e (patch)
tree49b44dbd61f2d0d16887ee0751d1e8d5796398e1 /lbu-model.lua
parent90a75da89bf3039fe4b26276923d21b20935f60f (diff)
downloadacf-alpine-conf-d296fec1d9bbdee3a212e4d0ac6e6a2cca21e70e.tar.bz2
acf-alpine-conf-d296fec1d9bbdee3a212e4d0ac6e6a2cca21e70e.tar.xz
Added ability to manage archive of lbu backups.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@1223 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lbu-model.lua')
-rw-r--r--lbu-model.lua72
1 files changed, 71 insertions, 1 deletions
diff --git a/lbu-model.lua b/lbu-model.lua
index f5a40c0..81236eb 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -5,6 +5,7 @@ require("fs")
require("format")
require("getopts")
require("daemoncontrol")
+require("validator")
-- Set variables
local configfile = "/etc/lbu/lbu.conf"
@@ -107,6 +108,10 @@ local function validateconfig(config)
config.value.PASSWORD.errtxt = "Encryption without password is not allowed!\nDeactivate password protection or configure a password!"
end
+ if not validator.is_integer(config.value.BACKUP_LIMIT.value) then
+ config.value.BACKUP_LIMIT.errtxt = "Must be an integer"
+ end
+
for name,value in pairs(config.value) do
if value.errtxt then
config.errtxt = "Invalid Config"
@@ -163,7 +168,31 @@ local function validatefilecontent (filecontent)
return filecontent
end
-
+
+local was_mounted
+local mnt
+local function mount()
+ local configopts = getopts.getoptsfromfile(configfile, "") or {}
+ mnt = "/media/"..configopts.LBU_MEDIA
+ local f = io.popen("grep "..mnt.." /proc/mounts")
+ local cmdresult = f:read("*a")
+ f:close()
+ if cmdresult ~= "" then
+ was_mounted = true
+ else
+ local g = io.popen("mount "..mnt)
+ g:close()
+ was_mounted = false
+ end
+end
+
+local function unmount()
+ if not was_mounted then
+ local g = io.popen("umount "..mnt)
+ g:close()
+ end
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -233,6 +262,11 @@ function getconfig (configcontents)
label="Password when encrypting",
})
+ config["BACKUP_LIMIT"] = cfe({
+ value=configopts.BACKUP_LIMIT or "0",
+ label="Backup archive limit",
+ })
+
retval = cfe({ type="group", value=config, label="LBU Config" })
validateconfig(retval)
@@ -254,6 +288,7 @@ function setconfig (config)
content = replacestring(content, "#*ENCRYPTION=[^\n]*\n", newstring)
content = replacestring(content, "#*DEFAULT_CIPHER=[^\n]*\n", "DEFAULT_CIPHER="..config.value.DEFAULT_CIPHER.value.."\n")
content = replacestring(content, "#*PASSWORD=[^\n]*\n", "PASSWORD="..config.value.PASSWORD.value.."\n")
+ content = replacestring(content, "#*BACKUP_LIMIT=[^\n]*\n", "BACKUP_LIMIT="..config.value.BACKUP_LIMIT.value.."\n")
content = string.gsub(content,"\n*$","")
-- Write changes to file
@@ -352,3 +387,38 @@ function commit(input)
return input
end
+
+function getbackupfiles()
+ mount()
+ local files = {}
+ local selected
+ local f = io.popen("ls "..mnt.."/*.[0-9]*[0-9].tar.gz")
+ for line in f:lines() do
+ files[#files + 1] = line
+ end
+ f:close()
+ if #files then
+ f = io.popen("date -u -r "..mnt.."/*.apkovl.tar.gz +%Y%m%d%H%m%S")
+ selected = string.match(files[1], "^[^.]*.") .. f:read("*l") .. ".tar.gz"
+ end
+ unmount()
+ return cfe({ type="list", value=files, label="Backup archive list", selected = selected })
+end
+
+function selectbackupfile(file)
+ mount()
+ if string.find(file, "^"..mnt) and fs.is_file(file) then
+ local f = io.popen("cp -p "..file.." "..string.match(file, "^[^.]*.").."apkovl.tar.gz")
+ f:close()
+ end
+ unmount()
+end
+
+function deletebackupfile(file)
+ mount()
+ if string.find(file, "^"..mnt) and fs.is_file(file) then
+ local f = io.popen("rm "..file)
+ f:close()
+ end
+ unmount()
+end