-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
95 lines (72 loc) · 2.94 KB
/
entrypoint.sh
File metadata and controls
95 lines (72 loc) · 2.94 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# DevDocker entrypoint - creates user and switches to it automatically
set -e
# ============================================
# User Setup (runs only once)
# ============================================
if [ ! -f /tmp/.user_created ]; then
echo "================================"
echo "🐳 DevDocker - User Setup"
echo "================================"
echo ""
# Get host user info
USER_NAME="${HOST_USER:-devuser}"
USER_UID="${HOST_UID:-1000}"
USER_GID="${HOST_GID:-1000}"
echo "👤 Creating user: $USER_NAME (UID: $USER_UID, GID: $USER_GID)"
# Create group if it doesn't exist
if ! getent group "$USER_GID" >/dev/null 2>&1; then
groupadd -g "$USER_GID" "$USER_NAME"
fi
# Create user
if ! id -u "$USER_NAME" >/dev/null 2>&1; then
useradd -m -u "$USER_UID" -g "$USER_GID" -s /bin/bash "$USER_NAME"
# Add to sudo without password
usermod -aG sudo "$USER_NAME"
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Copy and configure conda
if [ -f /root/.condarc ]; then
cp /root/.condarc /home/"$USER_NAME"/.condarc
chown "$USER_NAME":"$USER_NAME" /home/"$USER_NAME"/.condarc
fi
su - "$USER_NAME" -c "conda init bash" > /dev/null 2>&1
# Create symlinks for mounted configs
ln -sf /root/.gitconfig /home/"$USER_NAME"/.gitconfig 2>/dev/null || true
ln -sf /root/.ssh /home/"$USER_NAME"/.ssh 2>/dev/null || true
# Set workspace permissions
if [ -d /workspace ]; then
chown -R "$USER_NAME":"$USER_NAME" /workspace 2>/dev/null || true
fi
# Add cursor reset to user's bashrc
echo '' >> /home/"$USER_NAME"/.bashrc
echo '# Preserve host terminal cursor style' >> /home/"$USER_NAME"/.bashrc
echo 'if [ -n "$DEVDOCKER_CURSOR" ]; then' >> /home/"$USER_NAME"/.bashrc
echo ' printf "\033[%s q" "$DEVDOCKER_CURSOR"' >> /home/"$USER_NAME"/.bashrc
echo 'fi' >> /home/"$USER_NAME"/.bashrc
chown "$USER_NAME":"$USER_NAME" /home/"$USER_NAME"/.bashrc
echo "✅ User created successfully!"
echo ""
fi
# Mark as done
echo "$USER_NAME" > /tmp/.user_created
fi
# Get the created/existing user
USER_NAME=$(cat /tmp/.user_created 2>/dev/null || echo "${HOST_USER:-devuser}")
# ============================================
# Save and restore cursor style
# ============================================
# Trap to restore cursor on exit
restore_cursor() {
if [ -n "$DEVDOCKER_CURSOR" ]; then
printf "\033[%s q" "$DEVDOCKER_CURSOR"
fi
}
trap restore_cursor EXIT INT TERM
# ============================================
# Switch to non-root user and execute command
# ============================================
if [ "$(whoami)" = "root" ]; then
exec gosu "$USER_NAME" "$@"
else
exec "$@"
fi