Files
RGSX/docker/docker-entrypoint.sh
shane keulen 5569238e55 Refactor Docker setup with proper volume separation and backwards compatibility
Implemented environment variable-based configuration to support both Docker
and traditional Batocera/RetroBat installations with a single codebase.

Key Changes:
- Added RGSX_CONFIG_DIR and RGSX_DATA_DIR environment variables
- Separate /config and /data volumes in Docker mode
- App files now copied into container at build time (not runtime sync)
- Simplified directory structure (removed __downloads concept)
- Maintained 100% backwards compatibility with non-Docker installations

File Structure by Mode:

| Location        | Docker Mode     | Traditional Mode                   |
|-----------------|-----------------|----------------------------------- |
| Settings/Config | /config/        | /userdata/saves/ports/rgsx/        |
| Game Lists      | /config/games/  | /userdata/saves/ports/rgsx/games/  |
| Images          | /config/images/ | /userdata/saves/ports/rgsx/images/ |
| Logs            | /config/logs/   | /userdata/roms/ports/RGSX/logs/    |
| ROMs            | /data/roms/     | /userdata/roms/                    |

Detection:
- Docker mode: Activated when RGSX_CONFIG_DIR or RGSX_DATA_DIR is set
- Traditional mode: Default when no Docker env vars present

Tested and verified working in both modes.
2025-11-04 21:36:30 -05:00

64 lines
1.8 KiB
Bash

#!/bin/bash
set -e
echo "=== RGSX Docker Container Startup ==="
# If PUID/PGID are set, create user and run as that user
# If not set, run as root (works for SMB mounts)
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
echo "Creating user with PUID=$PUID, PGID=$PGID..."
# Create group if it doesn't exist
if ! getent group $PGID >/dev/null 2>&1; then
groupadd -g $PGID rgsx
fi
# Create user if it doesn't exist
if ! getent passwd $PUID >/dev/null 2>&1; then
useradd -u $PUID -g $PGID -m -s /bin/bash rgsx
fi
echo "Running as user $(id -un $PUID) (UID=$PUID, GID=$PGID)"
RUN_USER="gosu rgsx"
else
echo "Running as root (no PUID/PGID set) - suitable for SMB mounts"
RUN_USER=""
fi
# Create necessary directories
# /config needs logs directory, app will create others (like images/, games/) as needed
# /data needs roms directory
echo "Setting up directories..."
$RUN_USER mkdir -p /config/logs
$RUN_USER mkdir -p /data/roms
# Fix ownership of volumes if PUID/PGID are set
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
echo "Setting ownership on volumes..."
chown -R $PUID:$PGID /config /data 2>/dev/null || true
fi
# Create default settings with show_unsupported_platforms enabled if config doesn't exist
SETTINGS_FILE="/config/rgsx_settings.json"
if [ ! -f "$SETTINGS_FILE" ]; then
echo "Creating default settings with all platforms visible..."
$RUN_USER bash -c "cat > '$SETTINGS_FILE' << 'EOF'
{
\"show_unsupported_platforms\": true
}
EOF"
echo "Default settings created at $SETTINGS_FILE"
fi
echo "=== Starting RGSX Web Server ==="
echo "Config directory: /config"
echo "ROMs directory: /data/roms"
echo "======================================"
# Run the command from the working directory (/app/RGSX set in Dockerfile)
if [ -z "$RUN_USER" ]; then
exec "$@"
else
exec $RUN_USER "$@"
fi