WORKDIR /usr/src

ARG GIT_VERSION=2.16.2
ARG CMAKE_VERSION=3.11.0

COPY imagefiles/build-and-install-git.sh \
  imagefiles/utils.sh \
  imagefiles/build-and-install-openssl.sh \
  imagefiles/build-and-install-openssh.sh \
  imagefiles/build-and-install-cmake.sh \
  imagefiles/install-cmake-binary.sh \
  imagefiles/build-and-install-curl.sh \
  /dockcross/

RUN \
  if [ "$DEFAULT_DOCKCROSS_IMAGE" = "dockcross/manylinux-x86" ]; then \
    /dockcross/build-and-install-openssl.sh -32 && \
    /dockcross/build-and-install-openssh.sh && \
    /dockcross/build-and-install-curl.sh && \
    /dockcross/build-and-install-git.sh && \
    /dockcross/build-and-install-cmake.sh -32 || exit 1; \
  else \
    /dockcross/build-and-install-openssl.sh && \
    /dockcross/build-and-install-openssh.sh && \
    /dockcross/build-and-install-curl.sh && \
    /dockcross/build-and-install-git.sh && \
    /dockcross/install-cmake-binary.sh || exit 1; \
  fi; \
  rm /dockcross/build-and-install-git.sh \
  /dockcross/utils.sh \
  /dockcross/build-and-install-openssl.sh \
  /dockcross/build-and-install-openssh.sh \
  /dockcross/build-and-install-cmake.sh \
  /dockcross/install-cmake-binary.sh \
  /dockcross/build-and-install-curl.sh

COPY imagefiles/cmake.sh /usr/local/bin/cmake
COPY imagefiles/ccmake.sh /usr/local/bin/ccmake
# /opt/rh/devtoolset-2/root/usr/bin/sudo expects sudo at this location
COPY imagefiles/sudo.sh /usr/bin/sudo

COPY imagefiles/install-ninja.sh /dockcross/
RUN \
  /dockcross/install-ninja.sh \
    -python $([ -e /opt/python/cp35-cp35m/bin/python ] && echo "/opt/python/cp35-cp35m/bin/python" || echo "python") && \
  rm /dockcross/install-ninja.sh

RUN if [ -e /opt/python/cp35-cp35m/bin/python ]; then \
    : nothing to do here since it is updated by manylinux-common/install-python-packages.sh ; \
  else \
    curl -# -LO https://bootstrap.pypa.io/get-pip.py && \
    python get-pip.py --ignore-installed && \
    rm get-pip.py || exit 1; \
  fi

RUN $([ -e /opt/python/cp35-cp35m/bin/python ] && echo "/opt/python/cp35-cp35m/bin/python" || echo "python") -m pip install --ignore-installed conan

WORKDIR /usr/share
RUN git clone "https://github.com/nojhan/liquidprompt.git" && \
  cd liquidprompt && \
  git checkout v_1.11
COPY imagefiles/.bashrc /root/

RUN echo "root:root" | chpasswd
WORKDIR /work
ENTRYPOINT ["/dockcross/entrypoint.sh"]

COPY imagefiles/entrypoint.sh imagefiles/dockcross /dockcross/