blob: 5415237606581da22388611397322b6276651aa6 [file] [log] [blame]
Alexander Filippov55281df2019-05-22 11:07:30 +03001#!/bin/sh -eu
2
3show_error() {
4 echo "$@" >&2
5}
6
7sync_hostname() {
8 MAPPER_IFACE='xyz.openbmc_project.ObjectMapper'
9 MAPPER_PATH='/xyz/openbmc_project/object_mapper'
10 INVENTORY_PATH='/xyz/openbmc_project/inventory'
11 BMC_ITEM_IFACE='xyz.openbmc_project.Inventory.Item.Bmc'
12
13 BMC_ITEM_PATH=$(busctl --no-pager --verbose call \
14 ${MAPPER_IFACE} \
15 ${MAPPER_PATH} \
16 ${MAPPER_IFACE} \
17 GetSubTree sias \
18 ${INVENTORY_PATH} 0 1 ${BMC_ITEM_IFACE} \
19 2>/dev/null | grep ${INVENTORY_PATH} || true)
20
21 # ' STRING "/xyz/openbmc_project/inventory/system/chassis/bmc";'
22 BMC_ITEM_PATH=${BMC_ITEM_PATH#*\"}
23 BMC_ITEM_PATH=${BMC_ITEM_PATH%\"*}
24
25 BMC_ITEM_SERVICE=$(mapper get-service \
26 ${BMC_ITEM_PATH} 2>/dev/null || true)
27
28 if [[ -z "${BMC_ITEM_SERVICE}" ]]; then
29 echo "No BMC item found in the Inventory. Is VPD EEPROM empty?" >&2
30 return
31 fi
32
33 BMC_SN=$(busctl get-property ${BMC_ITEM_SERVICE} \
34 ${BMC_ITEM_PATH} \
35 ${BMC_ITEM_IFACE} SerialNumber)
36 # 's "002B0DH1000"'
37 BMC_SN=${BMC_SN#*\"}
38 BMC_SN=${BMC_SN%\"*}
39
40 hostnamectl set-hostname {MACHINE}-${BMC_SN}
41}
42
43[ "$(hostname)" = "{MACHINE}" ] && sync_hostname
44
45systemctl disable first-boot-set-hostname.service
46