From 18f97faa411078b95d042d207f5fff32bc8ece1d Mon Sep 17 00:00:00 2001 From: P Dheeraj Srujan Kumar Date: Thu, 31 Mar 2022 02:50:48 +0530 Subject: Update to internal 1-0.91 Signed-off-by: P Dheeraj Srujan Kumar --- .../network/static-mac-addr/mac-check | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check') diff --git a/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check index 39d7dd8a7..429f9264b 100644 --- a/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check +++ b/meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright 2018 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -158,4 +158,29 @@ done <<-END_CONF eth0 eth1addr eth1 ethaddr END_CONF + +### HOSTNAME FEATURE ### +if [[ $* == *--no-unique-hostname* ]]; then + echo "mac-check: Skipping hostname check" +else + # Read MAC and strip colon chars + hw_mac=$(cat /sys/class/net/eth0/address | tr -d ":") + # Read Hostname + hostname=$(hostname) + #Match bmc-mac (a MAC address has 12 hex digits) + bmc_mac_format="^bmc-mac[a-f0-9]{12}$" + #Match bmc-mac + inteldefault="bmc-mac$hw_mac" + #if the current hostname already has the current MAC address, we won't rewrite the name unnecessarily. + #Otherwise, match intel-obmc or bmc-mac, and change the hostname to use the current MAC address + if [[ "$hostname" == "intel-obmc" || \ + ("$hostname" != "$inteldefault" && \ + "$hostname" =~ $bmc_mac_format) ]]; then + hostnamectl set-hostname "$inteldefault" + echo "mac-check: HOSTNAME CHANGED (hostname deemed to be default or wrong MAC Address)" + else + echo "mac-check: HOSTNAME NOT CHANGED (hostname is already correct or is custom)" + fi +fi + exit $first_error_seen -- cgit v1.2.3