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


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

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" ]
