FROM debian:bookworm AS build
ENV DEBIAN_FRONTEND noninteractive
RUN echo 'deb-src http://deb.debian.org/debian bookworm main' >> /etc/apt/sources.list
WORKDIR /tmp
RUN apt-get update -y && apt install -y dpkg-dev git libpulse-dev
RUN apt-get source -y pulseaudio
RUN apt-get build-dep -y pulseaudio 
COPY ./buildpulse.sh .
RUN bash ./buildpulse.sh

FROM debian:bookworm
ENV DEBIAN_FRONTEND noninteractive
ARG ARCH
ARG TZ=Europe/London
RUN apt update -y && \
	apt-get upgrade -y && \
	apt-get install -y wget xrdp xfce4 chromium sudo dbus-x11 git vim bash-completion openjdk-17-jdk telnet net-tools iputils-ping && \
	apt-get remove -y xscreensaver && \
	apt-get autoremove -y && \
  	rm -rf /var/cache/apt /var/lib/apt/lists	
COPY --from=build --chmod=0755 /tmp/pulseaudio-module-xrdp/src/.libs/module-xrdp-sink.so /var/lib/xrdp-pulseaudio-installer/module-xrdp-sink.so
COPY --from=build --chmod=0755 /tmp/pulseaudio-module-xrdp/src/.libs/module-xrdp-sink.lai /var/lib/xrdp-pulseaudio-installer/module-xrdp-sink.la
COPY --from=build --chmod=0755 /tmp/pulseaudio-module-xrdp/src/.libs/module-xrdp-source.so /var/lib/xrdp-pulseaudio-installer/module-xrdp-source.so
COPY --from=build --chmod=0755 /tmp/pulseaudio-module-xrdp/src/.libs/module-xrdp-source.lai /var/lib/xrdp-pulseaudio-installer/module-xrdp-source.la
RUN sed -i '/^test/i pulseaudio --start' /etc/xrdp/startwm.sh
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg \
        && install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ \
        && sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' \
        && rm -f packages.microsoft.gpg

RUN     wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
        && dpkg -i packages-microsoft-prod.deb

RUN     wget https://dot.net/v1/dotnet-install.sh && \
        chmod +x ./dotnet-install.sh && \
        ./dotnet-install.sh -c STS --install-dir /dotnet && \
        echo 'export DOTNET_ROOT=/dotnet' > /etc/profile.d/dotnet.sh && \
        echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools:/opt/JetBrains\ Rider-2023.1.2/bin' >> /etc/profile.d/dotnet.sh

RUN apt update && apt install -y code

WORKDIR /opt
RUN wget https://download-cdn.jetbrains.com/rider/JetBrains.Rider-2023.1.2${ARCH}.tar.gz && \
	tar xvzf JetBrains.Rider-2023.1.2${ARCH}.tar.gz && \
	rm JetBrains.Rider-2023.1.2${ARCH}.tar.gz

COPY ./auto-install.xml /tmp
RUN wget https://github.com/squirrel-sql-client/squirrel-sql-stable-releases/releases/download/4.6.0-installer/squirrel-sql-4.6.0-standard.jar && \
	java -jar squirrel-sql-4.6.0-standard.jar /tmp/auto-install.xml && \
	rm squirrel-sql-4.6.0-standard.jar && \
	mv /root/.local/share/applications/SQ*.desktop /usr/share/applications/
ADD ./jdbc.tgz /opt/squirrelSql/

RUN wget 'https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb' && \
  dpkg --install dbeaver-ce_latest_amd64.deb && \
  rm dbeaver-ce_latest_amd64.deb

RUN wget https://download.docker.com/linux/static/stable/x86_64/docker-24.0.2.tgz && \
	tar xvzf docker-24.0.2.tgz --strip-components 1 -C /usr/local/bin && \
	rm docker-24.0.2.tgz && \
	mkdir -p /usr/libexec/docker/cli-plugins && \
	chmod +x /usr/libexec/docker/cli-plugins && \
	wget -O 'docker-compose' https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 && \
	chmod +x docker-compose && \
	mv docker-compose /usr/libexec/docker/cli-plugins/ && \
	ln -sv  /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
	
RUN     apt-get clean && \
        apt-get -y remove && \
	echo 'paul ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/90-super && \
	addgroup --system --gid 991 docker && \
        usermod -p '$1$S6iYWiUc$f1XwbNXb/gYtfVzIcmcuc.' root && \
        useradd -ms /bin/bash paul && \
        echo 'paul:harry1996' | chpasswd && \
        usermod -a -G sudo paul && \
        usermod -a -G docker paul && \
        usermod -a -G root paul && \
        useradd -ms /bin/bash tony && \
        echo 'tony:GPSPass' | chpasswd && \
        usermod -a -G sudo tony && \
        usermod -a -G docker tony

ENTRYPOINT /etc/init.d/xrdp start && tail -F /var/log/xrdp-sesman.log
