FROM python:3.10-bullseye

ENV mode="EWS"
ENV username=
ENV password=
ENV server="exchange.sankt-wendel.de"
ENV primary_smtp_address=
ENV filter_from="leitstelle@zrf-saar.de"
ENV webhooks=""
ENV alarminator_api=""
ENV alarminator_token=""
ENV alarmfax_parser_id=""
ENV alarminator_zvies_use_PEALGRP="False"
ENV print_num=0
ENV printer="DEFAULT"
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
ENV DIVERA_MESSANGER_API_KEY=""
ENV DIVERA_ALARMER_API_KEY=""
ENV MAPS_API_KEY=""


COPY *.deb /
RUN apt-get --yes --force-yes  update
RUN dpkg -i *.deb || exit 0
RUN apt-get --yes install -f
RUN apt-get --yes --force-yes  install ca-certificates cups cups-filters libcups2-dev \
  sudo \
  whois \
  usbutils \
  cups \
  cups-client \
  cups-bsd \
  cups-filters \
  foomatic-db-compressed-ppds \
  printer-driver-all \
  openprinting-ppds \
  hpijs-ppds \
  hp-ppd \
  hplip \
  smbclient \
  printer-driver-cups-pdf \
#  cndrvcups-common \
#  cndrvcups-ufr2-uk \
#&& dpkg -i /*.deb || exit 0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /*.deb

WORKDIR /usr/src/app
EXPOSE 631
# Add user and disable sudo password checking
RUN useradd \
  --groups=sudo,lp,lpadmin \
  --create-home \
  --home-dir=/home/print \
  --shell=/bin/bash \
  --password=$(mkpasswd print) \
  print \
&& sed -i '/%sudo[[:space:]]/ s/ALL[[:space:]]*$/NOPASSWD:ALL/' /etc/sudoers


# Print PDF
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    --no-install-recommends \
    && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update && apt-get install -y \
    google-chrome-stable \
    --no-install-recommends

# It won't run from the root user.
RUN groupadd chrome && useradd -g chrome -s /bin/bash -G audio,video chrome \
    && mkdir -p /home/chrome && chown -R chrome:chrome /home/chrome

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY ./app .
COPY *.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates

CMD [ "sh","-c","/etc/init.d/cups start && python3 /usr/src/app/run.py" ]
