Skip to content

Commit

Permalink
fix(NODE-1465): Update fetch-mgmt-mac (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbattat authored Sep 10, 2024
1 parent db67ca3 commit dfb1c63
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions ic-os/components/hostos-scripts/misc/fetch-mgmt-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ source /opt/ic/bin/logging.sh
source /opt/ic/bin/metrics.sh

SCRIPT="$(basename $0)[$$]"
CONFIG="/boot/config/config.ini"
DEPLOYMENT="${DEPLOYMENT:=/boot/config/deployment.json}"

# Get keyword arguments
for argument in "${@}"; do
Expand All @@ -30,16 +30,6 @@ Arguments:
esac
done

function read_variables() {
# Read limited set of keys. Be extra-careful quoting values as it could
# otherwise lead to executing arbitrary shell code!
while IFS="=" read -r key value; do
case "$key" in
"mgmt_mac") mgmt_mac="${value}" ;;
esac
done <"${CONFIG}"
}

# Fetch the management MAC address of the physical machine.
# The management MAC address will be used as unique key for:
# - Hostnames
Expand Down Expand Up @@ -67,12 +57,15 @@ function fetch_mgmt_mac() {

function main() {
# Establish run order
mgmt_mac=""
read_variables
if [ "${mgmt_mac}" == "" ]; then

# NOTE: `fetch-property` will error if the target is not found. Here we
# only want to act when the field is set.
MGMT_MAC=$(jq -r ".deployment.mgmt_mac" ${DEPLOYMENT})

if [ -z "${MGMT_MAC}" ] || [ "${MGMT_MAC}" = "null" ]; then
fetch_mgmt_mac
else
echo "${mgmt_mac}"
echo "${MGMT_MAC}"
fi
}

Expand Down

0 comments on commit dfb1c63

Please sign in to comment.