FROM archlinux/archlinux

RUN sed -i '1i Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch' /etc/pacman.d/mirrorlist && \
    sed -i '2i Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' /etc/pacman.d/mirrorlist && \
    pacman -Syyu --noconfirm && \
    pacman -S --needed --noconfirm sudo git emacs python-pip wqy-microhei wqy-zenhei && \
    pacman -S --needed --noconfirm python-pyqt5 python-pyqt5-sip python-pyqtwebengine wmctrl && \
    pacman -S --needed --noconfirm python-qrcode && \
    yes|pacman -Scc

RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U && \
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

RUN pip install PyMuPDF epc retrying && rm -rf /root/.cache

RUN git clone --depth=1 https://gitee.com/emacs-hub/emacs-application-framework.git  && \
    git clone --depth=1 https://github.com/magnars/s.el.git

ARG _UID="1000"
ARG _USER="eaf"
RUN useradd --uid ${_UID}  -ms /bin/bash ${_USER}
RUN echo "${_USER}     ALL=NOPASSWD: ALL" >> /etc/sudoers

COPY docker-init.sh tmp/lib-scripts/
RUN chmod +x /tmp/lib-scripts/docker-init.sh
RUN chown ${_USER}:root /tmp/lib-scripts/docker-init.sh

ENV LANG=zh_CN.UTF-8

USER ${_USER}
WORKDIR /home/${_USER}

ENTRYPOINT [ "/tmp/lib-scripts/docker-init.sh" ]
CMD [ "emacs", "-L", "/emacs-application-framework", "-L", "/s.el", "--eval", "(require 'eaf)" ]
