Skip to content

Commit e81dcc2

Browse files
author
Carlos Brandt
committed
Fix bugs
- when no EXECAPP, bash is now interactive - when 'user' exist, use it and don't complain
1 parent 880d2b6 commit e81dcc2

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

entrypoint.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#set -xv
77

88
# Executable to which cl arguments should fit
9-
EXECAPP="${EXECAPP:-'/bin/bash'}"
9+
_SHELL='/bin/bash'
10+
EXECAPP="${EXECAPP:-$_SHELL}"
1011

1112
# Save the input cl arguments
1213
DARGS="$*"
@@ -38,11 +39,12 @@ function config_user()
3839
DUID="${DUID:-$DEFAULT_UID}"
3940
DGID="${DGID:-$DEFAULT_GID}"
4041

41-
useradd -u "$DUID" \
42-
-g "$DGID" \
43-
-d "/home/$DUSER" -m \
44-
-s /bin/bash \
45-
"$DUSER" || DUSER=$(id -u $DUID -n)
42+
[[ `id $DUSER > /dev/null` ]] && \
43+
useradd -u "$DUID" \
44+
-g "$DGID" \
45+
-d "/home/$DUSER" -m \
46+
-s /bin/bash \
47+
"$DUSER"
4648

4749
echo "$DUSER"
4850
return 0
@@ -67,13 +69,22 @@ USERNAME=$(config_user)
6769
#TODO: give 'w/r/x' permissions instead of changing ownership;
6870
# this is important 'cause WORKDIR could already exist.
6971
chown ${USERNAME}: $WORKDIR && chmod -R u+wrx $WORKDIR
72+
USERID=$(id -u $USERNAME)
73+
GROUPID=$(id -g $USERNAME)
7074

7175
echo ""
72-
echo "#==========================================#"
73-
echo " This container is running: \'$EXECAPP\',"
74-
echo " with arguments: \'$DARGS\',"
75-
echo " at directory: \'$WORKDIR\',"
76-
echo " by user: \'$USERNAME\'."
77-
echo "#==========================================#"
76+
echo "#====================================================#"
77+
echo " This container is running: '$EXECAPP',"
78+
echo " with arguments: '$DARGS',"
79+
echo " at directory: '$WORKDIR',"
80+
echo " by user: '${USERNAME} (uid:$USERID,gid:$GROUPID)'."
81+
echo "#====================================================#"
7882
echo ""
79-
su -l $USERNAME -c "cd $WORKDIR && $EXECAPP $DARGS"
83+
if [ "$EXECAPP" != "$_SHELL" ]; then
84+
echo "Running execapp"
85+
su -l $USERNAME -c "cd $WORKDIR && $EXECAPP $DARGS"
86+
else
87+
echo "Running bash"
88+
cd $WORKDIR && su $USERNAME
89+
fi
90+

0 commit comments

Comments
 (0)