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