-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit
More file actions
executable file
·43 lines (37 loc) · 1.49 KB
/
init
File metadata and controls
executable file
·43 lines (37 loc) · 1.49 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
#!/usr/bin/env bash
set -e
# If running as root, optionally adjust UID/GID
if [ "$(id -u)" -eq 0 ]; then
TARGET_UID="${UID:-1001}"
TARGET_GID="${GID:-1001}"
CURRENT_UID="$(id -u planka)"
CURRENT_GID="$(id -g planka)"
# Only change GID if needed and if target GID is not already taken
if [ "$TARGET_GID" != "$CURRENT_GID" ]; then
if ! getent group "$TARGET_GID" > /dev/null; then
groupmod -g "$TARGET_GID" planka
fi
fi
# Only change UID if needed and if target UID is not already taken
if [ "$TARGET_UID" != "$CURRENT_UID" ]; then
if ! getent passwd "$TARGET_UID" > /dev/null; then
usermod -u "$TARGET_UID" -g "$TARGET_GID" planka
fi
fi
# Ensure required directories exist
mkdir -p /app/public/user-avatars /app/public/project-background-images /app/private/attachments
# Check if any file/dir under /app is not owned by TARGET_UID:GID
if find /app \! -uid "$TARGET_UID" -o \! -gid "$TARGET_GID" | grep -q .; then
echo "Applying chown -R planka:planka /app/"
chown -R planka:planka /app/
else
echo "Skipping chown: all files under /app are already owned by $TARGET_UID:$TARGET_GID"
fi
gosu planka node db/init.js
exec "$@"
else
# Non-root: just make sure directories exist (permission errors may occur if volumes are not owned)
mkdir -p /app/public/user-avatars /app/public/project-background-images /app/private/attachments
node db/init.js
exec "$@"
fi