Skip to content

Commit

Permalink
fix some bugs in the pattern matching and field extraction routines in
Browse files Browse the repository at this point in the history
S42LoadNetFiles which could result in the wrong group file being used.
  • Loading branch information
jens-maus committed Aug 5, 2024
1 parent d263419 commit f143f35
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions buildroot-external/rootfs-overlay/etc/init.d/S42LoadNetFiles
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f143f35

Please sign in to comment.