#!/usr/bin/env bash

# Retrieves mac address of various interfaces in the compute stack including
# BMC node. This script needs to be run from main-ai to get all the required
# metadata

# IPMICFG-Linux is a linux tool from super micro to which can be used to
# retrieve BMC node. This binary was uploaded to s3 to make this script simple
# The url to download is https://www.supermicro.com/solutions/SMS_IPMI.cfm
IPMICFG_BINARY_URL="https://s3-us-west-1.amazonaws.com/zoox-third-party/bd7a3053340f92c05e61422f5b9ff2dcd322ced22ebe5f90f1b41bc0f0d8a7fa/IPMICFG-Linux"
IPMICFG_BINARY_PATH="/tmp/IPMICFG-Linux"

# On main-ai
wget --quiet "${IPMICFG_BINARY_URL}" --output-document=${IPMICFG_BINARY_PATH}
chmod a+x ${IPMICFG_BINARY_PATH}

echo "############################ main-ai ###################################"

echo "############################ BMC info ##################################"
sudo ${IPMICFG_BINARY_PATH} -m

echo "############################ host info #################################"
ip a

# on vision machines
for i in {1..6}; do
    echo "############################ vision$i ###################################"

    echo "############################ BMC info ##################################"
    ssh vision${i} "wget --quiet \"${IPMICFG_BINARY_URL}\" --output-document=${IPMICFG_BINARY_PATH}; chmod a+x ${IPMICFG_BINARY_PATH}; sudo ${IPMICFG_BINARY_PATH} -m"

    echo "############################ host info #################################"
    ssh vision${i} "ip a"
done

