gluon-core: add domain aliases and pretty name

This commit is contained in:
lemoer 2017-10-28 17:05:53 +02:00
parent bf3446598b
commit 88a9a974ff
4 changed files with 43 additions and 3 deletions

View File

@ -4,6 +4,17 @@ need_string_match(in_domain('domain_seed'), '^' .. ('%x'):rep(64) .. '$')
need_string(in_site('default_domain_code')) need_string(in_site('default_domain_code'))
need_string(in_domain('domain_name'))
function check_alias(k, conf_name)
assert_uci_name(k, conf_name)
local path = string.format('domain_aliases[%q]', k)
need_string(in_domain(path))
end
need_table(in_domain('domain_aliases'), check_alias, false)
if need_table('opkg', nil, false) then if need_table('opkg', nil, false) then
need_string('opkg.lede', false) need_string('opkg.lede', false)

View File

@ -29,7 +29,11 @@ local domain = (function(site)
dc = site['default_domain_code'] dc = site['default_domain_code']
end end
return read_json('/lib/gluon/domains/'..dc..'.json') local domain = read_json('/lib/gluon/domains/'..dc..'.json')
if domain['domain_aliases'] and domain['domain_aliases'][dc] then
domain['domain_name'] = domain['domain_aliases'][dc]
end
return domain
end)(site) end)(site)

View File

@ -49,7 +49,15 @@ define Build/Compile
ls $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/*.conf > /dev/null # at least one domain cfg has to exist ls $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/*.conf > /dev/null # at least one domain cfg has to exist
GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(assert(dofile("../../scripts/site_config.lua")).default_domain_code)' > $(PKG_BUILD_DIR)/default_domain_code GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(assert(dofile("../../scripts/site_config.lua")).default_domain_code)' > $(PKG_BUILD_DIR)/default_domain_code
ls '$(call qstrip,$(CONFIG_GLUON_SITEDIR))'/domains/$$$$(cat $(PKG_BUILD_DIR)/default_domain_code).conf # ensure default_domain_code exists ls '$(call qstrip,$(CONFIG_GLUON_SITEDIR))'/domains/$$$$(cat $(PKG_BUILD_DIR)/default_domain_code).conf # ensure default_domain_code exists
for domain_cfg in `find $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/ -iname \*.conf -printf "%f\n"`; do dc=$$$${domain_cfg%.conf}; GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(require("cjson").encode(assert(dofile("../../scripts/domain_config.lua")("'$$$${dc}'"))))' > $(PKG_BUILD_DIR)/domains/$$$${dc}.json; done rm -f $(PKG_BUILD_DIR)/domains/*.json
for domain_cfg in `find $(call qstrip,$(CONFIG_GLUON_SITEDIR))/domains/ -iname \*.conf -printf "%f\n"`; do \
dc=$$$${domain_cfg%.conf}; \
GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'print(require("cjson").encode(assert(dofile("../../scripts/domain_config.lua")("'$$$${dc}'"))))' > $(PKG_BUILD_DIR)/domains/$$$${dc}.json; \
aliases=$$$$(GLUON_SITEDIR='$(call qstrip,$(CONFIG_GLUON_SITEDIR))' lua -e 'for alias_name, _ in pairs(dofile("../../scripts/domain_config.lua")("'$$$${dc}'")["domain_aliases"] or {}) do print(alias_name.." ") end'); \
for alias in $$$${aliases}; do \
ln -s $$$${dc}.json $(PKG_BUILD_DIR)/domains/$$$${alias}.json; \
done; \
done
$(call GluonBuildI18N,gluon-site,$(GLUON_SITEDIR)/i18n) $(call GluonBuildI18N,gluon-site,$(GLUON_SITEDIR)/i18n)
endef endef

View File

@ -281,7 +281,6 @@ struct json_object * gluonutil_load_site_config(void) {
snprintf(domain_path, sizeof domain_path, domain_path_fmt, domain_code); snprintf(domain_path, sizeof domain_path, domain_path_fmt, domain_code);
free(domain_code);
struct json_object * domain = json_object_from_file(domain_path); struct json_object * domain = json_object_from_file(domain_path);
@ -290,6 +289,24 @@ struct json_object * gluonutil_load_site_config(void) {
return NULL; return NULL;
} }
json_object * aliases;
// it's okay to pass base == NULL to json_object_object_get_ex()
if (!json_object_object_get_ex(domain, "domain_aliases", &aliases))
goto skip_name_replacement;
json_object * aliased_domain_name;
if (!json_object_object_get_ex(aliases, domain_code, &aliased_domain_name))
goto skip_name_replacement;
// freeing of old value is done inside json_object_object_add()
json_object_object_add(domain, "domain_name", json_object_get(aliased_domain_name));
skip_name_replacement:
free(domain_code);
// finally merge them // finally merge them
return merge_json(domain, base); return merge_json(domain, base);
} }