Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion turtlebot4_setup/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -213,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
Expand All @@ -230,6 +236,15 @@ 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')) # noqa: E501
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:
# Try to open the existing wifi configuration, but if it doesn't exist we can carry on
Expand Down
Loading