FROM debian:bullseye-slim

LABEL maintainer="Alice D. <alice@starwitch.productions>"

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
	apt dist-upgrade -yqq && \
	apt install -y --no-install-recommends \
		apt-utils \
		sudo \
		ca-certificates \
		pkg-config \
		curl \
		wget \
		bzip2 \
		xz-utils \
		make \
		git \
		libarchive-tools \
		doxygen \
		gnupg \
		build-essential \
		python3-docutils \
		python3-pip \
		gdebi-core \
		apt-transport-https \
		cmake

RUN pip3 install \
		meson==0.63.3 \
		ninja \
		zstandard \
		python-gnupg

ENV DEVKITPRO=/opt/devkitpro
ENV PATH=${DEVKITPRO}/tools/bin:$PATH

RUN mkdir -p /usr/local/share/keyring/ && \
	curl https://apt.devkitpro.org/devkitpro-pub.gpg -o /usr/local/share/keyring/devkitpro-pub.gpg && \
	echo "deb [signed-by=/usr/local/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list && \
	apt update && \
	apt install devkitpro-pacman -yqq && \
	apt-get clean && \
	rm -rf /var/lib/apt/lists/*

RUN mkdir -p -m 755 /etc/apt/keyrings

RUN wget https://cli.github.com/packages/githubcli-archive-keyring.gpg -O /etc/apt/keyrings/githubcli-archive-keyring.gpg

RUN chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg

RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list

RUN apt-get update

RUN apt-get install -y --no-install-recommends gh

RUN apt-get clean -y

# required so that dkp-pacman works, otherwise it exits with an error because /etc/mtab doesn't exist
RUN ln -s /proc/self/mounts /etc/mtab

RUN dkp-pacman -Syyu --noconfirm \
		switch-dev \
		switch-portlibs \
		dkp-toolchain-vars \
		switch-pkg-config && \
    dkp-pacman -S --needed --noconfirm `dkp-pacman -Slq dkp-libs | grep '^switch-'` && \
    dkp-pacman -Scc --noconfirm
