blob: 9668ed5f130f13677f4e8ed4ffe5f57d98330af6 [file] [log] [blame]
Alexander Filippov126f6672018-11-28 11:32:04 +03001#!/bin/sh -eu
2
3show_error() {
Alexander Filippovc2102a42019-06-10 18:44:59 +03004 if [ -n "${JOURNAL_STREAM-}" ]; then
5 echo "$@" | systemd-cat -t first-boot-set-mac -p emerg
6 else
7 echo "$@" >&2
8 fi
Alexander Filippov126f6672018-11-28 11:32:04 +03009}
10
11sync_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 Filippovc2102a42019-06-10 18:44:59 +030054if [ $# -eq 0 ]; then
55 show_error 'No Ethernet interface name is given'
Alexander Filippov126f6672018-11-28 11:32:04 +030056 exit 1
57fi
58
59sync_mac $1
60
61systemctl disable first-boot-set-mac@${1}.service