#!/bin/bash
set -euo pipefail
if (( EUID == 0 )); then
    echo 'Start Steam from your normal desktop account, without sudo.' >&2
    exit 1
fi
if [[ ! -x /lib/ld-linux.so.2 ]]; then
    echo 'Steam requires the Tuxenix lib32-glibc package.' >&2
    exit 1
fi
if [[ ! -d /dev/fd ]]; then
    echo 'Install multilib-runtime and reboot to provide /dev/fd.' >&2
    echo 'See /usr/share/doc/steam/README.tuxenix for installation instructions.' >&2
    exit 1
fi
if ! unshare --user --map-root-user true 2>/dev/null; then
    echo 'Steam requires user namespaces. Boot a Tuxenix kernel with CONFIG_USER_NS=y.' >&2
    echo 'See /usr/share/doc/steam/README.tuxenix for kernel installation instructions.' >&2
    exit 1
fi
# Minimal Tuxenix installations have no ld.so.conf. Make the compatibility
# directory visible to Steam Runtime's host-library discovery, so Mesa uses
# the current compiler runtimes instead of Valve's older bundled copies.
export LD_LIBRARY_PATH="/usr/lib32${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
exec /usr/lib/steam/bin_steam.sh "$@"
