From 2dc2dca73ef4639f495390ea97ade6a201b5e68c Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Fri, 22 Mar 2019 20:15:25 +0100
Subject: [PATCH] gluon-site: add better error message for domain name
 conflicts

When two domains alias the same name (or one aliases another), display a
meaningful error message like:

    Failed to alias domain 'foo' as 'bar', name already taken by
    domain 'baz'.

(cherry picked from commit c208fc4fd9c94b765413795dfc1f995a0139e5c8)
---
 package/gluon-site/Makefile | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/package/gluon-site/Makefile b/package/gluon-site/Makefile
index 914522647..dd4432bc4 100644
--- a/package/gluon-site/Makefile
+++ b/package/gluon-site/Makefile
@@ -49,9 +49,16 @@ define Build/Compile
 	$(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 \
+		@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; \
+			link="$(PKG_BUILD_DIR)/domains/$$$${alias}.json"; \
+			if ! ln -s '$(domain).json' "$$$$link"; then \
+				other="$$$$(basename $$$$(readlink -f "$$$$link") .json)"; \
+				if [ "$$$$other" ]; then \
+					echo >&2 "Failed to alias domain '"'$(domain)'"' as '$$$$alias', name already taken by domain '$$$$other'."; \
+				fi; \
+				exit 1; \
+			fi; \
 		done
 	)
   endif
-- 
GitLab