ARG FROM_IMG=docker.io/library/debian
ARG FROM_TAG=12.5

FROM ${FROM_IMG}:${FROM_TAG}

# Setup locales
# RUN apt-get update && apt-get -y install locales locales-all
# RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
#     locale-gen
# ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8

# FraDrive runtime dependencies
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt-get update && apt-get -y install libpq-dev
RUN apt-get update && apt-get -y install libsodium-dev
RUN apt-get update && apt-get -y install fonts-roboto
# TODO: minimize texlive dependencies, switch to basic schemes where possible
RUN apt-get update && apt-get -y install \
    texlive-full \
    texlive-luatex \
    texlive-plain-generic \
    texlive-fonts-recommended \
    texlive-fonts-extra \
    texlive-lang-english \
    texlive-lang-german

# Add uniworx user and directories
RUN mkdir -p /var/lib
RUN mkdir -p /var/log
RUN groupadd -r uniworx
RUN useradd -r -g uniworx -d /var/lib/uniworx -M uniworx --uid 999
RUN mkdir -p /var/lib/uniworx && chown -R uniworx:uniworx /var/lib/uniworx
RUN mkdir -p /var/log/uniworx && chown -R uniworx:uniworx /var/log/uniworx

# Install FraDrive binaries
# RUN install -d -g uniworx -o uniworx -m 0750 /var/lib/uniworx
# RUN install -d -g uniworx -o uniworx -m 0755 /var/log/uniworx
COPY ./bin/uniworx /usr/bin/uniworx
COPY ./bin/uniworxdb /usr/bin/uniworxdb
# COPY uniworxload /usr/bin/uniworx
RUN chmod -R 777 /usr/bin
COPY ./docker/fradrive/fradrive-entrypoint.sh /entrypoint.sh
RUN chmod 777 /entrypoint.sh

USER uniworx
ENTRYPOINT /entrypoint.sh
EXPOSE 8080/tcp
VOLUME /var/lib/uniworx /var/log