From 3b670b6cf90f1f95545a8938fd043594c76bb046 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 27 Mar 2020 19:52:24 +0100 Subject: [PATCH] Automatically remove existing system group if it exists when creating primary groups --- locales/en.json | 1 + src/yunohost/user.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/locales/en.json b/locales/en.json index c4f82117e..9084bada8 100644 --- a/locales/en.json +++ b/locales/en.json @@ -221,6 +221,7 @@ "good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters—though it is good practice to use 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