much better

This commit is contained in:
Martin Berghaus
2025-02-23 00:07:07 +01:00
parent 5cdc7524e2
commit c71ce67a5a

View File

@@ -11,18 +11,21 @@ _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
_BOOT_DOMAIN="$(hostname -b | grep -F '.' | cut -d. -f2-)"
#Removes shortest matching pattern '*.' from the begin to get the domain
echo "${_BOOT_HOSTNAME#*.}" \
# Take OVERRIDING_DOMAIN_FILE without empty lines and comments, then take the first line without leading spaces
_OVERRIDE_DOMAIN="$(grep -vE '^[[:space:]]*$|^[[:space:]]*#' "${_OVERRIDE_DOMAIN_FILE}" 2> /dev/null | head -n 1 | xargs)"
! [ -z "${_OVERRIDE_DOMAIN}" ] \
&& [ "${_OVERRIDE_DOMAIN}" != "${_BOOT_DOMAIN}" ] \
&& echo "WARNING: Domain has been overridden by: ${_OVERRIDE_DOMAIN_FILE}" > /dev/stderr \
&& echo "${_OVERRIDE_DOMAIN}" \
&& exit 0
! [ -z "${_BOOT_DOMAIN}" ] \
&& echo "${_BOOT_DOMAIN}" \
&& exit 0
echo "It was impossible to find out the domain of this host, please prepare this host first." > /dev/stderr
exit 1