forked from cognitom/momy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint
29 lines (24 loc) · 870 Bytes
/
entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
if [ ! -f /.dockerenv ]; then
echo '🚨 Do not run it outside a Docker container.' 1>&2
exit 1
fi
host_uid=$(ls -n $0 | awk '{print $3}') # study who my owner is
host_gid=$(ls -n $0 | awk '{print $4}') # study what I belong to
# Create a user which has the common uid:gid with the host
# TODO: if the user with the uid already exists,
# assign the name of user to `user`.
user=app
groupadd --gid $host_gid $user
useradd --uid $host_uid --gid $host_gid --shell /bin/bash $user
# Add some default files to the home
# note: it's needed because the volumes might be mounted before `useradd`.
mkdir -p /home/$user
cp -r /etc/skel/. /home/$user
chown $user:$user /home/$user /home/$user/.bash* /home/$user/.profile
# Execute the command left, or enter `bash`
if [ $# -gt 0 ]; then
exec su-exec $user $@
else
exec su-exec $user bash
fi