From 5cdc7524e216a527ef10f71d1ba24afec524db8b Mon Sep 17 00:00:00 2001 From: Martin Berghaus Date: Sat, 22 Feb 2025 23:11:10 +0100 Subject: [PATCH] getter handling with own domain --- .gitignore | 4 ++-- core/printOwnDomain.sh | 28 ++++++++++++++++++++++++++++ setupCoreOntoThisHost.sh | 4 ++-- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 core/printOwnDomain.sh diff --git a/.gitignore b/.gitignore index 34a2b94..ff1f297 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# Ignore the file '/domainOfHostOwner' because this is per host individually. -/domainOfHostOwner +# Ignore the file '/overrideOwnDomain' because this is per host individually. +/overrideOwnDomain # Ignore the subfolders only, because their content are other git repositories. # But 'definitions and 'states' should be prepared by cloning this repository. diff --git a/core/printOwnDomain.sh b/core/printOwnDomain.sh new file mode 100644 index 0000000..5d619ef --- /dev/null +++ b/core/printOwnDomain.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +#WARNING: Used for core functionality in setup.sh +# DO NOT rename the script and test changes well! + + + +# Folders always ends with an tailing '/' +_SCRIPT="$(readlink -f "${0}" 2> /dev/null)" +_CORE_SCRIPTS="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/" +_CIS_ROOT="$(dirname ${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"} 2> /dev/null)/" +_OVERRIDE_DOMAIN_FILE="${_CIS_ROOT:?"Missing CIS_ROOT"}overrideOwnDomain" + +# Wenn OVERRIDING_DOMAIN_FILE enhält lesbare Daten +grep '[^[:space:]]' "${_OVERRIDE_DOMAIN_FILE:?"Missing OVERRIDE_DOMAIN_FILE"}" &> /dev/null \ + && echo "WARNING: Domain has been overridden by: ${_OVERRIDE_DOMAIN_FILE}" > /dev/stderr \ + && cat "${_OVERRIDE_DOMAIN_FILE}" \ + && exit 0 + +_BOOT_HOSTNAME="$(hostname -b)" +# There has to be one dot at least. +echo "${_BOOT_HOSTNAME}" | grep -v '\.' &> /dev/null \ + && echo "It was impossible to find out the domain of this host, please prepare this host first." > /dev/stderr \ + && exit 1 + +#Removes shortest matching pattern '*.' from the begin to get the domain +echo "${_BOOT_HOSTNAME#*.}" \ + && exit 0 diff --git a/setupCoreOntoThisHost.sh b/setupCoreOntoThisHost.sh index b0b9876..78bc6b3 100755 --- a/setupCoreOntoThisHost.sh +++ b/setupCoreOntoThisHost.sh @@ -39,7 +39,7 @@ function checkPreconditions() { ! [ -z "${_DOMAIN}" ] \ && [ "$(hostname -d)" != "${_DOMAIN}" ] \ && echo \ - && echo "WARNING: system-domain DOES NOT MATCH domainOfHostOwner: '$(hostname -d)' != '${_DOMAIN}'" \ + && echo "WARNING: system-domain DOES NOT MATCH overrideOwnDomain: '$(hostname -d)' != '${_DOMAIN}'" \ && echo # Given domain verfügbar (nicht leer) @@ -71,7 +71,7 @@ function checkPreconditions() { function getOrSetDomain() { local _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN _CIS_ROOT="${1:?"Missing parameter CIS_ROOT"}" - _DOMAIN_FILE="${_CIS_ROOT:?"Missing CIS_ROOT"}domainOfHostOwner" + _DOMAIN_FILE="${_CIS_ROOT:?"Missing CIS_ROOT"}overrideOwnDomain" _GIVEN_DOMAIN="${2}" # Optional parameter DOMAIN readonly _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN