Skip to content

Commit b1d7724

Browse files
committed
Update the hostname in /boot/firmware/user-data as well as /etc/hostname to ensure it persists properly across reboots
1 parent 28770db commit b1d7724

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

turtlebot4_setup/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def __init__(self) -> None:
130130
self.netplan_wifis_file = os.path.join(self.netplan_dir, '50-wifis.yaml')
131131
self.discovery_sh_file = os.path.join(self.setup_dir, 'discovery.sh')
132132
self.hostname_file = '/etc/hostname'
133+
self.fw_user_data_file = '/boot/firmware/user-data'
133134

134135
self.system_conf = copy.deepcopy(self.default_system_conf)
135136
self.wifi_conf = copy.deepcopy(self.default_wifi_conf)
@@ -230,6 +231,11 @@ def write_system(self):
230231
f.write(self.get(SystemOptions.HOSTNAME))
231232
subprocess.run(shlex.split('sudo mv /tmp' + self.hostname_file + ' ' + self.hostname_file))
232233

234+
# update /boot/firmware/user-data with the new hostname
235+
subprocess.run(shlex.split(f'cp {self.fw_user_data_file} /tmp/user-data'))
236+
subprocess.run(shlex.split(f'sed -i -E "s/^hostname:.+/hostname: {self.get(SystemOptions.HOSTNAME)}/" /tmp/user-data'))
237+
subprocess.run(shlex.split(f'sudo mv /tmp/user-data {self.fw_user_data_file}'))
238+
233239
def read_wifi(self):
234240
try:
235241
# Try to open the existing wifi configuration, but if it doesn't exist we can carry on

0 commit comments

Comments
 (0)