-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathentrypoint
40 lines (33 loc) · 1.05 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
if [ ! -f /.dockerenv ]; then
echo '🚨 Do not run it outside a Docker container.' 1>&2
exit 1
fi
# Create a user which has the common uid:gid with the host,
# or check if the user exists
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
user=$(cat /etc/passwd | grep ":x:$host_uid:" | cut -d: -f1)
group=$(cat /etc/group | grep ":x:$host_gid:" | cut -d: -f1)
if [ -z "$group" ]; then
group=app
echo "Creating a group..."
groupadd --gid $host_gid $group
fi
if [ -z "$user" ]; then
user=app
echo "Creating an user..."
useradd --uid $host_uid --gid $host_gid --shell /bin/bash $user
# Add some default files to the home
mkdir -p /home/$user
cp -r /etc/skel/. /home/$user
chown $user:$group /home/$user /home/$user/.bash* /home/$user/.profile
else
echo "The user $user already exists in this container (id:$host_uid)"
fi
# Execute the command left, or enter `bash`
if [ $# -gt 0 ]; then
exec su-exec $user $@
else
exec su-exec $user bash
fi