Leo Tu | 9104c30 | 2022-08-18 05:17:39 +0000 | [diff] [blame] | 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. |
| 15 | set -eo pipefail |
| 16 | |
| 17 | HOSTNAME="$(hostname)" |
| 18 | USER="${1?Missing first param: USER (Usually passed by agetty via \\u)}" |
| 19 | |
| 20 | if [[ "$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]}" |
| 23 | fi |
| 24 | |
| 25 | if [[ "${HOSTNAME}" == *"@HOSTNAME_SUFFIX@" ]]; then |
| 26 | # Valid hostname is already set, invoke normal glome |
| 27 | exec /usr/sbin/glome-login -M "${HOSTNAME}" "${USER}" |
| 28 | fi |
| 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 |
| 35 | INT="xyz.openbmc_project.Inventory.Decorator.Asset" |
| 36 | PART="SerialNumber" |
| 37 | BOARDSN="$(busctl get-property -j "@INV_SERV@" "@INV_OBJ@" "${INT}" "${PART}" | jq -r '.data')" |
| 38 | |
| 39 | WARN_MSG="WARNING: Hostname is not set, using Board Serial Number" |
| 40 | echo "${WARN_MSG}" |
| 41 | echo "${WARN_MSG}" | systemd-cat -t gbmc-glome -p warning |
| 42 | exec /usr/sbin/glome-login -M "@BOARDSN_KEY@:${BOARDSN}" "${USER}" |