summaryrefslogtreecommitdiff
path: root/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.sh
blob: 408ffb61547819b6693113ee66a509ef4f895ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
oldname=
while read -r _; do
  # Don't bother parsing the output, just read the final hostname
  name="$(</etc/hostname)" || continue
  [[ "$oldname" == "$name" ]] && continue
  oldname="$name"
  echo "Updating BMC RA Hostname $name" >&2

  contents='[IPv6SendRA]'$'\n'"Domains=$name"
  for netfile in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/60-domains.conf; do
    mkdir -p "$(dirname "$netfile")"
    printf '%s' "$contents" >"$netfile"
   done

  networkctl reload && networkctl reconfigure gbmcbr
done < <(dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.hostname1'")