diff --git a/turtlebot4_setup/ros_setup.py b/turtlebot4_setup/ros_setup.py index 8fc31e8..3e01f38 100644 --- a/turtlebot4_setup/ros_setup.py +++ b/turtlebot4_setup/ros_setup.py @@ -408,6 +408,7 @@ def post_install(self): def generate_install(self): with open('/etc/turtlebot4/discovery.conf') as f: discovery_conf_contents = f.read() + discovery_conf_contents = self.fix_conf_username(discovery_conf_contents) with open('/etc/turtlebot4/discovery.sh') as f: discovery_sh_contents = f.read() return { @@ -434,3 +435,15 @@ def generate_uninstall(self): '/etc/systemd/system/multi-user.target.wants/discovery.service': { 'remove': True }} + + def fix_conf_username(self, discovery_conf_contents): + """ + Replace the `User=ubuntu` text in the configuration with the current username + + @return The modified config file contents + """ + if os.getlogin() == 'ubuntu': + # no changes needed! + return discovery_conf_contents + + return discovery_conf_contents.replace('User=ubuntu', f'User={os.getlogin()}')