autoupdater: rework command line parsing, allow overriding branch

Unexpected command line arguments will now cause the updater to abort.
This commit is contained in:
Matthias Schiffer 2015-01-27 00:33:41 +01:00
parent 7fd3477263
commit 1df94acf98
1 changed files with 33 additions and 7 deletions

View File

@ -21,8 +21,7 @@ autoupdater_util.randomseed()
local settings = uci:get_all('autoupdater', 'settings') local settings = uci:get_all('autoupdater', 'settings')
local branch = uci:get_all('autoupdater', settings.branch) local branch_name = settings.branch
local old_version = util.trim(fs.readfile(settings.version_file) or '') local old_version = util.trim(fs.readfile(settings.version_file) or '')
@ -36,15 +35,42 @@ local force = false
local fallback = false local fallback = false
for _, a in ipairs(arg) do local function parse_args()
if a == '-f' then local i = 1
force = true while arg[i] do
elseif a == '--fallback' then if arg[i] == '-f' then
fallback = true force = true
elseif arg[i] == '--fallback' then
fallback = true
elseif arg[i] == '-b' then
i = i+1
if not arg[i] then
io.stderr:write("Error parsing command line: expected branch name\n")
os.exit(1)
end
branch_name = arg[i]
else
io.stderr:write("Error parsing command line: unexpected argument '" .. arg[i] .. "'\n")
os.exit(1)
end
i = i+1
end end
end end
parse_args()
local branch = uci:get_all('autoupdater', branch_name)
if not branch then
io.stderr:write("Can't find configuration for branch '" .. branch_name .. "'\n")
os.exit(1)
end
if settings.enabled ~= '1' and not force then if settings.enabled ~= '1' and not force then
io.stderr:write('autoupdater is disabled.\n') io.stderr:write('autoupdater is disabled.\n')
os.exit(0) os.exit(0)