Skip to content

Commit bcd4b9d

Browse files
author
Carlos Brandt
committed
Fix useradd function
1 parent 69005ac commit bcd4b9d

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

entrypoint.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,25 @@ function config_user()
2626
# Variables DUSER, DUID, DGID are read from the #
2727
# environment; if NOUSER is set, do nothing. #
2828
#================================================#
29-
29+
3030
DEFAULT_USER="user"
3131
DEFAULT_UID="1000"
3232
DEFAULT_GID="100"
33-
33+
3434
[[ ! -z "$NOUSER" ]] && \
3535
# nothing to be done here
3636
return 0
37-
37+
3838
DUSER="${DUSER:-$DEFAULT_USER}"
3939
DUID="${DUID:-$DEFAULT_UID}"
4040
DGID="${DGID:-$DEFAULT_GID}"
41-
42-
[[ `id $DUSER > /dev/null` ]] && \
43-
useradd -u "$DUID" \
44-
-g "$DGID" \
45-
-d "/home/$DUSER" -m \
46-
-s /bin/bash \
47-
"$DUSER"
48-
41+
42+
`id $DUSER &> /dev/null` || useradd -u "$DUID" \
43+
-g "$DGID" \
44+
-d "/home/$DUSER" -m \
45+
-s /bin/bash \
46+
"$DUSER"
47+
4948
echo "$DUSER"
5049
return 0
5150
}
@@ -55,7 +54,7 @@ function config_user()
5554
USERNAME=$(config_user)
5655

5756
# If no user created, define the current one (root)
58-
[[ `id "$USERNAME"` ]] || USERNAME="$USER"
57+
[ `id "$USERNAME"` ] || USERNAME="$USER"
5958

6059
# Garantee the user will run on a proper place.
6160
# WORKDIR is the dir where the user will run from.
@@ -72,17 +71,16 @@ chown ${USERNAME}: $WORKDIR && chmod -R u+wrx $WORKDIR
7271
USERID=$(id -u $USERNAME)
7372
GROUPID=$(id -g $USERNAME)
7473

75-
echo ""
74+
echo ""
7675
echo "#====================================================#"
7776
echo " This container is running: '$EXECAPP',"
7877
echo " with arguments: '$DARGS',"
7978
echo " at directory: '$WORKDIR',"
8079
echo " by user: '${USERNAME} (uid:$USERID,gid:$GROUPID)'."
8180
echo "#====================================================#"
82-
echo ""
81+
echo ""
8382
if [ "$EXECAPP" != "$_SHELL" ]; then
8483
su -l $USERNAME -c "cd $WORKDIR && $EXECAPP $DARGS"
8584
else
8685
cd $WORKDIR && su $USERNAME
8786
fi
88-

0 commit comments

Comments
 (0)