FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y \
      ca-certificates \
      curl \
      lib32gcc-s1 \
      libssl3 \
      xvfb \
      winbind \
      cabextract \
      xz-utils && \
    rm -rf /var/lib/apt/lists/*

# Create steam user
RUN useradd -m -s /bin/bash steam

# SteamCMD install (as root)
RUN mkdir -p /home/steam/steamcmd && \
    cd /home/steam/steamcmd && \
    curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" \
      | tar zxvf - && \
    chown -R steam:steam /home/steam/steamcmd && \
    chmod -R a+x /home/steam/steamcmd

ENV STEAMCMD_DIR=/home/steam/steamcmd
ENV ACEVO_INSTALL_DIR=/home/steam/acevo-server

RUN mkdir -p ${ACEVO_INSTALL_DIR} && \
    chown -R steam:steam ${ACEVO_INSTALL_DIR}

# Copy AC Evo Server Manager
COPY . /app
WORKDIR /app

# Copy entrypoint
COPY entrypoint.sh /home/steam/entrypoint.sh
RUN chown steam:steam /home/steam/entrypoint.sh && \
    chmod +x /home/steam/entrypoint.sh

USER steam
WORKDIR /home/steam

ENTRYPOINT ["/home/steam/entrypoint.sh"]
