Skip to content

Commit 560402a

Browse files
author
Jakub Kaczmarzyk
authored
FIX: check if user exists before creating (#253)
* check if user exists before adding * fix syntax error
1 parent 20f1247 commit 560402a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

neurodocker/generators/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ def add(cls, user):
6969
if user not in cls.initialized_users:
7070
cls.initialized_users.add(user)
7171
return (
72-
"useradd --no-user-group --create-home --shell /bin/bash {0}".
73-
format(user))
72+
# Test whether the user exists. If not, add user.
73+
'test "$(getent passwd {0})" ||'
74+
' useradd --no-user-group --create-home --shell /bin/bash {0}'
75+
.format(user))
7476
else:
7577
return False
7678

0 commit comments

Comments
 (0)