Skip to content

Commit 0f10776

Browse files
Replace User=ubuntu with User={os.getlogin()} when generating the discovery server configuration file if necessary (#20)
1 parent 28770db commit 0f10776

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

turtlebot4_setup/ros_setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def post_install(self):
408408
def generate_install(self):
409409
with open('/etc/turtlebot4/discovery.conf') as f:
410410
discovery_conf_contents = f.read()
411+
discovery_conf_contents = self.fix_conf_username(discovery_conf_contents)
411412
with open('/etc/turtlebot4/discovery.sh') as f:
412413
discovery_sh_contents = f.read()
413414
return {
@@ -434,3 +435,15 @@ def generate_uninstall(self):
434435
'/etc/systemd/system/multi-user.target.wants/discovery.service': {
435436
'remove': True
436437
}}
438+
439+
def fix_conf_username(self, discovery_conf_contents):
440+
"""
441+
Replace the `User=ubuntu` text in the configuration with the current username
442+
443+
@return The modified config file contents
444+
"""
445+
if os.getlogin() == 'ubuntu':
446+
# no changes needed!
447+
return discovery_conf_contents
448+
449+
return discovery_conf_contents.replace('User=ubuntu', f'User={os.getlogin()}')

0 commit comments

Comments
 (0)