-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentrypoint.sh
More file actions
68 lines (52 loc) · 2.22 KB
/
entrypoint.sh
File metadata and controls
68 lines (52 loc) · 2.22 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
#!/bin/bash
# PUID/PGID support for lancache-manager
# Similar to linuxserver.io images
PUID=${PUID:-1000}
PGID=${PGID:-1000}
# Export PUID/PGID for the .NET application to display
export LANCACHE_PUID=$PUID
export LANCACHE_PGID=$PGID
# Create group if GID doesn't exist
if ! getent group "$PGID" > /dev/null 2>&1; then
groupadd -g "$PGID" lancache
fi
# Get group name for the GID
GROUP_NAME=$(getent group "$PGID" | cut -d: -f1)
# Create user if UID doesn't exist
if ! getent passwd "$PUID" > /dev/null 2>&1; then
useradd -u "$PUID" -g "$PGID" -d /app -s /bin/bash -M lancache
fi
# Get username for the UID
USER_NAME=$(getent passwd "$PUID" | cut -d: -f1)
# Handle docker socket permissions if mounted
# This allows the container to communicate with docker for nginx log rotation
DOCKER_GROUP=""
if [ -S /var/run/docker.sock ]; then
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
# Create docker group with the socket's GID if it doesn't exist
if ! getent group "$DOCKER_GID" > /dev/null 2>&1; then
groupadd -g "$DOCKER_GID" docker
fi
DOCKER_GROUP=$(getent group "$DOCKER_GID" | cut -d: -f1)
# Add our user to the docker group
usermod -aG "$DOCKER_GROUP" "$USER_NAME" 2>/dev/null || true
echo "Docker socket detected (GID: $DOCKER_GID). User '$USER_NAME' added to group '$DOCKER_GROUP'."
fi
# Change ownership of application directories
# /data needs write access for database and progress files
# /app needs read access for the application
chown -R "$PUID:$PGID" /data /app/rust-processor 2>/dev/null || true
# Fix ownership of /logs and /cache if they are writable (not mounted read-only)
# Only chown the directory itself (not -R) to avoid slow recursive operations on large caches
for dir in /logs /cache; do
if [ -d "$dir" ] && touch "$dir/.permcheck" 2>/dev/null; then
rm -f "$dir/.permcheck"
chown "$PUID:$PGID" "$dir" 2>/dev/null || true
echo "Fixed ownership of $dir for UID:$PUID GID:$PGID"
fi
done
# Ensure rust binaries are executable
chmod +x /app/rust-processor/* 2>/dev/null || true
# Run the application as the specified user
# Use username (not UID:GID) so gosu picks up supplementary groups from /etc/group
exec gosu "$USER_NAME" dotnet LancacheManager.dll "$@"