From 0fba0da794b27894e01d8eb49e6113f274b1ce88 Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Fri, 13 Oct 2017 23:31:17 +0200 Subject: [PATCH 1/2] Use getent to check the existence of user/group --- entrypoint | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint b/entrypoint index d3a528f..03eb959 100755 --- a/entrypoint +++ b/entrypoint @@ -51,7 +51,7 @@ function createUser() { gid="${args[$[$index+3]]}"; validateArg "GID" "$gid" "$reGid" || return 1 dir="${args[$[$index+4]]}"; validateArg "dirs" "$dir" "$reDir" || return 1 - if $(cat /etc/passwd | cut -d: -f1 | grep -q "^$user:"); then + if getent passwd $user > /dev/null; then log "WARNING: User \"$user\" already exists. Skipping." return 0 fi @@ -63,7 +63,7 @@ function createUser() { fi if [ -n "$gid" ]; then - if ! $(cat /etc/group | cut -d: -f3 | grep -q "$gid"); then + if ! getent group $gid > /dev/null; then groupadd --gid $gid "group_$gid" fi From f3212b3377d20f9bf81e989d4bec8f6dffa479fb Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Fri, 13 Oct 2017 23:39:04 +0200 Subject: [PATCH 2/2] Consistent syntax for subshell --- entrypoint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint b/entrypoint index 03eb959..e5f2601 100755 --- a/entrypoint +++ b/entrypoint @@ -77,7 +77,7 @@ function createUser() { # Retrieving user id to use it in chown commands instead of the user name # to avoid problems on alpine when the user name contains a '.' - uid=`id $user -u` + uid="$(id -u $user)" if [ -n "$pass" ]; then echo "$user:$pass" | chpasswd $chpasswdOptions