Skip to content
Snippets Groups Projects
Unverified Commit 1a7d93a2 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

scripts/check_site.lua: add support for alternative checks

parent 91912f49
No related branches found
No related tags found
No related merge requests found
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() ...@@ -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) ...@@ -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 ...@@ -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) ...@@ -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()) ...@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment