1#!/bin/bash
2# Copyright 2022 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15set -eo pipefail
16
17HOSTNAME="$(hostname)"
18USER="${1?Missing first param: USER (Usually passed by agetty via \\u)}"
19
20if [[ "$HOSTNAME" =~ ^([^-.]+)[^.]*(.*[.]corp[.]google[.]com)$ ]]; then
21  # for google corp address the suffix must be removed from the name
22  HOSTNAME="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
23fi
24
25if [[ "${HOSTNAME}" == *"@HOSTNAME_SUFFIX@" ]];  then
26  # Valid hostname is already set, invoke normal glome
27  exec /usr/sbin/glome-login -M "${HOSTNAME}" "${USER}"
28fi
29
30# Get the board serial number from the FRU EEPROM
31# Service passed in as a parameter would be either inventory-manager or
32# entity-manager depending on platforms
33# Path to the FRU EEPROM object has to be passed in as a parameter
34# If the target platform has neither of them, the fallback mechanism is useless
35INT="xyz.openbmc_project.Inventory.Decorator.Asset"
36PART="SerialNumber"
37BOARDSN="$(busctl get-property -j "@INV_SERV@" "@INV_OBJ@" "${INT}" "${PART}" | jq -r '.data')"
38
39WARN_MSG="WARNING: Hostname is not set, using Board Serial Number"
40echo "${WARN_MSG}"
41echo "${WARN_MSG}" | systemd-cat -t gbmc-glome -p warning
42exec /usr/sbin/glome-login -M "@BOARDSN_KEY@:${BOARDSN}" "${USER}"
43