refactor: Specify linux HOSTNAME detection

This is the first step to fix error on OpenWrt without changing current
behavior.
This commit is contained in:
macie 2025-02-08 17:16:37 +01:00
parent 4f7a333a35
commit f907c320a2
No known key found for this signature in database

19
lynis
View File

@ -514,22 +514,27 @@ ${NORMAL}
. ${INCLUDEDIR}/osdetection . ${INCLUDEDIR}/osdetection
Display --indent 2 --text "- Detecting OS... " --result "${STATUS_DONE}" --color GREEN Display --indent 2 --text "- Detecting OS... " --result "${STATUS_DONE}" --color GREEN
# Check hostname and get timestamp # Detect hostname and domain
FQDN=$(hostname 2> /dev/null)
case ${OS} in case ${OS} in
HP-UX) HP-UX)
HOSTNAME=$(hostname) ;; HOSTNAME=$(hostname) ;;
Linux)
HOSTNAME=$(hostname -s 2> /dev/null)
if [ -z "${HOSTNAME}" ]; then
HOSTNAME="${FQDN:-no-hostname}"
fi
if [ "${HOSTNAME}" = "${FQDN}" ]; then
FQDN=$(hostname -f 2> /dev/null)
fi
;;
Solaris) Solaris)
HOSTNAME=$(uname -n) ;; HOSTNAME=$(uname -n) ;;
*) *)
HOSTNAME=$(hostname -s 2> /dev/null) ;; HOSTNAME=$(hostname -s 2> /dev/null) ;;
esac esac
if [ -z "${HOSTNAME}" ]; then if [ -z "${HOSTNAME}" ]; then
HOSTNAME=$(hostname 2> /dev/null) HOSTNAME="${FQDN:-no-hostname}"
if [ -z "${HOSTNAME}" ]; then HOSTNAME="no-hostname"; fi
fi
FQDN=$(hostname 2> /dev/null)
if [ "${OS}" = "Linux" -a "${HOSTNAME}" = "${FQDN}" ]; then
FQDN=$(hostname -f 2> /dev/null)
fi fi
# #
################################################################################# #################################################################################