Alexander Filippov | 126f667 | 2018-11-28 11:32:04 +0300 | [diff] [blame] | 1 | #!/bin/sh -eu |
| 2 | |
| 3 | show_error() { |
Alexander Filippov | c2102a4 | 2019-06-10 18:44:59 +0300 | [diff] [blame^] | 4 | if [ -n "${JOURNAL_STREAM-}" ]; then |
| 5 | echo "$@" | systemd-cat -t first-boot-set-mac -p emerg |
| 6 | else |
| 7 | echo "$@" >&2 |
| 8 | fi |
Alexander Filippov | 126f667 | 2018-11-28 11:32:04 +0300 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | sync_mac() { |
| 12 | |
| 13 | MAPPER_IFACE='xyz.openbmc_project.ObjectMapper' |
| 14 | MAPPER_PATH='/xyz/openbmc_project/object_mapper' |
| 15 | INVENTORY_PATH='/xyz/openbmc_project/inventory' |
| 16 | NETWORK_ITEM_IFACE='xyz.openbmc_project.Inventory.Item.NetworkInterface' |
| 17 | |
| 18 | NETWORK_ITEM_PATH=$(busctl --no-pager --verbose call \ |
| 19 | ${MAPPER_IFACE} \ |
| 20 | ${MAPPER_PATH} \ |
| 21 | ${MAPPER_IFACE} \ |
| 22 | GetSubTree sias \ |
| 23 | ${INVENTORY_PATH} 0 1 ${NETWORK_ITEM_IFACE} \ |
| 24 | 2>/dev/null | grep ${INVENTORY_PATH} || true) |
| 25 | |
| 26 | # ' STRING "/xyz/openbmc_project/inventory/system/chassis/ethernet";' |
| 27 | NETWORK_ITEM_PATH=${NETWORK_ITEM_PATH#*\"} |
| 28 | NETWORK_ITEM_PATH=${NETWORK_ITEM_PATH%\"*} |
| 29 | |
| 30 | NETWORK_ITEM_SERVICE=$(mapper get-service \ |
| 31 | ${NETWORK_ITEM_PATH} 2>/dev/null || true) |
| 32 | |
| 33 | if [[ -z "${NETWORK_ITEM_SERVICE}" ]]; then |
| 34 | show_error 'No Ethernet interface found in the Inventory. Is VPD EEPROM empty?' |
| 35 | return |
| 36 | fi |
| 37 | |
| 38 | MAC_ADDR=$(busctl get-property ${NETWORK_ITEM_SERVICE} \ |
| 39 | ${NETWORK_ITEM_PATH} \ |
| 40 | ${NETWORK_ITEM_IFACE} MACAddress) |
| 41 | |
| 42 | # 's "54:52:01:02:03:04"' |
| 43 | MAC_ADDR=${MAC_ADDR#*\"} |
| 44 | MAC_ADDR=${MAC_ADDR%\"*} |
| 45 | |
| 46 | if [[ -n "${MAC_ADDR}" ]]; then |
| 47 | busctl set-property xyz.openbmc_project.Network \ |
| 48 | /xyz/openbmc_project/network/$1 \ |
| 49 | xyz.openbmc_project.Network.MACAddress \ |
| 50 | MACAddress s ${MAC_ADDR} |
| 51 | fi |
| 52 | } |
| 53 | |
Alexander Filippov | c2102a4 | 2019-06-10 18:44:59 +0300 | [diff] [blame^] | 54 | if [ $# -eq 0 ]; then |
| 55 | show_error 'No Ethernet interface name is given' |
Alexander Filippov | 126f667 | 2018-11-28 11:32:04 +0300 | [diff] [blame] | 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | sync_mac $1 |
| 60 | |
| 61 | systemctl disable first-boot-set-mac@${1}.service |