Files
ComicOPDS/entrypoint.sh
T

42 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# Get PUID and PGID from environment, default to root (0)
PUID=${PUID:-0}
PGID=${PGID:-0}
echo "Starting ComicOPDS with PUID=$PUID PGID=$PGID"
# If running as root (default), handle user/group creation and permissions
if [ "$(id -u)" = "0" ]; then
# Create group if it doesn't exist
if ! getent group comicopds >/dev/null 2>&1; then
groupadd -g "$PGID" comicopds 2>/dev/null || groupmod -g "$PGID" comicopds
fi
# Create user if it doesn't exist
if ! getent passwd comicopds >/dev/null 2>&1; then
useradd -u "$PUID" -g "$PGID" -d /config -s /bin/bash comicopds 2>/dev/null || usermod -u "$PUID" -g "$PGID" comicopds
fi
# Ensure /data directory exists with correct permissions
# Create all subdirectories that the app will need
mkdir -p /data/thumbs /data/pages
# Fix ownership of /data and all its contents (including any existing files from volume mount)
# This ensures the application user can write to all directories
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
echo "Setting ownership of /data to $PUID:$PGID"
chown -R "$PUID:$PGID" /data
echo "Running uvicorn as user comicopds (UID=$PUID, GID=$PGID)"
exec gosu comicopds "$@"
else
# Running as root - just fix ownership without switching users
chown -R "$PUID:$PGID" /data
fi
fi
# If we get here, either we're already non-root or PUID/PGID were 0
echo "Running uvicorn as current user (UID=$(id -u), GID=$(id -g))"
exec "$@"