From f143f3573df02ce8ff7d227683842606dc7fe3ea Mon Sep 17 00:00:00 2001 From: Jens Maus Date: Mon, 5 Aug 2024 09:51:12 +0200 Subject: [PATCH] fix some bugs in the pattern matching and field extraction routines in S42LoadNetFiles which could result in the wrong group file being used. --- .../rootfs-overlay/etc/init.d/S42LoadNetFiles | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildroot-external/rootfs-overlay/etc/init.d/S42LoadNetFiles b/buildroot-external/rootfs-overlay/etc/init.d/S42LoadNetFiles index 3f7e8a0..acdb966 100755 --- a/buildroot-external/rootfs-overlay/etc/init.d/S42LoadNetFiles +++ b/buildroot-external/rootfs-overlay/etc/init.d/S42LoadNetFiles @@ -70,7 +70,7 @@ load_thinroot_hosts() { # put all additional groups matching the hostname # to the host variable - FOUND_GRP=$(grep -m1 -e ^"${HOSTNAME}" "${TMPDIR}/thinroot.hosts" | cut -d" " -f "2-") + FOUND_GRP=$(grep -m1 -i -e "^${HOSTNAME} " "${TMPDIR}/thinroot.hosts" | awk '{for(i=3;i<=NF;i++) {printf $i " "}}') if [[ -n "${FOUND_GRP}" ]]; then for grp in ${FOUND_GRP}; do # a comment lets us break out here @@ -83,7 +83,7 @@ load_thinroot_hosts() { done fi MAC_ADDR=$(cat "/sys/class/net/$(ip route show default | awk '/default/ {print $5}')/address") - FOUND_GRP=$(grep -m1 -i "${MAC_ADDR}" "${TMPDIR}/thinroot.hosts" | cut -d" " -f "2-") + FOUND_GRP=$(grep -m1 -i " ${MAC_ADDR}" "${TMPDIR}/thinroot.hosts" | awk '{for(i=3;i<=NF;i++) {printf $i " "}}') if [[ -n "${FOUND_GRP}" ]]; then for grp in ${FOUND_GRP}; do # a comment lets us break out here @@ -96,7 +96,7 @@ load_thinroot_hosts() { done if [[ "${HOSTNAME}" == "localhost" ]]; then - NEW_HOSTNAME=$(grep -m1 -i "${MAC_ADDR}" "${TMPDIR}/thinroot.hosts" | cut -f1) + NEW_HOSTNAME=$(grep -m1 -i " ${MAC_ADDR}" "${TMPDIR}/thinroot.hosts" | cut -d" " -f1) if [[ -n "${NEW_HOSTNAME}" && "${NEW_HOSTNAME}" != "-" ]]; then /bin/hostname "${NEW_HOSTNAME}" HOSTNAME=$(/bin/hostname)