From b1d7724631c8cd38f2bf7d22e57f075f11c04557 Mon Sep 17 00:00:00 2001 From: Chris Iverach-Brereton Date: Thu, 20 Feb 2025 14:33:39 -0500 Subject: [PATCH 1/4] Update the hostname in /boot/firmware/user-data as well as /etc/hostname to ensure it persists properly across reboots --- turtlebot4_setup/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/turtlebot4_setup/conf.py b/turtlebot4_setup/conf.py index 509beb2..4dacc06 100644 --- a/turtlebot4_setup/conf.py +++ b/turtlebot4_setup/conf.py @@ -130,6 +130,7 @@ def __init__(self) -> None: self.netplan_wifis_file = os.path.join(self.netplan_dir, '50-wifis.yaml') self.discovery_sh_file = os.path.join(self.setup_dir, 'discovery.sh') self.hostname_file = '/etc/hostname' + self.fw_user_data_file = '/boot/firmware/user-data' self.system_conf = copy.deepcopy(self.default_system_conf) self.wifi_conf = copy.deepcopy(self.default_wifi_conf) @@ -230,6 +231,11 @@ def write_system(self): f.write(self.get(SystemOptions.HOSTNAME)) subprocess.run(shlex.split('sudo mv /tmp' + self.hostname_file + ' ' + self.hostname_file)) + # update /boot/firmware/user-data with the new hostname + subprocess.run(shlex.split(f'cp {self.fw_user_data_file} /tmp/user-data')) + subprocess.run(shlex.split(f'sed -i -E "s/^hostname:.+/hostname: {self.get(SystemOptions.HOSTNAME)}/" /tmp/user-data')) + subprocess.run(shlex.split(f'sudo mv /tmp/user-data {self.fw_user_data_file}')) + def read_wifi(self): try: # Try to open the existing wifi configuration, but if it doesn't exist we can carry on From a32e1f297de3f8ccc2fca3dad8abc6cda057a3f5 Mon Sep 17 00:00:00 2001 From: Chris Iverach-Brereton Date: Thu, 20 Feb 2025 14:49:30 -0500 Subject: [PATCH 2/4] Disable line-length warning --- turtlebot4_setup/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turtlebot4_setup/conf.py b/turtlebot4_setup/conf.py index 4dacc06..acb0b73 100644 --- a/turtlebot4_setup/conf.py +++ b/turtlebot4_setup/conf.py @@ -233,7 +233,7 @@ def write_system(self): # update /boot/firmware/user-data with the new hostname subprocess.run(shlex.split(f'cp {self.fw_user_data_file} /tmp/user-data')) - subprocess.run(shlex.split(f'sed -i -E "s/^hostname:.+/hostname: {self.get(SystemOptions.HOSTNAME)}/" /tmp/user-data')) + subprocess.run(shlex.split(f'sed -i -E "s/^hostname:.+/hostname: {self.get(SystemOptions.HOSTNAME)}/" /tmp/user-data')) # noqa: E501 subprocess.run(shlex.split(f'sudo mv /tmp/user-data {self.fw_user_data_file}')) def read_wifi(self): From 93735310daa791f2728929315750e81592bd5059 Mon Sep 17 00:00:00 2001 From: Chris Iverach-Brereton Date: Mon, 3 Mar 2025 15:28:55 -0500 Subject: [PATCH 3/4] Suppress error output about failure to preserve permissions across filesystems --- turtlebot4_setup/conf.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/turtlebot4_setup/conf.py b/turtlebot4_setup/conf.py index acb0b73..85b7874 100644 --- a/turtlebot4_setup/conf.py +++ b/turtlebot4_setup/conf.py @@ -234,7 +234,11 @@ def write_system(self): # update /boot/firmware/user-data with the new hostname subprocess.run(shlex.split(f'cp {self.fw_user_data_file} /tmp/user-data')) subprocess.run(shlex.split(f'sed -i -E "s/^hostname:.+/hostname: {self.get(SystemOptions.HOSTNAME)}/" /tmp/user-data')) # noqa: E501 - subprocess.run(shlex.split(f'sudo mv /tmp/user-data {self.fw_user_data_file}')) + subprocess.run( + shlex.split(f'sudo mv /tmp/user-data {self.fw_user_data_file}'), + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) def read_wifi(self): try: From f767da4b8a3352c209f4f39974dbec33b6956ac3 Mon Sep 17 00:00:00 2001 From: Chris Iverach-Brereton Date: Tue, 4 Mar 2025 12:07:50 -0500 Subject: [PATCH 4/4] Write the updated hostname to the turtlebot4/system file --- turtlebot4_setup/conf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/turtlebot4_setup/conf.py b/turtlebot4_setup/conf.py index 85b7874..cbc9545 100644 --- a/turtlebot4_setup/conf.py +++ b/turtlebot4_setup/conf.py @@ -214,7 +214,12 @@ def write_system(self): system = f.readlines() for i, line in enumerate(system): is_conf = False - for k in [SystemOptions.MODEL, SystemOptions.VERSION, SystemOptions.ROS]: + for k in [ + SystemOptions.MODEL, + SystemOptions.VERSION, + SystemOptions.ROS, + SystemOptions.HOSTNAME, + ]: if k in line: system[i] = f'{k}:{self.system_conf[k]}\n' is_conf = True