-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·54 lines (45 loc) · 1.3 KB
/
entrypoint.sh
File metadata and controls
executable file
·54 lines (45 loc) · 1.3 KB
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
52
53
54
#!/usr/bin/env bash
set -euo pipefail
project_dir=${DEVSHELL_PROJECT_DIR:=""}
if [[ $project_dir == "" ]]; then
echo DEVSHELL_PROJECT_DIR must be set. >&2
exit 1
fi
cd "$project_dir"
host_uid=$(stat -c %u .)
host_gid=$(stat -c %g .)
group_name=$(getent group "$host_gid" | cut -d: -f1 || echo)
if [[ ! $group_name ]]; then
group_name=user
groupadd -g $host_gid $group_name
fi
user_name=$(getent passwd "$host_uid" | cut -d: -f1 || echo)
if [[ ! $user_name ]]; then
user_name=user
useradd -mg $host_gid -u $host_uid $user_name 2> /dev/null
fi
# It's helpful to use the same home directory regardless of base image.
HOME=/home/user
mkdir -p "$HOME"
chown "$host_uid:$host_gid" "$HOME"
if [[ $(getent passwd "$user_name" | cut -d: -f6 || echo) != $HOME ]]; then
usermod -d "$HOME" "$user_name"
fi
if [[ $host_uid == 0 ]]; then
# The container engine is likely remapping ids, so root _is_ our user and
# we'll just have to roll with it.
rm -rf /root
ln -s /home/user /root
else
if [[ ! -f /etc/sudoers.d/user ]]; then
echo "$user_name:secret" | chpasswd
echo "$user_name ALL=(ALL:ALL) ALL" > /etc/sudoers.d/user
echo "Defaults !lecture" > /etc/sudoers.d/lecture
fi
fi
exec setpriv \
--reuid $host_uid \
--regid $host_gid \
--clear-groups \
/usr/local/bin/entrypoint-user.sh \
"$@"