-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
40 lines (33 loc) · 1.19 KB
/
docker-entrypoint.sh
File metadata and controls
40 lines (33 loc) · 1.19 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
#!/bin/sh
set -e
echo "🦞 [ClawChives] Initializing Container..."
# PUID/PGID support: Match user ID to host user
TARGET_UID=${PUID:-1000}
TARGET_GID=${PGID:-1000}
# Modify 'node' user if running as root and IDs differ
if [ "$(id -u)" = "0" ] && [ "$TARGET_UID" != "1000" ]; then
echo "🔧 [ClawChives] Updating 'node' user to UID: $TARGET_UID / GID: $TARGET_GID"
# Check if group exists
if getent group "$TARGET_GID" >/dev/null; then
groupmod -o -g "$TARGET_GID" node || true
else
groupmod -g "$TARGET_GID" node
fi
usermod -o -u "$TARGET_UID" -g "$TARGET_GID" node
fi
# Ensure storage directory exists and is writable by the target user
if [ -d "$DATA_DIR" ]; then
echo "📦 [ClawChives] Fixing permissions for $DATA_DIR..."
chown -R "$TARGET_UID:$TARGET_GID" "$DATA_DIR"
elif [ -n "$DATA_DIR" ]; then
echo "📦 [ClawChives] Creating directory $DATA_DIR..."
mkdir -p "$DATA_DIR"
chown -R "$TARGET_UID:$TARGET_GID" "$DATA_DIR"
fi
# Switch to 'node' user if running as root
if [ "$(id -u)" = "0" ]; then
echo "🔒 [ClawChives] Dropping privileges to user 'node' (UID: $(id -u node))..."
exec su-exec node "$@"
else
exec "$@"
fi