scripts/check_site.lua: add support for alternative checks
This commit is contained in:
parent
91912f4935
commit
1a7d93a2b9
@ -1,8 +1,7 @@
|
|||||||
local cjson = require 'cjson'
|
local cjson = require 'cjson'
|
||||||
|
|
||||||
local function exit_error(src, ...)
|
local function config_error(src, ...)
|
||||||
io.stderr:write(string.format('*** %s error: %s\n', src, string.format(...)))
|
error(src .. ' error: ' .. string.format(...), 0)
|
||||||
os.exit(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ local function get_domains()
|
|||||||
dirs:close()
|
dirs:close()
|
||||||
|
|
||||||
if not next(domains) then
|
if not next(domains) then
|
||||||
exit_error('site', 'no domain configurations found')
|
config_error('site', 'no domain configurations found')
|
||||||
end
|
end
|
||||||
|
|
||||||
return domains
|
return domains
|
||||||
@ -101,13 +100,13 @@ local function var_error(path, val, msg)
|
|||||||
src = site_src()
|
src = site_src()
|
||||||
end
|
end
|
||||||
|
|
||||||
exit_error(src, 'expected %s to %s, but it is %s', path_to_string(path), msg, tostring(val))
|
config_error(src, 'expected %s to %s, but it is %s', path_to_string(path), msg, tostring(val))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function in_site(path)
|
function in_site(path)
|
||||||
if has_domains and loadpath(nil, domain, unpack(path)) ~= nil then
|
if has_domains and loadpath(nil, domain, unpack(path)) ~= nil then
|
||||||
exit_error(domain_src(), '%s is allowed in site configuration only', path_to_string(path))
|
config_error(domain_src(), '%s is allowed in site configuration only', path_to_string(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
return path
|
return path
|
||||||
@ -115,7 +114,7 @@ end
|
|||||||
|
|
||||||
function in_domain(path)
|
function in_domain(path)
|
||||||
if has_domains and loadpath(nil, site, unpack(path)) ~= nil then
|
if has_domains and loadpath(nil, site, unpack(path)) ~= nil then
|
||||||
exit_error(site_src(), '%s is allowed in domain configuration only', path_to_string(path))
|
config_error(site_src(), '%s is allowed in domain configuration only', path_to_string(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
return path
|
return path
|
||||||
@ -174,6 +173,21 @@ local function check_one_of(array)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function alternatives(...)
|
||||||
|
local errs = {'All of the following alternatives have failed:'}
|
||||||
|
for i, f in ipairs({...}) do
|
||||||
|
local ok, err = pcall(f)
|
||||||
|
if ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
errs[#errs+1] = string.format('%i) %s', i, err)
|
||||||
|
end
|
||||||
|
|
||||||
|
error(table.concat(errs, '\n '), 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function need(path, check, required, msg)
|
function need(path, check, required, msg)
|
||||||
local val = loadvar(path)
|
local val = loadvar(path)
|
||||||
if required == false and val == nil then
|
if required == false and val == nil then
|
||||||
@ -283,14 +297,21 @@ local check = assert(loadfile())
|
|||||||
|
|
||||||
site = load_json(os.getenv('IPKG_INSTROOT') .. '/lib/gluon/site.json')
|
site = load_json(os.getenv('IPKG_INSTROOT') .. '/lib/gluon/site.json')
|
||||||
|
|
||||||
if has_domains then
|
local ok, err = pcall(function()
|
||||||
for k, v in pairs(get_domains()) do
|
if has_domains then
|
||||||
domain_code = k
|
for k, v in pairs(get_domains()) do
|
||||||
domain = v
|
domain_code = k
|
||||||
conf = merge(site, domain)
|
domain = v
|
||||||
|
conf = merge(site, domain)
|
||||||
|
check()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
conf = site
|
||||||
check()
|
check()
|
||||||
end
|
end
|
||||||
else
|
end)
|
||||||
conf = site
|
|
||||||
check()
|
if not ok then
|
||||||
|
io.stderr:write('*** ', err, '\n')
|
||||||
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user