-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwei-entrypoint.sh
51 lines (46 loc) · 1.56 KB
/
wei-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -e
set -o pipefail
# Change the UID and GID of the app user if they are provided as environment variables
if [ -z "${USER_ID}" ]; then
USER_ID=9999
fi
if [ -z "${GROUP_ID}" ]; then
GROUP_ID=9999
fi
if [ "$USER_ID" -ne 0 ] && [ "$USER_ID" -ne 9999 ]; then
GROUP_LIST=$(groups app)
userdel app
elif [ "$GROUP_ID" -ne 0 ] && [ "$GROUP_ID" -ne 9999 ]; then
groupdel app
fi
if [ "$GROUP_ID" -ne 0 ] && [ "$GROUP_ID" -ne 9999 ]; then
groupadd -g $GROUP_ID app
fi
if [ "$USER_ID" -ne 0 ] && [ "$USER_ID" -ne 9999 ]; then
useradd -u $USER_ID --shell /bin/bash -g ${GROUP_ID} app
usermod -aG $(echo "$GROUP_LIST" | sed 's/.*: //; s/ /,/g') app
fi
# Best-effort attempt to align permissions for the default data directory
mkdir -p /home/app/.wei/experiments /home/app/.wei/temp /home/app/.diaspora
chown $USER_ID:$GROUP_ID /home/app || true
chown $USER_ID:$GROUP_ID /home/app/.wei || true
chown $USER_ID:$GROUP_ID /home/app/.wei/experiments || true
chown $USER_ID:$GROUP_ID /home/app/.wei/temp || true
chown $USER_ID:$GROUP_ID /home/app/.diaspora || true
# Run the container command as the specified user
if [ "$USER_ID" -eq 0 ] && [ "$GROUP_ID" -eq 0 ]; then
# If we are root, easiest thing to do is to symlink everything from /home/app to /root
shopt -s dotglob
for item in /home/app/*; do
dest="/root/$(basename "$item")"
if [ ! -e "$dest" ]; then
ln -s "$item" "$dest"
fi
done
shopt -u dotglob
exec "$@"
else
# If we are not root, we need to drop privileges
exec gosu app "$@"
fi