fix: Detect HOSTNAME on OpenWrt

OpenWrt can be run on devices with little resource, so it can miss some BusyBox
commands (eg. hostname). The standard way of gathering info about OpenWrt is by
the `uci` command, see: <https://openwrt.org/docs/guide-user/base-system/uci>.
This commit is contained in:
macie 2025-02-08 16:32:38 +01:00
parent f907c320a2
commit b8f5b41b98
No known key found for this signature in database
1 changed files with 11 additions and 6 deletions

5
lynis
View File

@ -520,6 +520,10 @@ ${NORMAL}
HP-UX)
HOSTNAME=$(hostname) ;;
Linux)
if [ "${LINUX_VERSION}" = "OpenWrt" ]; then
HOSTNAME=$(uname -n)
FQDN="${HOSTNAME:+$HOSTNAME.}$(uci -q get dhcp.@dnsmasq[0].domain)"
else
HOSTNAME=$(hostname -s 2> /dev/null)
if [ -z "${HOSTNAME}" ]; then
HOSTNAME="${FQDN:-no-hostname}"
@ -527,6 +531,7 @@ ${NORMAL}
if [ "${HOSTNAME}" = "${FQDN}" ]; then
FQDN=$(hostname -f 2> /dev/null)
fi
fi
;;
Solaris)
HOSTNAME=$(uname -n) ;;