FROM debian:trixie-slim

RUN apt update \
    && apt -y upgrade \
    && apt install --no-install-recommends -y supervisor iproute2 iputils-ping openssh-server procps corosync-qnetd \
    && apt -y autoremove \
    && apt clean all

RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config && \
    grep -qE '^Port 22$' /etc/ssh/sshd_config || echo 'Port 22' >> /etc/ssh/sshd_config && \
    grep -qE '^Port 11922$' /etc/ssh/sshd_config || echo 'Port 11922' >> /etc/ssh/sshd_config

RUN grep -q '^UsePAM' /etc/ssh/sshd_config && \
      sed -i 's/^UsePAM.*/UsePAM yes/' /etc/ssh/sshd_config || \
      echo 'UsePAM yes' >> /etc/ssh/sshd_config

COPY set_root_password.sh /usr/local/bin/set_root_password.sh
RUN chown root.root /usr/local/bin/set_root_password.sh \
    && chmod 755 /usr/local/bin/set_root_password.sh

RUN mkdir -p /run/sshd
RUN mkdir -p /etc/update-motd.d
COPY motd-qdevice.sh /etc/update-motd.d/20-qdevice
RUN chmod 755 /etc/update-motd.d/20-qdevice
RUN : > /etc/motd

COPY supervisord.conf /etc/supervisord.conf

EXPOSE 22
EXPOSE 11922
EXPOSE 5403

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]