-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·51 lines (40 loc) · 1.09 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -e
USER=${USER:-"lean"}
GROUP=${GROUP:-"lean"}
UID=${UID:-1000}
GID=${GID:-1000}
# if uid or gid equal to 0, we just run the command directly
if [ $UID -eq 0 ] || [ $GID -eq 0 ]; then
exec "$@"
fi
# there are serval cases we need to couple with
(
exec 2>/dev/null
# 1. duplicate user name, not same uid
if [ $(getent passwd $USER) ]; then
userdel -r $USER
fi
# 2. duplicate uid, not same name
if [ $(getent passwd $UID) ]; then
userdel -r $(getent passwd $UID | cut -d: -f1)
fi
# 3. duplicate group name with different gid
if [ $(getent group $GROUP) ]; then
groupdel -f $GROUP
fi
# 4. duplicate gid with different group name
if [ $(getent group $GID) ]; then
groupdel -f $(getent group $GID | cut -d: -f1)
fi
)
groupadd -g $GID $GROUP
useradd -m -u $UID -g $GID $USER
# check if XDG_CACHE_HOME is set
if [ "$XDG_CACHE_HOME" != "" ]; then
if [ ! -d "$XDG_CACHE_HOME" ]; then
mkdir -p "$XDG_CACHE_HOME"
fi
chown -R $USER:$GROUP "$XDG_CACHE_HOME"
fi
exec gosu $USER:$GROUP "$@"