forked from projectcalico/go-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·36 lines (29 loc) · 1.01 KB
/
entrypoint.sh
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
#!/bin/bash
# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or
# fallback
USER_ID=${LOCAL_USER_ID:-9001}
if [ "${RUN_AS_ROOT}" = "true" ]; then
exec "$@"
fi
echo "Starting with UID : $USER_ID" 1>&2
# Do not create mail box.
/bin/sed -i 's/^CREATE_MAIL_SPOOL=yes/CREATE_MAIL_SPOOL=no/' /etc/default/useradd
# Don't pass "-m" to useradd if the home directory already exists (which can occur if it was volume mounted in) otherwise it will fail.
if [[ ! -d "/home/user" ]]; then
/usr/sbin/useradd -m -U -s /bin/bash -u $USER_ID user
else
/usr/sbin/useradd -U -s /bin/bash -u $USER_ID user
fi
export HOME=/home/user
if [ -n "$EXTRA_GROUP_ID" ]; then
echo "Adding user to additional GID : $EXTRA_GROUP_ID" 1>&2
# Adding the group can fail if it already exists.
if addgroup --gid $EXTRA_GROUP_ID group; then
adduser user group
else
echo "Adding user to existing group instead" 1>&2
adduser user `getent group $EXTRA_GROUP_ID | cut -d: -f1`
fi
fi
exec /sbin/su-exec user "$@"