#!/bin/bash # NSS wrapper for Avorion getpwuid(); then match upstream Ptero steamcmd entrypoint behavior # (see https://github.com/Ptero-Eggs/yolks/blob/main/steamcmd/entrypoint.sh ) set -eo 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)" PASSWD_FILE="/tmp/passwd" GROUP_FILE="/tmp/group" cp /etc/passwd "$PASSWD_FILE" cp /etc/group "$GROUP_FILE" 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 ! 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 -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 || exit 1 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 # --- below: adapted from Ptero-Eggs/yolks steamcmd/entrypoint.sh --- sleep 1 TZ=${TZ:-UTC} export TZ INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}') export INTERNAL_IP # Set environment for Steam Proton (unchanged from upstream) if [ -f "/usr/local/bin/proton" ]; then if [ -n "${SRCDS_APPID:-}" ]; then mkdir -p "/home/container/.steam/steam/steamapps/compatdata/${SRCDS_APPID}" export STEAM_COMPAT_CLIENT_INSTALL_PATH="/home/container/.steam/steam" export STEAM_COMPAT_DATA_PATH="/home/container/.steam/steam/steamapps/compatdata/${SRCDS_APPID}" export PATH="${PATH}:/root/.local/bin" else echo -e "----------------------------------------------------------------------------------" echo -e "WARNING!!! SRCDS_APPID is missing and must be set when using Proton" echo -e "Server will now terminate" echo -e "----------------------------------------------------------------------------------" exit 1 fi fi STEAM_USER=${STEAM_USER:-anonymous} if [ "${STEAM_USER}" == "anonymous" ]; then STEAM_PASS="" STEAM_AUTH="" fi if [ -z "${AUTO_UPDATE}" ] || [ "${AUTO_UPDATE}" == "1" ]; then if [ -n "${SRCDS_APPID:-}" ] && [ -x "./steamcmd/steamcmd.sh" ]; then # shellcheck disable=SC2046,SC2086 ./steamcmd/steamcmd.sh +force_install_dir /home/container \ $([[ "${WINDOWS_INSTALL:-}" == "1" ]] && printf %s '+@sSteamCmdForcePlatformType windows' || printf %s '+@sSteamCmdForcePlatformType linux') \ +login "${STEAM_USER}" "${STEAM_PASS}" "${STEAM_AUTH}" \ $([[ -z ${HLDS_GAME:-} ]] || printf %s "+app_set_config 90 mod ${HLDS_GAME}") \ "+app_update ${SRCDS_APPID} $([[ -z ${SRCDS_BETAID:-} ]] || printf %s "-beta ${SRCDS_BETAID}") $([[ -z ${SRCDS_BETAPASS:-} ]] || printf %s "-betapassword ${SRCDS_BETAPASS}") ${INSTALL_FLAGS:-} $([[ "${VALIDATE:-}" == "1" ]] && printf %s 'validate')" \ $([[ "${UPDATE_STEAMWORKS:-}" == "1" ]] && printf %s '+app_update 1007') +quit fi fi # Replace {{VAR}} with ${VAR} then eval (required for Pterodactyl egg startup strings) MODIFIED_STARTUP=$(echo "${STARTUP}" | sed -e 's/{{/${/g' -e 's/}}/}/g') echo -e ":/home/container$ ${MODIFIED_STARTUP}" # shellcheck disable=SC2086 eval ${MODIFIED_STARTUP}