From 6ae067cb379436bc915b2a5e6865106e9fb24c29 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer <mschiffer@universe-factory.net> Date: Sat, 20 Jan 2018 06:22:26 +0100 Subject: [PATCH] gluon-core: add domain aliases and pretty name Based-on-patch-by: lemoer <git@irrelefant.net> --- package/gluon-core/check_site.lua | 6 ++++++ package/gluon-site/Makefile | 6 ++++++ scripts/domain_aliases.lua | 13 +++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 scripts/domain_aliases.lua diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua index 2ae05427e..99cdedac5 100644 --- a/package/gluon-core/check_site.lua +++ b/package/gluon-core/check_site.lua @@ -13,6 +13,12 @@ if this_domain() then end, nil, 'be a valid domain name') end need_domain_name(in_site({'default_domain'})) + + need_table(in_domain({'domain_names'}), function(domain) + need_alphanumeric_key(domain) + need_string(domain) + end) + need_string(in_domain({'domain_names', this_domain()})) end need_string_match(in_domain({'domain_seed'}), '^' .. ('%x'):rep(64) .. '$') diff --git a/package/gluon-site/Makefile b/package/gluon-site/Makefile index 9c2494859..f930888c1 100644 --- a/package/gluon-site/Makefile +++ b/package/gluon-site/Makefile @@ -53,9 +53,15 @@ define Build/Compile $(call GenerateJSON,site) ifdef CONFIG_GLUON_MULTIDOMAIN + rm -rf $(PKG_BUILD_DIR)/domains mkdir -p $(PKG_BUILD_DIR)/domains $(foreach domain,$(patsubst $(GLUON_SITEDIR)/domains/%.conf,%,$(wildcard $(GLUON_SITEDIR)/domains/*.conf)), + [ ! -e '$(PKG_BUILD_DIR)/domains/$(domain).json' ] $(call GenerateJSON,domains/$(domain)) + lua ../../scripts/domain_aliases.lua '$(PKG_BUILD_DIR)/domains/$(domain).json' | while read alias; do \ + [ "$$$${alias}" != '$(domain)' ] || continue; \ + ln -s '$(domain).json' $(PKG_BUILD_DIR)/domains/$$$${alias}.json || exit 1; \ + done ) endif diff --git a/scripts/domain_aliases.lua b/scripts/domain_aliases.lua new file mode 100644 index 000000000..ea7fbf3a3 --- /dev/null +++ b/scripts/domain_aliases.lua @@ -0,0 +1,13 @@ +local cjson = require 'cjson' + +local function load_json(filename) + local f = assert(io.open(filename)) + local json = cjson.decode(f:read('*a')) + f:close() + return json +end + +local domain = load_json(arg[1]) +for k, _ in pairs(domain.domain_names) do + print(k) +end -- GitLab