Files
family-planner/docker-entrypoint.sh

36 lines
1.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
set -e
# Resolve PUID/PGID (Unraid default: nobody=99, users=100)
PUID=${PUID:-99}
PGID=${PGID:-100}
echo "[entrypoint] Starting Family Planner (PUID=${PUID}, PGID=${PGID})"
# Resolve group: reuse existing group at PGID, or create a new one
if getent group "${PGID}" > /dev/null 2>&1; then
APP_GROUP=$(getent group "${PGID}" | cut -d: -f1)
echo "[entrypoint] Reusing existing group '${APP_GROUP}' (GID=${PGID})"
else
APP_GROUP=appgroup
addgroup -g "${PGID}" "${APP_GROUP}"
echo "[entrypoint] Created group '${APP_GROUP}' (GID=${PGID})"
fi
# Resolve user: reuse existing user at PUID, or create a new one
if getent passwd "${PUID}" > /dev/null 2>&1; then
APP_USER=$(getent passwd "${PUID}" | cut -d: -f1)
echo "[entrypoint] Reusing existing user '${APP_USER}' (UID=${PUID})"
else
APP_USER=appuser
adduser -D -u "${PUID}" -G "${APP_GROUP}" "${APP_USER}"
echo "[entrypoint] Created user '${APP_USER}' (UID=${PUID})"
fi
# Ensure /data is owned by the app user so SQLite can write
mkdir -p /data
chown -R "${PUID}:${PGID}" /data
# Drop privileges and exec the CMD
exec su-exec "${PUID}:${PGID}" "$@"