diff options
author | dheerajpdsk <p.dheeraj.srujan.kumar@intel.com> | 2022-05-06 02:48:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-06 02:48:05 +0300 |
commit | ca8d06bc610af08c2d3efc487aa9519989b743e6 (patch) | |
tree | c557da2136640a8ce48439f19fe5f7071faffeca /meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check | |
parent | 7cf0c1cd0ce835d1833509b7b911e8a97380278b (diff) | |
parent | 18f97faa411078b95d042d207f5fff32bc8ece1d (diff) | |
download | openbmc-ca8d06bc610af08c2d3efc487aa9519989b743e6.tar.xz |
Update
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check')
-rw-r--r-- | meta-openbmc-mods/meta-common/recipes-network/network/static-mac-addr/mac-check | 27 |
1 files changed, 26 insertions, 1 deletions
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<any MAC address> (a MAC address has 12 hex digits) + bmc_mac_format="^bmc-mac[a-f0-9]{12}$" + #Match bmc-mac<current MAC address> + 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<any MAC address>, 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 |