1#!/bin/bash
2# Copyright 2024 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
16# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-net-lib.sh
17source /usr/share/gbmc-net-lib.sh || exit
18
19oldname=
20while read -r _; do
21  # Don't bother parsing the output, just read the final hostname
22  name="$(</etc/hostname)" || continue
23  [[ "$oldname" == "$name" ]] && continue
24  oldname="$name"
25  echo "Updating BMC RA Hostname $name" >&2
26
27  contents='[IPv6SendRA]'$'\n'"Domains=$name"
28  for netfile in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/60-domains.conf; do
29    mkdir -p "$(dirname "$netfile")"
30    printf '%s' "$contents" >"$netfile"
31   done
32
33  # shellcheck disable=SC2119
34  gbmc_net_networkd_reload
35done < <(dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.hostname1'")
36