
FROM ubuntu:focal

ARG TARGETPLATFORM
ARG DEBIAN_FRONTEND=noninteractive
ARG userid
ARG groupid
ARG username

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get install -y locales && \
    localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

ENV LANG en_US.UTF-8

RUN apt-get install --no-install-recommends --no-install-suggests --yes \
        build-essential ca-certificates gcc gcc-multilib clang curl \
        git git-lfs gnupg gperf build-essential zip libc6-dev python \
        x11proto-core-dev libgl1-mesa-dev g++-multilib tofrodos zlib1g-dev \
        libncurses5-dev:i386 libx11-dev:i386 libreadline6-dev:i386  \
        libgl1-mesa-glx:i386 zlib1g-dev:i386 linux-libc-dev:i386 gawk \
        libncurses5-dev bc bison flex gettext libssl-dev autoconf libtool \
        wget patch dos2unix tree u-boot-tools libelf-dev libncurses5 \
        libxml2-utils xsltproc markdown texinfo gettext busybox \
        fakeroot cpio unzip rsync ccache xxd vim liblzo2-2 && \
    apt-get clean && \
    rm -rf /var/lib/apt/* /var/cache/apt/* /tmp/* /var/tmp/*

RUN groupadd -g $groupid $username \
 && useradd -m -u $userid -g $groupid $username \
 && echo $username >/root/username

COPY gitconfig /home/$username/.gitconfig

RUN chown $userid:$groupid /home/$username/.gitconfig

RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz && \
    tar -xf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz -C /opt

ENV HOME=/home/$username
ENV USER=$username

WORKDIR $HOME

ENV HOME=/home/$username
ENV USER=$username
ENV WORKFOLDER=/home/$username/T527
ENV GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
ENV PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin'
ENV ARCH=arm64
ENV CROSS_COMPILE=aarch64-none-linux-gnu-

ENTRYPOINT chroot --userspec=$(cat /root/username):$(cat /root/username) / /bin/bash -c "cd $WORKFOLDER && exec /bin/bash -i"
