diff --git a/locales/en.json b/locales/en.json index 4582b71b9..124bd79d3 100644 --- a/locales/en.json +++ b/locales/en.json @@ -290,6 +290,7 @@ "good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters long—though it is good practice to use a longer password (i.e. a passphrase) and/or to a variation of characters (uppercase, lowercase, digits and special characters).", "group_already_exist": "Group {group} already exists", "group_already_exist_on_system": "Group {group} already exists in the system groups", + "group_already_exist_on_system_but_removing_it": "Group {group} already exists in the system groups, but YunoHost will remove it…", "group_created": "Group '{group}' created", "group_creation_failed": "Could not create the group '{group}': {error}", "group_cannot_edit_all_users": "The group 'all_users' cannot be edited manually. It is a special group meant to contain all users registered in YunoHost", diff --git a/src/yunohost/user.py b/src/yunohost/user.py index fdcac658d..34b367d7d 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -576,7 +576,11 @@ def user_group_create(operation_logger, groupname, gid=None, primary_group=False # Validate uniqueness of groupname in system group all_existing_groupnames = {x.gr_name for x in grp.getgrall()} if groupname in all_existing_groupnames: - raise YunohostError('group_already_exist_on_system', group=groupname) + if primary_group: + logger.warning('group_already_exist_on_system_but_removing_it', group=groupname) + subprocess.check_call("sed --in-place '/^%s:/d' /etc/group" % groupname, shell=True) + else: + raise YunohostError('group_already_exist_on_system', group=groupname) if not gid: # Get random GID