# Based on the skiff/core defconfig (Ubuntu) Dockerfile, with modifications for
# Debian.

FROM debian:bullseye as stage1

# setup environment
ENV LANG=C.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    container=docker

# Download apt cache
RUN rm -rf /var/lib/apt/lists/* && \
    apt-get update

# Core packages
RUN export DEBIAN_FRONTEND=noninteractive; \
    apt-get dist-upgrade -y && \
    apt-get install -y  \
    --no-install-recommends \
    -o "Dpkg::Options::=--force-confdef"  \
    -o "Dpkg::Options::=--force-confnew"  \
    autotools-dev \
    build-essential \
    cups \
    curl \
    git \
    htop \
    locales \
    lsb-release \
    nano \
    net-tools \
    openssh-client \
    rsync \
    software-properties-common \
    sudo \
    systemd \
    unzip \
    usbutils \
    vim \
    wget && \
    apt-get autoremove -y

# Cleanup any data we don't need.
RUN rm -rf /var/lib/apt/lists/*

# Locale-gen
RUN locale-gen "en_US.UTF-8"

FROM scratch as stage2

COPY --from=stage1 / /

# Note: this section identical to skiff-core-defconfig

ENV container=docker \
  LANG=en_US.UTF-8 \
  LANGUAGE=en_US:en \
  LC_ALL=en_US.UTF-8

# Create the user 'core' which will be the usual userspace account
# Also allow core to run stuff as sudo without a password.
RUN \
  adduser core \
  --no-create-home \
  --gecos "SkiffOS Core" \
  --shell /bin/bash \
  --disabled-password && \
  adduser core audio && \
  adduser core sudo && \
  adduser core root && \
  adduser core systemd-journal && \
  adduser core dialout && \
  adduser core plugdev && \
  mkdir -p /home/core/ && \
  chown core:core /home/core && \
  passwd -d core && \
  echo "core    ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN systemctl set-default graphical.target && \
    systemctl mask tmp.mount && \
    find /etc/systemd/system \
         /lib/systemd/system \
         \( -path '*.wants/*' \
         -name '*swapon*' \
         -or -name '*ntpd*' \
         -or -name '*resolved*' \
         -or -name '*udev*' \
         -or -name '*freedesktop*' \
         -or -name '*persist-resize*' \
         -or -name '*remount-fs*' \
         -or -name '*getty*' \
         -or -name '*systemd-sysctl*' \
         -or -name '*.mount' \
         -or -name '*remote-fs*' \) \
         -exec echo \{} \; \
         -exec rm \{} \;

WORKDIR /
ENTRYPOINT ["/lib/systemd/systemd"]
