Repository: ranger Updated Branches: refs/heads/master 91a437a29 -> dcba4bc40
RANGER-2001:Similar to RANGER-1469, we should check whether the user or group has existed before the installer create a new user or group when user install usersync Signed-off-by: zhangqiang2 <zhangqia...@zte.com.cn> Project: http://git-wip-us.apache.org/repos/asf/ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/dcba4bc4 Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/dcba4bc4 Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/dcba4bc4 Branch: refs/heads/master Commit: dcba4bc40a795156fbac8b747e339dc34a23bec7 Parents: 91a437a Author: zhangqiang2 <zhangqia...@zte.com.cn> Authored: Thu Mar 1 14:56:59 2018 +0800 Committer: zhangqiang2 <zhangqia...@zte.com.cn> Committed: Fri Mar 2 08:57:20 2018 +0800 ---------------------------------------------------------------------- unixauthservice/scripts/setup.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ranger/blob/dcba4bc4/unixauthservice/scripts/setup.py ---------------------------------------------------------------------- diff --git a/unixauthservice/scripts/setup.py b/unixauthservice/scripts/setup.py index 5ae9123..3fd0dd9 100755 --- a/unixauthservice/scripts/setup.py +++ b/unixauthservice/scripts/setup.py @@ -280,11 +280,14 @@ def convertInstallPropsToXML(props): def createUser(username, groupname): - cmd = "useradd -g %s %s -m" % (groupname, username) - ret = os.system(cmd) - if (ret != 0): - print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret) - sys.exit(1) + checkuser = "grep ^" + username + ": /etc/passwd | awk -F: '{print $1}'|head -1 " + (status, output) = commands.getstatusoutput(checkuser) + if len(output) < 1: + cmd = "useradd -g %s %s -m" % (groupname, username) + ret = os.system(cmd) + if (ret != 0): + print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret) + sys.exit(1) try: ret = pwd.getpwnam(username).pw_uid return ret @@ -294,11 +297,14 @@ def createUser(username, groupname): def createGroup(groupname): - cmd = "groupadd %s" % (groupname) - ret = os.system(cmd) - if (ret != 0): - print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret) - sys.exit(1) + checkgroup = "egrep ^" + groupname + ": /etc/group | awk -F: '{print $1}'|head -1 " + (status, output) = commands.getstatusoutput(checkgroup) + if len(output) < 1: + cmd = "groupadd %s" % (groupname) + ret = os.system(cmd) + if (ret != 0): + print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret) + sys.exit(1) try: ret = grp.getgrnam(groupname).gr_gid return ret