getter handling with own domain

This commit is contained in:
Martin Berghaus
2025-02-22 23:11:10 +01:00
parent da4aedb0b6
commit 5cdc7524e2
3 changed files with 32 additions and 4 deletions

4
.gitignore vendored
View File

@@ -1,5 +1,5 @@
# Ignore the file '/domainOfHostOwner' because this is per host individually. # Ignore the file '/overrideOwnDomain' because this is per host individually.
/domainOfHostOwner /overrideOwnDomain
# Ignore the subfolders only, because their content are other git repositories. # Ignore the subfolders only, because their content are other git repositories.
# But 'definitions and 'states' should be prepared by cloning this repository. # But 'definitions and 'states' should be prepared by cloning this repository.

28
core/printOwnDomain.sh Normal file
View File

@@ -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

View File

@@ -39,7 +39,7 @@ function checkPreconditions() {
! [ -z "${_DOMAIN}" ] \ ! [ -z "${_DOMAIN}" ] \
&& [ "$(hostname -d)" != "${_DOMAIN}" ] \ && [ "$(hostname -d)" != "${_DOMAIN}" ] \
&& echo \ && echo \
&& echo "WARNING: system-domain DOES NOT MATCH domainOfHostOwner: '$(hostname -d)' != '${_DOMAIN}'" \ && echo "WARNING: system-domain DOES NOT MATCH overrideOwnDomain: '$(hostname -d)' != '${_DOMAIN}'" \
&& echo && echo
# Given domain verfügbar (nicht leer) # Given domain verfügbar (nicht leer)
@@ -71,7 +71,7 @@ function checkPreconditions() {
function getOrSetDomain() { function getOrSetDomain() {
local _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN local _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN
_CIS_ROOT="${1:?"Missing parameter CIS_ROOT"}" _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 _GIVEN_DOMAIN="${2}" # Optional parameter DOMAIN
readonly _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN readonly _CIS_ROOT _DOMAIN_FILE _GIVEN_DOMAIN