diff --git a/entrypoint.sh b/entrypoint.sh index 21f99e1..f35c4b3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,8 +2,12 @@ set -euo pipefail export USER=container +export LOGNAME=container export HOME=/home/container +export XDG_CONFIG_HOME=/home/container/.config +export XDG_DATA_HOME=/home/container/.local/share mkdir -p /home/container /tmp +mkdir -p "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" uid="$(id -u)" gid="$(id -g)" @@ -14,24 +18,33 @@ GROUP_FILE="/tmp/group" cp /etc/passwd "$PASSWD_FILE" cp /etc/group "$GROUP_FILE" -if ! getent passwd "$uid" >/dev/null 2>&1; then +if ! awk -F: -v target_uid="$uid" '$3 == target_uid { found=1 } END { exit !found }' "$PASSWD_FILE"; then echo "container:x:${uid}:${gid}::/home/container:/bin/bash" >> "$PASSWD_FILE" fi -if ! getent group "$gid" >/dev/null 2>&1; then +if ! awk -F: -v target_gid="$gid" '$3 == target_gid { found=1 } END { exit !found }' "$GROUP_FILE"; then echo "container:x:${gid}:" >> "$GROUP_FILE" fi export NSS_WRAPPER_PASSWD="$PASSWD_FILE" export NSS_WRAPPER_GROUP="$GROUP_FILE" -libnss="$(find /usr/lib /lib -name 'libnss_wrapper.so' 2>/dev/null | head -n 1 || true)" +libnss="$(find /usr/lib /lib -type f \( -name 'libnss_wrapper.so' -o -name 'libnss_wrapper.so.*' \) -print -quit 2>/dev/null || true)" if [ -n "$libnss" ]; then export LD_PRELOAD="${libnss}${LD_PRELOAD:+:${LD_PRELOAD}}" +else + echo "[entrypoint] WARNING: libnss_wrapper not found; UID/GID passthrough may fail for Avorion." >&2 fi cd /home/container +echo "[entrypoint] uid=${uid} gid=${gid} home=${HOME} user=${USER}" >&2 +echo "[entrypoint] NSS wrapper passwd=${NSS_WRAPPER_PASSWD} group=${NSS_WRAPPER_GROUP}" >&2 +echo "[entrypoint] LD_PRELOAD=${LD_PRELOAD:-}" >&2 +if ! getent passwd "$uid" >/dev/null 2>&1; then + echo "[entrypoint] WARNING: getent cannot resolve uid ${uid} prior to exec." >&2 +fi + if [ -n "${STARTUP:-}" ]; then echo ":/home/container$ ${STARTUP}" exec /bin/bash -c "${STARTUP}"