Skip to content

Commit f82e852

Browse files
committed
Added the idea of WORKDIR, where to run things from.
1 parent 8c7db8b commit f82e852

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

entrypoint.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,26 @@ CWD="$PWD"
1616
# Add a user here
1717
USERNAME=$(${CWD}/config_user.sh)
1818

19-
[[ "$USERNAME" = "0" ]] && USERNAME="$USER"
19+
# If no user created, define the current one (root)
20+
[[ `id $USERNAME` ]] || USERNAME="$USER"
2021

21-
su -l $USERNAME -c "$INTERP $DARGS"
22+
# Garantee the user will run on a proper place.
23+
# WORKDIR is the dir where the user will run from.
24+
if [ ! -z "$WORKDIR" ]; then
25+
# If WORKDIR is defined, verify the permissions
26+
if [ -d "$WORKDIR" ]; then
27+
if [ ! -w "$WORKDIR" ]; then
28+
chown -R ${USERNAME}: $WORKDIR
29+
chmod 755 $WORKDIR
30+
fi
31+
else
32+
mkdir -p $WORKDIR
33+
chown ${USERNAME}: $WORKDIR
34+
fi
35+
else
36+
# If WORKDIR is not defined, use its HOME
37+
WORKDIR=$(getent passwd $USERNAME | awk -F: '{print $(NF-1)}')
38+
fi
39+
40+
su -l $USERNAME -c "cd $WORKDIR && $INTERP $DARGS"
2241

0 commit comments

Comments
 (0)